Array
bakergus
这个作者很懒,什么都没留下…
展开
-
1.Two Sum
Click here to try this problem on LeetcodeProblems with tag: Array Problems with tag : Hash Table Given an array of integers, return indices of the two numbers such that they add up to a specific tar原创 2016-11-12 23:59:49 · 206 阅读 · 0 评论 -
189. 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].Note: Try to come up as many solutions as you can, ther原创 2016-11-17 13:35:02 · 331 阅读 · 0 评论 -
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 always原创 2016-11-16 07:53:17 · 227 阅读 · 0 评论 -
123. Best Time to Buy and Sell Stock III
Say 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 at most two transactions.Note: You may not engag原创 2016-11-13 13:53:12 · 223 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
Say you have an array for which the i th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one an原创 2016-11-13 13:01:47 · 410 阅读 · 0 评论 -
121. 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 most one transaction (ie, buy one and sell one share of the stock), desi原创 2016-11-13 12:51:43 · 298 阅读 · 0 评论 -
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]]思路: 首先定义一个二位vector,也就是vector原创 2016-11-13 09:54:24 · 212 阅读 · 0 评论 -
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].Note: Could you optimize your algorithm to use only O(k) extra space?思路: 这道题目是118. Pascal’s T原创 2016-11-13 10:15:44 · 258 阅读 · 0 评论 -
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 additional原创 2016-11-13 09:42:29 · 280 阅读 · 0 评论 -
66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.思路: 作为一道Array的题目,这个题目比较简单。原创 2016-11-13 09:21:41 · 192 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index原创 2016-11-13 08:54:00 · 258 阅读 · 0 评论 -
26.Remove Duplicates from Sorted Array
Click here to try this problem on Leetcode Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for anothe原创 2016-11-13 00:17:00 · 278 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Click here to try this problem on Leetcode Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should r原创 2016-11-13 00:46:19 · 216 阅读 · 0 评论 -
27. Remove Element
Click here to try this problem on Leetcode Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do原创 2016-11-13 00:26:52 · 252 阅读 · 0 评论 -
217. 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 array, and it should return false if every element is原创 2016-11-17 16:09:35 · 246 阅读 · 0 评论