
leetcode
文章平均质量分 64
baladeer
CV菜鸟
展开
-
53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1]原创 2018-01-11 06:48:23 · 113 阅读 · 0 评论 -
234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?这个题目在discussion里有人证明了空间复杂度不可能为O(1)。/** * Definition for singly-linked list.原创 2018-01-08 21:16:16 · 111 阅读 · 0 评论 -
328. Odd Even Linked List
这个题是把链表进行重新排序,先把奇数节点放在一起,再把偶数节点放在一起。需要注意: odd_node->next = NULL 要写上,否则会出现错误** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode原创 2018-01-09 01:30:39 · 114 阅读 · 0 评论 -
725. Split Linked List in Parts
Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts".The length of each part should be as equal as possible: no two原创 2018-01-09 02:43:57 · 138 阅读 · 0 评论 -
92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the原创 2018-01-09 08:32:19 · 109 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2018-01-09 08:53:33 · 120 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2018-01-09 09:18:12 · 118 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2018-01-09 11:03:02 · 109 阅读 · 0 评论 -
143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2018-01-09 21:20:47 · 103 阅读 · 0 评论 -
203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special than原创 2018-01-09 21:21:32 · 109 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.需要注意只存在一个节点的情况,/**原创 2018-01-09 21:50:24 · 106 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which th原创 2018-01-09 22:33:58 · 107 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number o原创 2018-01-10 01:08:20 · 125 阅读 · 0 评论 -
314. Binary Tree Vertical Order Traversal
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from left原创 2018-01-10 11:48:42 · 142 阅读 · 0 评论 -
739. Daily Temperatures
Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which thi原创 2018-01-10 12:31:27 · 142 阅读 · 0 评论 -
746. Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top原创 2018-01-10 12:55:57 · 147 阅读 · 0 评论 -
681. Next Closest Time
Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.You may assume the given input str原创 2018-01-10 14:56:12 · 297 阅读 · 0 评论 -
138. Copy List with Random Pointer 133. Clone Graph
133:/** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */class Soluti原创 2018-01-08 20:43:45 · 111 阅读 · 0 评论 -
206. Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2018-01-08 18:39:23 · 109 阅读 · 0 评论 -
148. Sort List 21. Merge Two Sorted Lists
很好的一个模板题,链表找中点(快慢指针)和merge。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */clas原创 2018-01-08 14:00:26 · 121 阅读 · 0 评论 -
697. Degree of an Array
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length o原创 2018-01-11 08:11:49 · 193 阅读 · 0 评论 -
560. Subarray Sum Equals K
560. Subarray Sum Equals KGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k原创 2018-01-11 08:35:09 · 152 阅读 · 0 评论 -
523. Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up t原创 2018-01-11 09:40:40 · 144 阅读 · 0 评论 -
724. Find Pivot Index
Given an array of integers nums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal t原创 2018-01-11 10:43:10 · 142 阅读 · 0 评论 -
371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.00 + 00->0000 + 01-> 0101 + 00-> 0101 + 01-> 10cl原创 2018-01-12 03:38:27 · 114 阅读 · 0 评论 -
179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2018-01-12 23:09:04 · 573 阅读 · 0 评论 -
479. Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers.Since the result could be very large, you should return the largest palindrome mod 1337.Example:Input: 2Output:原创 2018-01-13 04:46:20 · 138 阅读 · 0 评论 -
50. Pow(x, n)
Implement pow(x, n).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100class Solution {public: double myPow(double x, int n) {原创 2018-01-14 02:13:59 · 120 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2018-01-14 02:34:22 · 107 阅读 · 0 评论 -
22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())原创 2018-01-14 02:42:31 · 127 阅读 · 0 评论 -
544. Output Contest Matches
During the NBA playoffs, we always arrange the rather strong team to play with the rather weak team, like make the rank 1 team play with the rank nth team, which is a good strategy to make the conte原创 2018-01-14 03:10:02 · 224 阅读 · 0 评论 -
71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where p原创 2018-01-14 05:29:06 · 217 阅读 · 0 评论 -
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return原创 2018-01-08 11:05:36 · 138 阅读 · 0 评论 -
445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i原创 2018-01-08 11:45:15 · 115 阅读 · 0 评论 -
43. Multiply Strings
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits原创 2018-01-08 13:01:47 · 106 阅读 · 0 评论 -
415. Add Strings
这个题很简单,仅此记录一下;class Solution {public: string addStrings(string num1, string num2) { int size1 = num1.size(); int size2 = num2.size(); string res = ""; int原创 2018-01-08 13:02:45 · 104 阅读 · 0 评论