
LeetCode算法题
文章平均质量分 92
LeetCode难题解题思路解析
chenjieping1995
这个作者很懒,什么都没留下…
展开
-
638. Shopping Offers [LeetCode]
In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a原创 2017-07-18 20:00:12 · 3118 阅读 · 0 评论 -
461. Hamming Distance [LeetCode]
The hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x, y Exam转载 2017-01-30 23:02:43 · 480 阅读 · 0 评论 -
476. Number Complement [LeetCode]
iven a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range o原创 2017-01-31 17:25:15 · 559 阅读 · 0 评论 -
412. Fizz Buzz [LeetCode]
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.原创 2017-02-01 17:46:12 · 786 阅读 · 0 评论 -
485. Max Consecutive Ones [LeetCode]
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecu转载 2017-02-02 00:14:00 · 421 阅读 · 0 评论 -
463. Island Perimeter [LeetCode]
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely原创 2017-02-02 11:12:05 · 525 阅读 · 0 评论 -
492. Construct the Rectangle [LeetCode]
题目:For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose l原创 2017-02-02 14:50:45 · 504 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-02-02 15:21:11 · 975 阅读 · 0 评论 -
226. Invert Binary Tree [LeetCode]
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe原创 2017-02-02 21:49:18 · 655 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted [LeetCode]
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 number原创 2017-02-02 22:16:01 · 533 阅读 · 0 评论 -
283. Move Zeroes [LeetCode]
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 you原创 2017-02-02 22:46:01 · 391 阅读 · 0 评论 -
455. Assign Cookies [LeetCode]
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a c原创 2017-02-02 23:07:55 · 524 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements [LeetCode]
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou原创 2017-02-03 09:41:53 · 364 阅读 · 0 评论 -
383. Ransom Note [LeetCode]
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot原创 2017-02-03 10:19:24 · 478 阅读 · 0 评论 -
404. Sum of Left Leaves [LeetCode]
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2017-02-03 11:11:11 · 381 阅读 · 0 评论 -
349. Intersection of Two Arrays [LeetCode]
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原创 2017-02-03 13:02:17 · 337 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II [LeetCode]
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 on原创 2017-02-03 15:42:16 · 418 阅读 · 0 评论 -
387. First Unique Character in a String [LeetCode]
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:原创 2017-02-04 11:26:42 · 389 阅读 · 0 评论 -
一次搞懂全排列——LeetCode四道Permutations问题详解
LeetCode中与Permutations相关的共有四题: 31. Next Permutation 46. Permutations 47. Permutations II 60. Permutation Sequence 大致包括了所有全排列问题可能考到的题型。 本文按序列出了解这四道题的详细思路和AC代码。在各题之间,尽可能地使用了不同的解法,使大家对各种原创 2017-03-26 17:52:17 · 27263 阅读 · 2 评论 -
34. Search for a Range [LeetCode]
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the原创 2017-05-08 17:53:24 · 430 阅读 · 0 评论 -
76. Minimum Window Substring [LeetCode]
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2017-07-15 13:46:58 · 642 阅读 · 0 评论 -
4. Median of Two Sorted Arrays [LeetCode]
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-07-16 22:11:37 · 443 阅读 · 0 评论