
leetcode
文章平均质量分 64
Yingying_code
这个作者很懒,什么都没留下…
展开
-
153. Find Minimum 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).Find the minimum element.You may assume no duplicate exists in the arra原创 2016-08-28 19:57:50 · 404 阅读 · 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-08-28 16:59:26 · 340 阅读 · 0 评论 -
169. Majority Element*
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alw原创 2016-08-28 16:28:24 · 356 阅读 · 0 评论 -
238. Product of Array Except Self **
Given an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(n).原创 2016-08-28 15:45:53 · 450 阅读 · 0 评论 -
283. 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 nums = [0, 1, 0, 3, 12], after calling your原创 2016-08-28 15:31:23 · 380 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array *
Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-08-27 17:09:04 · 380 阅读 · 0 评论 -
374. Guess Number Higher or Lower *
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h原创 2016-08-07 16:45:47 · 297 阅读 · 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 res原创 2016-08-08 10:09:41 · 202 阅读 · 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 ma原创 2016-08-08 11:35:26 · 325 阅读 · 0 评论 -
219. Contains Duplicate II *
Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and the difference betweeni and j is at most k.My cod原创 2016-08-29 19:36:56 · 306 阅读 · 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.My code:class Solution原创 2016-08-29 20:16:53 · 329 阅读 · 0 评论 -
27. Remove Element*
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 this in place with constant memory.The原创 2016-08-29 20:44:20 · 323 阅读 · 0 评论 -
88. Merge Sorted Array*
Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal tom + n) to hold addit原创 2016-08-29 21:03:52 · 344 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted**
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers原创 2016-08-29 21:32:27 · 407 阅读 · 0 评论 -
345. Reverse Vowels of a String*
Write 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", return "leotcede".Note原创 2016-08-08 15:34:29 · 284 阅读 · 0 评论 -
344. Reverse String*
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".My code:class Solution(object): def reverseString(self, s):原创 2016-08-08 17:55:58 · 215 阅读 · 0 评论 -
190. Reverse Bits*
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-09-09 21:01:00 · 254 阅读 · 0 评论 -
36. Valid Sudoku*
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2016-09-09 21:25:48 · 221 阅读 · 0 评论 -
342. Power of Four*
Given 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.import mathclass Solution(object):原创 2016-08-08 18:10:24 · 191 阅读 · 0 评论 -
299. Bulls and Cows*
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-08-09 10:39:14 · 200 阅读 · 0 评论 -
292. Nim Game*
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2016-08-09 11:54:40 · 174 阅读 · 0 评论 -
258. Add Digits*
Given 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 = 2. Since 2 has on原创 2016-08-09 15:41:27 · 175 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree*
Given 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.My code: # Definition for a b原创 2016-08-09 16:14:41 · 151 阅读 · 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原创 2016-08-09 20:31:59 · 164 阅读 · 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]]My code:class Solution(o原创 2016-08-31 15:56:38 · 196 阅读 · 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?原创 2016-08-31 16:27:20 · 184 阅读 · 0 评论 -
228. Summary Ranges**
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].My code:class Solution(object): def summaryRang原创 2016-08-31 17:01:08 · 177 阅读 · 0 评论 -
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-08-10 15:24:32 · 228 阅读 · 0 评论 -
15. 3Sum**
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain du原创 2016-08-31 20:19:35 · 243 阅读 · 0 评论 -
136. Single Number **
Given 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 without using e原创 2016-08-10 16:28:36 · 180 阅读 · 0 评论 -
16. 3Sum Closest**
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2016-09-01 14:48:22 · 210 阅读 · 0 评论 -
18. 4Sum **
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution原创 2016-09-01 20:13:10 · 209 阅读 · 0 评论 -
231. Power of Two *
Given an integer, write a function to determine if it is a power of two.My code:import mathclass Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype:原创 2016-08-11 10:42:34 · 223 阅读 · 0 评论 -
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 sho原创 2016-08-11 16:53:18 · 165 阅读 · 0 评论 -
13. Roman to Integer *
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.My code:class Solution(object): def romanToInt(self, s): """ :原创 2016-08-11 17:34:32 · 148 阅读 · 0 评论 -
12. Integer to Roman **
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.My code:class Solution(object): def intToRoman(self, num): """原创 2016-08-11 18:01:05 · 172 阅读 · 0 评论 -
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.原创 2016-08-11 18:22:32 · 248 阅读 · 0 评论 -
263. Ugly Number
class Solution(object): def isUgly(self, num): """ :type num: int :rtype: bool """ if num ==1: return True if num<=0: return原创 2016-08-11 20:32:45 · 161 阅读 · 0 评论 -
264. Ugly Number II**
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first原创 2016-08-11 21:18:24 · 187 阅读 · 0 评论 -
313. Super Ugly Number **
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13,原创 2016-08-12 11:24:06 · 233 阅读 · 0 评论