
python
文章平均质量分 57
徐州牧
这个作者很懒,什么都没留下…
展开
-
LeetCode||100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...原创 2018-05-03 14:53:16 · 282 阅读 · 0 评论 -
LeetCode||80. 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原创 2018-01-05 13:58:40 · 211 阅读 · 0 评论 -
LeetCode||79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2017-12-29 15:16:40 · 242 阅读 · 0 评论 -
LeetCode||78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:原创 2017-12-29 14:01:29 · 191 阅读 · 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 · 295 阅读 · 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 · 233 阅读 · 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 · 235 阅读 · 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 · 195 阅读 · 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 · 225 阅读 · 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 · 329 阅读 · 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 · 260 阅读 · 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 · 287 阅读 · 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 · 273 阅读 · 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 · 243 阅读 · 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 · 253 阅读 · 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 · 251 阅读 · 0 评论 -
LeetCode||81. Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending order is rotated a原创 2018-01-05 16:09:00 · 252 阅读 · 0 评论 -
LeetCode||86. Partition List
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原创 2018-01-15 14:13:27 · 280 阅读 · 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 · 241 阅读 · 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 · 266 阅读 · 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 · 275 阅读 · 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 · 295 阅读 · 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 · 208 阅读 · 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 · 221 阅读 · 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 · 317 阅读 · 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 · 254 阅读 · 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 · 262 阅读 · 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 · 246 阅读 · 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 · 310 阅读 · 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 · 220 阅读 · 0 评论 -
LeetCode||92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the原创 2018-01-24 11:05:03 · 198 阅读 · 0 评论 -
LeetCode||91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total numb原创 2018-01-24 10:33:10 · 219 阅读 · 0 评论 -
LeetCode||87. Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr原创 2018-01-15 16:18:57 · 241 阅读 · 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 · 236 阅读 · 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 · 242 阅读 · 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 · 203 阅读 · 0 评论 -
LeetCode||54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]原创 2017-11-09 14:08:46 · 215 阅读 · 0 评论 -
Leetcode||46. permutations
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1原创 2017-10-23 16:15:05 · 199 阅读 · 0 评论 -
Leetcode||45. Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2017-10-23 13:59:36 · 204 阅读 · 0 评论 -
LeetCode||53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] ha原创 2017-11-08 15:24:50 · 186 阅读 · 0 评论