![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 75
sscssz
这个作者很懒,什么都没留下…
展开
-
[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 · 348 阅读 · 0 评论 -
[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 · 367 阅读 · 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 · 377 阅读 · 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 · 421 阅读 · 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 · 332 阅读 · 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 · 316 阅读 · 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 · 444 阅读 · 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 · 746 阅读 · 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 · 1593 阅读 · 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 · 459 阅读 · 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 · 483 阅读 · 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 · 403 阅读 · 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 · 327 阅读 · 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 · 409 阅读 · 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 · 451 阅读 · 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 · 428 阅读 · 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 · 273 阅读 · 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 · 277 阅读 · 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 · 275 阅读 · 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 · 1038 阅读 · 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 · 723 阅读 · 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 · 375 阅读 · 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 · 303 阅读 · 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 · 453 阅读 · 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 · 320 阅读 · 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 · 336 阅读 · 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 · 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 · 391 阅读 · 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 · 420 阅读 · 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 · 351 阅读 · 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 · 438 阅读 · 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 · 249 阅读 · 0 评论 -
330. Patching Array【M】【84】【leetcode】
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Re原创 2016-03-18 12:22:17 · 412 阅读 · 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 · 329 阅读 · 0 评论 -
61. Rotate List【M】【54】【leetcode】
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.Subscribe to see which原创 2016-03-18 16:30:34 · 369 阅读 · 0 评论 -
338. Counting Bits【M】【leetcode题解】
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 =原创 2016-03-19 14:02:43 · 1275 阅读 · 1 评论 -
203. Remove Linked List Elements【E】【70】【leetcode】
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special thank原创 2016-03-19 15:19:35 · 684 阅读 · 0 评论 -
2. Add Two Numbers 【M】【72】【leetcode】
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-03-31 17:48:41 · 312 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters【M】【28】【leetcode】
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2016-03-31 21:49:51 · 332 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree【M】【33】【leetcode题解】
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this question从给定的有序链表生成平衡二叉树。解原创 2016-02-23 15:24:41 · 418 阅读 · 0 评论