
leetcode
文章平均质量分 72
sscssz
这个作者很懒,什么都没留下…
展开
-
[81][E][leetcode 题解]Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Subscribe to see which c原创 2015-12-09 23:28:17 · 381 阅读 · 0 评论 -
【E】【51】【leetcode题解】Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2015-12-10 00:16:39 · 309 阅读 · 0 评论 -
Plus One【leetcode】【89】【E】
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.class Solution原创 2015-11-18 22:19:42 · 372 阅读 · 0 评论 -
【E】【59】【leetcode题解】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原创 2015-12-10 22:18:45 · 399 阅读 · 0 评论 -
Game of Life 【leetcode】【98.9】【M】
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m原创 2015-11-18 20:25:14 · 426 阅读 · 0 评论 -
【M】【83】【leetcode题解】Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2015-12-11 20:48:36 · 356 阅读 · 0 评论 -
[E][79][leetcode题解]Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.Subscribe to see which companies asked this question思路简单,首先找到最短的那个,然后把它,一位一位减少,跟每个字符串比较,看是原创 2015-12-11 21:12:01 · 338 阅读 · 0 评论 -
【leetcode】【40%】【M】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 fi原创 2015-11-19 16:48:25 · 447 阅读 · 0 评论 -
【leetcode题解】【E】【59】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 as0011100101原创 2015-12-13 22:14:29 · 466 阅读 · 0 评论 -
【特别重要!!!快排的partition思想】【leetcode题解】【M】【71】Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.原创 2015-12-13 20:10:09 · 1632 阅读 · 0 评论 -
【100题纪念】【有趣的算法】【leetcode题解】【E】【84】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 addit原创 2015-12-14 18:24:33 · 767 阅读 · 0 评论 -
【leetcode题解】【E】【97】Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Subscribe to see which companies asked th原创 2015-12-14 19:13:21 · 280 阅读 · 0 评论 -
【64.22】【E】【leetcode】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?Subscr原创 2015-11-28 16:16:02 · 506 阅读 · 0 评论 -
【E】【87】【leetcode】Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating原创 2015-11-28 16:39:10 · 423 阅读 · 0 评论 -
【VIP】【leetcode题解】【回溯】【97.5】【M】Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For原创 2015-12-15 13:46:41 · 346 阅读 · 0 评论 -
【回溯】【leetcode题解】【M】【57】Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited numbe原创 2015-12-15 18:37:56 · 431 阅读 · 0 评论 -
【leetcode题解】【回溯】【54】【M】Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain du原创 2015-12-15 20:01:12 · 474 阅读 · 0 评论 -
【34.7】【H】【leetcode】Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2015-11-28 15:43:26 · 489 阅读 · 0 评论 -
【leetcode题解】【99.38】【E】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] and the difference between i and j is at most k.原创 2015-12-17 19:28:14 · 289 阅读 · 0 评论 -
【leetcode题解】【再看一遍】【86】【M】Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j原创 2015-12-17 23:08:52 · 448 阅读 · 0 评论 -
【leetcode题解】【M】【79】Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ [原创 2015-12-18 23:54:35 · 293 阅读 · 0 评论 -
【leetcode题解】【M】【67】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.原创 2015-12-18 23:56:24 · 299 阅读 · 0 评论 -
【leetcode题解】【E】【61.5】Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2015-12-19 01:17:33 · 296 阅读 · 0 评论 -
【leetcode题解】【再来,动态规划】【H】【21.8】Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num转载 2015-12-21 19:19:52 · 1066 阅读 · 0 评论 -
【leetcode题解】【有问题,python没AC,java却过了】【M】【66】Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =原创 2015-12-21 22:38:22 · 751 阅读 · 0 评论 -
【leetcode题解】【M】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原创 2015-12-23 00:29:36 · 398 阅读 · 0 评论 -
【leetcode题解】【M】【10】318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le原创 2015-12-23 01:28:31 · 330 阅读 · 0 评论 -
【leetcode题解】【28】【E】Palindrome Number
class Solution(object): def isPalindrome(self, x): l = 1 if x < 0 : return False #x = 0 - x while x / (pow(10,l)): l += 1 #prin原创 2015-12-06 21:25:52 · 348 阅读 · 0 评论 -
【92】【H】【leetcode】 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 retur原创 2015-12-06 21:03:43 · 480 阅读 · 0 评论 -
【leetcode题解】[E][52]303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan原创 2015-12-23 21:41:35 · 355 阅读 · 0 评论 -
【leetcode题解】【E】【19】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原创 2015-12-23 22:09:41 · 355 阅读 · 0 评论 -
【leetcode题解】【再做一遍】【47】【M】241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +,- and *.Example 1Input原创 2015-12-24 01:46:19 · 456 阅读 · 0 评论 -
[88][E][leetcode 题解]Length of Last Word
Given 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.Note: A word is原创 2015-12-09 22:26:21 · 363 阅读 · 0 评论 -
290. Word Pattern【E】【47】
Given 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 in str.原创 2016-03-01 14:12:47 · 331 阅读 · 0 评论 -
328. Odd Even Linked List[E][86]【leetcode】
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in原创 2016-02-14 15:20:08 · 412 阅读 · 0 评论 -
326. Power of Three【E】【81】
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?Credits:Special thanks to @dietpepsi for adding this原创 2016-02-14 15:35:52 · 440 阅读 · 0 评论 -
86. Partition List【M】【48】【leetcode题解】
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2016-03-16 19:16:15 · 377 阅读 · 0 评论 -
【VIP】【图】332. Reconstruct Itinerary【M】【47】
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus,原创 2016-03-29 19:44:09 · 462 阅读 · 0 评论 -
7. Reverse Integer【E】【27】
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before cod原创 2016-03-29 20:15:07 · 274 阅读 · 0 评论 -
【VIP】189. Rotate Array 【E】【85】【leetcode】
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 y原创 2016-03-18 16:18:13 · 352 阅读 · 0 评论