leetcode
文章平均质量分 61
徐州牧
这个作者很懒,什么都没留下…
展开
-
Leetcode||50. Pow(x, n)
Implement pow(x, n).实现幂的算法,需要考虑到正负数,我是用递归class Solution(object): def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ if n原创 2017-11-02 16:12:15 · 296 阅读 · 0 评论 -
LeetCode||60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3原创 2017-11-16 14:30:53 · 194 阅读 · 0 评论 -
LeetCode||65. Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo原创 2017-11-22 10:46:14 · 232 阅读 · 0 评论 -
LeetCode||66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi原创 2017-11-22 11:37:06 · 220 阅读 · 0 评论 -
LeetCode||67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".python自带的函数真简洁class Solution(object): def addBinary(self, a, b): """原创 2017-11-22 14:02:14 · 238 阅读 · 0 评论 -
LeetCode||71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path原创 2017-12-11 10:29:42 · 241 阅读 · 0 评论 -
LeetCode||75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2017-12-20 16:37:35 · 232 阅读 · 0 评论 -
LeetCode||76. Minimum Window Substring
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-12-20 18:04:07 · 257 阅读 · 0 评论 -
LeetCode||72. Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2017-12-12 17:50:28 · 274 阅读 · 0 评论 -
LeetCode||68. Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i原创 2017-12-04 15:18:34 · 244 阅读 · 0 评论 -
LeetCode||69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4Output: 2Example 2:Input: 8Output: 2Explan原创 2017-12-05 10:21:51 · 313 阅读 · 0 评论 -
LeetCode||63. Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the原创 2017-11-21 13:51:52 · 232 阅读 · 0 评论 -
LeetCode||64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2017-11-21 14:28:46 · 258 阅读 · 0 评论 -
Leetcode||48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matr原创 2017-10-25 19:20:38 · 197 阅读 · 0 评论 -
Leetcode||39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) 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原创 2017-10-17 09:25:24 · 267 阅读 · 0 评论 -
Leetcode||40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina原创 2017-10-17 09:31:55 · 191 阅读 · 0 评论 -
LeetCode||56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].先将区间按照每个start的值来排序,排好序以后判断一个区间的start值是否处在前一个区间中,如果在前原创 2017-11-14 15:59:03 · 190 阅读 · 0 评论 -
LeetCode||57. Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E原创 2017-11-14 16:09:17 · 262 阅读 · 0 评论 -
LeetCode||58. 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原创 2017-11-15 10:24:15 · 173 阅读 · 0 评论 -
LeetCode||61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.Example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.先把链表连成环,再在特定的位置断开。注意k可能大于链表的长度。# De原创 2017-11-20 11:49:54 · 228 阅读 · 0 评论 -
LeetCode||62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2017-11-20 14:06:42 · 233 阅读 · 0 评论 -
Leetcode||51. N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2017-11-06 17:11:09 · 230 阅读 · 0 评论 -
LeetCode||59. Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2017-11-15 16:17:34 · 184 阅读 · 0 评论 -
LeetCode||70. Climbing Stairs
You 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?Note: Given n will be a posi原创 2017-12-05 10:40:30 · 206 阅读 · 0 评论 -
LeetCode||73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad i原创 2017-12-14 10:29:37 · 182 阅读 · 0 评论 -
LeetCode||74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2017-12-14 14:11:41 · 225 阅读 · 0 评论 -
LeetCode||77. Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2017-12-29 10:22:22 · 230 阅读 · 0 评论 -
LeetCode||93. Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2018-01-25 11:18:17 · 248 阅读 · 0 评论 -
LeetCode||94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solu原创 2018-01-25 11:41:39 · 244 阅读 · 0 评论 -
LeetCode||95. Unique Binary Search Trees II
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1原创 2018-01-25 14:32:54 · 296 阅读 · 0 评论 -
LeetCode||82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-原创 2018-01-09 19:23:19 · 211 阅读 · 0 评论 -
LeetCode||83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.遍历所有节点,对于每个节点,检查其后的一个节点是否原创 2018-01-10 09:27:36 · 192 阅读 · 0 评论 -
LeetCode||96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2018-02-02 15:25:24 · 276 阅读 · 0 评论 -
LeetCode||90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2],原创 2018-01-19 17:24:36 · 261 阅读 · 0 评论 -
LeetCode||98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right ...原创 2018-05-03 14:43:41 · 251 阅读 · 0 评论 -
LeetCode||99. Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Example 1:Input: [1,3,null,null,2] 1 / 3 \ 2Output: [3,1,null,null,2] ...原创 2018-05-03 14:49:26 · 224 阅读 · 0 评论 -
LeetCode||89. Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2018-01-17 10:50:39 · 286 阅读 · 0 评论 -
LeetCode||88. 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原创 2018-01-17 10:39:46 · 210 阅读 · 0 评论 -
LeetCode||84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o原创 2018-01-12 14:10:25 · 222 阅读 · 0 评论 -
LeetCode||85. Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1原创 2018-01-12 15:27:02 · 281 阅读 · 0 评论