leetcode
文章平均质量分 60
Juxin_Lin
这个作者很懒,什么都没留下…
展开
-
【LeetCode】344. Reverse String
Difficulty: EasyWrite a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".class Solution {public: string revers原创 2016-09-04 21:46:16 · 328 阅读 · 0 评论 -
【LeetCode】241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1原创 2017-01-08 16:55:40 · 292 阅读 · 0 评论 -
【LeetCode】169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2017-01-08 16:52:50 · 270 阅读 · 0 评论 -
【LeetCode】 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.原创 2017-01-08 16:46:57 · 810 阅读 · 0 评论 -
【LeetCode】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] ha原创 2017-01-08 10:42:39 · 318 阅读 · 0 评论 -
【LeetCode】55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2017-01-08 10:30:12 · 236 阅读 · 0 评论 -
【LeetCode】35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2017-01-08 09:58:31 · 198 阅读 · 0 评论 -
【LeetCode】241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Difficulty: M原创 2017-01-07 20:05:18 · 313 阅读 · 0 评论 -
【LeetCode】258. Add Digits
Difficulty: EasyGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1原创 2017-01-07 20:02:10 · 237 阅读 · 0 评论 -
【LeetCode】101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-01-08 17:00:02 · 328 阅读 · 0 评论 -
【LeetCode】6. ZigZag Conversion
6. ZigZag Conversion Add to ListQuestionEditorial Solution My SubmissionsTotal Accepted: 129677Total Submissions: 500836Difficulty: EasyContributors: AdminThe原创 2017-01-09 08:57:04 · 292 阅读 · 0 评论 -
【LeetCode】41. First Missing Positive
Difficulty: HardGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n)原创 2017-01-14 23:22:27 · 309 阅读 · 0 评论 -
【LeetCode】3. Longest Substring Without Repeating Characters
Difficulty: MediumGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Gi原创 2017-01-14 16:55:32 · 416 阅读 · 0 评论 -
【LeetCode】122. Best Time to Buy and Sell Stock II
Difficulty: MediumSay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transact原创 2017-01-14 16:45:58 · 318 阅读 · 0 评论 -
【LeetCode】45. Jump Game II
Difficulty: HardGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that po原创 2017-01-14 16:39:09 · 275 阅读 · 0 评论 -
【LeetCode】69. Sqrt(x)
Difficulty: MediumImplement int sqrt(int x).Compute and return the square root of x.Subscribe to see which companies asked this question二分查找,时间复杂度O(logn)class Solution {publ原创 2017-01-14 16:35:44 · 259 阅读 · 0 评论 -
【LeetCode】50. Pow(x, n)
Difficulty: MediumImplement pow(x, n).Subscribe to see which companies asked this question分析二分法,x^n=x^(n/2) * x^(n/2) * x^(n%2),时间复杂度O(logn)class Solution {public:原创 2017-01-14 16:21:49 · 312 阅读 · 0 评论 -
【LeetCode】131. Palindrome Partitioning
131. Palindrome PartitioningTotal Accepted: 84076Total Submissions: 272482Difficulty: MediumContributors: AdminGiven a string s, partition s such that every substring of the pa原创 2017-01-14 00:00:48 · 257 阅读 · 0 评论 -
【LeetCode】130. Surrounded Regions
Difficulty: MediumGiven a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded reg原创 2017-01-13 23:53:14 · 288 阅读 · 0 评论 -
【LeetCode】268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul原创 2017-01-07 19:56:44 · 184 阅读 · 0 评论 -
【LeetCode】273. Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand Th原创 2017-01-07 19:53:03 · 262 阅读 · 0 评论 -
【LeetCode】416. Partition Equal Subset Sum
Difficulty: MediumGiven a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note原创 2016-11-01 16:48:53 · 229 阅读 · 0 评论 -
【LeetCode】300. Longest Increasing Subsequence
Difficulty: MediumGiven an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence原创 2016-10-20 12:09:14 · 347 阅读 · 0 评论 -
【LeetCode】121. Best Time to Buy and Sell Stock
Difficulty: EasySay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell原创 2016-10-20 15:41:43 · 228 阅读 · 0 评论 -
【LeetCode】303. Range Sum Query - Immutable
Difficulty: EasyGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sum原创 2016-10-25 21:49:12 · 248 阅读 · 0 评论 -
【LeetCode】70. Climbing Stairs
Difficulty: EasyYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Su原创 2016-10-25 21:12:03 · 254 阅读 · 0 评论 -
【LeetCode】144. Binary Tree Preorder Traversal
Difficulty: MediumGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].原创 2016-09-06 21:34:23 · 347 阅读 · 0 评论 -
【LeetCode】127. Word Ladder
Difficulty: MediumGiven two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWord to endWord, such that:Only one lett原创 2016-09-11 16:19:17 · 573 阅读 · 2 评论 -
【LeetCode】338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2016-09-04 20:37:45 · 428 阅读 · 0 评论 -
【LeetCode】392. Is Subsequence
Difficulty: MediumGiven a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (原创 2016-11-01 17:36:41 · 303 阅读 · 0 评论 -
【LeetCode】96. Unique Binary Search Trees
Difficulty: MediumGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3原创 2016-11-01 19:56:17 · 190 阅读 · 0 评论 -
【LeetCode】10. Regular Expression Matching
Difficulty: HardImplement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cov原创 2017-01-07 19:49:41 · 329 阅读 · 0 评论 -
【LeetCode】4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 =原创 2017-01-07 19:43:09 · 214 阅读 · 0 评论 -
【LeetCode】100. Same Tree
Difficulty: EasyGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the sam原创 2017-01-07 18:53:35 · 211 阅读 · 0 评论 -
【LeetCode】104. Maximum Depth of Binary Tree
Difficulty: EasyGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Defin原创 2017-01-07 19:12:17 · 192 阅读 · 0 评论 -
【LeetCode】21. Merge Two Sorted Lists
Difficulty: EasyMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路比较简单,不断比较取出来的2个节点的大小,把小的加入新的链表,时间原创 2017-01-07 12:05:18 · 209 阅读 · 0 评论 -
【LeetCode】19. Remove Nth Node From End of List
Difficulty: EasyGiven 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原创 2017-01-07 10:49:38 · 245 阅读 · 0 评论 -
【LeetCode】120. Triangle
Difficulty: MediumGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[原创 2016-11-01 21:48:39 · 200 阅读 · 0 评论 -
【LeetCode】322. Coin Change
Difficulty: MediumYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount.原创 2016-11-01 20:35:07 · 277 阅读 · 0 评论 -
【LeetCode】75. Sort Colors
Difficulty: MediumGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Her原创 2017-01-14 23:28:37 · 329 阅读 · 0 评论