
LeetCode-Array
R_zz
这个作者很懒,什么都没留下…
展开
-
LeetCode-Array-27 Remove Element
问题:Givenan array and a value, remove all instances of that value in place and returnthe new length.Do not allocate extra space for another array, you must do thisin place with constant memory.The orde原创 2016-12-07 21:32:59 · 211 阅读 · 0 评论 -
LeetCode-Hash-409. Longest Palindrome
问题:https://leetcode.com/problems/longest-palindrome/ Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.原创 2017-01-11 20:43:12 · 217 阅读 · 0 评论 -
LeetCode-Array-26 Remove Duplicates from Sorted Array
问题:Givena sorted array, remove the duplicates in place such that each element appearonly once and return the new length.Do not allocate extraspace for another array, you must do this in place with con原创 2016-12-07 21:29:50 · 196 阅读 · 0 评论 -
LeetCode-Array-80 Remove Duplicates from Sorted Array II
问题:Followup for "Remove Duplicates":What if duplicates are allowed at most twice?Forexample,Given sorted array nums = [1,1,1,2,2,3],Yourfunction should return length = 5, with the first five elements原创 2016-12-07 21:53:19 · 230 阅读 · 0 评论 -
LeetCode-Array-66. Plus One
问题:Givena non-negative number represented as an array of digits, plus one to thenumber.The digits are stored such that the mostsignificant digit is at the head of the list.数组形式代表一个数,让这个数加一得到的数,在数组原创 2016-12-12 10:23:19 · 270 阅读 · 0 评论 -
LeetCode-Array-118. Pascal's Triangle
问题:Given numRows,generate the first numRows of Pascal’s triangle.For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 思考:帕斯卡三角形的规律:(1)第i层有i个元素;(2)第一原创 2016-12-12 20:22:00 · 304 阅读 · 1 评论 -
LeetCode-Array-119. Pascal's Triangle II
**问题:**Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1]. 思考:要求得到第k层的三角,但只能用O(k)的空间,所以不能用上一题二维数组的方式,只能用一维数组滚动得到。帕斯卡三角的计算公式是,A[k][n]=A[k-1][n-1]+原创 2016-12-12 21:36:09 · 253 阅读 · 0 评论 -
LeetCode-Array-88. Merge Sorted Array
**问题:**Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-12-12 21:37:42 · 248 阅读 · 0 评论 -
LeetCode-Array-1. Two Sum
问题:https://leetcode.com/problems/two-sum/Given an array of integers, return indicesof the two numbers such that they add up to a specific target.You may assumethat each input would have exactly one原创 2016-12-14 11:23:42 · 192 阅读 · 0 评论 -
LeetCode-Array-448. Find All Numbers Disappeared in an Array
问题:Givenan array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appearonce.Find all the elements of [1, n] inclusive that do not appear in thisarray.Could yo原创 2016-12-14 17:10:59 · 251 阅读 · 0 评论 -
LeetCode-Array-414. Third Maximum Number
问题:https://leetcode.com/problems/third-maximum-number/Given a non-empty array of integers, returnthe third maximum number in this array. If it does not exist, return themaximum number. The time comp原创 2016-12-16 11:16:04 · 310 阅读 · 0 评论 -
LeetCode-Array-189. Rotate Array
问题:https://leetcode.com/problems/rotate-array/ Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. 思考:创原创 2016-12-19 10:55:05 · 232 阅读 · 0 评论 -
LeetCode-Array-283. Move Zeroes
问题:https://leetcode.com/problems/move-zeroes/ Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example, given原创 2016-12-19 11:20:25 · 195 阅读 · 0 评论 -
LeetCode-Array-219. Contains Duplicate II
题目:https://leetcode.com/problems/contains-duplicate-ii/ Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] an原创 2017-01-05 20:23:32 · 199 阅读 · 0 评论 -
LeetCode-Array-217. Contains Duplicate
问题:https://leetcode.com/problems/contains-duplicate/ Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the原创 2017-01-05 20:38:51 · 264 阅读 · 0 评论 -
LeetCode-Array-121. Best Time to Buy and Sell Stock
问题:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Say 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 mos原创 2017-01-06 17:02:31 · 194 阅读 · 0 评论 -
LeetCode-Array-169. Majority Element
问题:https://leetcode.com/problems/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. 分析:如果元素出现次数超过了一半,它是占大原创 2017-01-09 11:07:08 · 175 阅读 · 0 评论 -
LeetCode-485. Max Consecutive Ones
问题: https://leetcode.com/problems/max-consecutive-ones/?tab=Description Given a binary array, find the maximum number of consecutive 1s in this array. 找出一个二进制串中连续的1的个数。 Example 1: Input: [1,1,0,原创 2017-03-02 15:27:31 · 248 阅读 · 0 评论