leetcode
NodYoung
专注于机器人,计算机视觉,机器学习
展开
-
53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.Example: For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2原创 2017-02-07 20:14:35 · 593 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
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 another array, you must do this in place with cons原创 2016-06-09 21:27:03 · 439 阅读 · 0 评论 -
319. Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turning off i原创 2016-06-09 17:08:42 · 402 阅读 · 0 评论 -
343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return 1原创 2016-06-09 16:37:22 · 481 阅读 · 0 评论 -
347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of unique ele原创 2016-06-09 15:58:23 · 620 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
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 as many transactions as you like (ie, buy one and原创 2016-06-09 00:41:44 · 452 阅读 · 0 评论 -
338. Counting Bits
338. Counting BitsGiven 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:原创 2016-06-04 16:48:32 · 463 阅读 · 0 评论 -
118. Pascal's Triangle
118. Pascal’s TriangleGiven 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]]Analysis: 高中时原创 2016-05-22 12:23:02 · 496 阅读 · 0 评论 -
342. Power of Four
342. Power of FourGiven an integer (signed 32 bits), write a function to check whether it is a power of 4.Example: Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve i原创 2016-05-22 11:37:06 · 504 阅读 · 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. Analysis: 理解题意:用一个数字构成的数组原创 2016-05-22 11:13:25 · 440 阅读 · 0 评论 -
27. Remove Element
27. Remove ElementGiven 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 this in place with constan原创 2016-05-22 10:00:38 · 408 阅读 · 0 评论 -
345. Reverse Vowels of a String
345. Reverse Vowels of a StringWrite a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, retu原创 2016-05-22 09:26:04 · 430 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockSay 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 an原创 2016-05-22 09:01:25 · 486 阅读 · 0 评论 -
202. Happy Number
202. Happy NumberWrite an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of原创 2016-05-22 00:10:50 · 570 阅读 · 0 评论 -
263. Ugly Number
263. Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not原创 2016-05-21 23:39:16 · 570 阅读 · 0 评论 -
70. Climbing Stairs
70. Climbing StairsYou 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?Link: https://le原创 2016-05-21 17:41:56 · 466 阅读 · 0 评论 -
8. String to Integer (atoi)
8. String to Integer (atoi)Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are原创 2016-06-02 22:39:03 · 405 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
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 return length = 5, with the first five elemen原创 2016-06-09 21:42:49 · 402 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
172. Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Analysis: 参考:http://bookshadow.com/weblog/201原创 2016-05-23 10:13:35 · 356 阅读 · 0 评论 -
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 if you are原创 2016-06-20 21:48:08 · 443 阅读 · 0 评论 -
324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]….Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1原创 2016-06-20 07:50:15 · 567 阅读 · 0 评论 -
350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note: Each element in the result should appear as many times as it原创 2016-06-18 21:44:37 · 568 阅读 · 0 评论 -
349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can be in原创 2016-06-17 11:26:39 · 472 阅读 · 0 评论 -
300. Longest Increasing Subsequence
Given 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 is [2, 3, 7, 101], therefore原创 2016-06-16 11:14:26 · 467 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
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 as many transactions as you like (ie, buy one and原创 2016-06-15 14:52:38 · 792 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excludi原创 2016-06-14 20:48:08 · 1175 阅读 · 0 评论 -
322. Coin Change
You 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. If that amount of money c原创 2016-06-14 15:43:11 · 607 阅读 · 0 评论 -
238. Product of Array Except Self
238. Product of Array Except SelfGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it w原创 2016-06-07 11:13:38 · 494 阅读 · 0 评论 -
137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ex原创 2016-06-06 23:33:58 · 421 阅读 · 0 评论 -
260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,原创 2016-06-06 23:13:46 · 485 阅读 · 0 评论 -
200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume原创 2016-06-12 16:32:56 · 531 阅读 · 0 评论 -
136. Single Number
136. Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it with原创 2016-06-06 00:38:52 · 488 阅读 · 0 评论 -
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses原创 2016-06-11 21:10:51 · 501 阅读 · 0 评论 -
119. Pascal's Triangle II
119. Pascal’s Triangle IIGiven an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1]. Analysis: 118. Pascal’s Triangle 的进阶。本来想用定理“第n行的第k個數字為組合數C{n}^{k}原创 2016-05-23 20:24:29 · 420 阅读 · 0 评论 -
354. Russian Doll Envelopes
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than the原创 2016-06-10 23:57:30 · 2005 阅读 · 0 评论 -
165. Compare Version Numbers
165. Compare Version NumbersCompare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version str原创 2016-06-02 21:33:03 · 343 阅读 · 0 评论 -
189. Rotate Array
189. Rotate ArrayRotate 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原创 2016-06-02 20:42:16 · 430 阅读 · 0 评论 -
38. Count and Say
38. Count and SayThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read原创 2016-05-27 19:21:35 · 386 阅读 · 0 评论 -
58. Length of Last Word
58. Length of Last WordGiven a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Not原创 2016-05-27 17:34:21 · 353 阅读 · 0 评论 -
290. Word Pattern
290. Word PatternGiven a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word i原创 2016-05-27 15:59:22 · 433 阅读 · 0 评论