
LeetCode
船桥
这个作者很懒,什么都没留下…
展开
-
LeetCode43. Multiply Strings(思路及python解法)
Given two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Exampl...原创 2020-01-16 11:45:12 · 587 阅读 · 0 评论 -
LeetCode40. Combination Sum II(思路及python解法)
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidatesmay...原创 2020-01-16 11:09:40 · 443 阅读 · 0 评论 -
LeetCode80. Remove Duplicates from Sorted Array II(思路及python解法)
Given a sorted arraynums, remove the duplicatesin-placesuch that duplicates appeared at mosttwiceand return the new length.Do not allocate extra space for another array, you must do this bymod...原创 2020-01-15 21:47:07 · 388 阅读 · 0 评论 -
LeetCode31. Next Permutation(思路及python解法)
Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o...原创 2020-01-15 20:46:28 · 351 阅读 · 0 评论 -
LeetCode16. 3Sum Closest(思路及python解法)
Given an arraynumsofnintegers and an integertarget, find three integers innumssuch that the sum is closest totarget. Return the sum of the three integers. You may assume that each input would ...原创 2020-01-15 11:52:22 · 363 阅读 · 0 评论 -
LeetCode18. 4Sum (思路及python解法)
Given an arraynumsofnintegers and an integertarget, are there elementsa,b,c, anddinnumssuch thata+b+c+d=target? Find all unique quadruplets in the array which gives the sum oftar...原创 2020-01-14 21:54:53 · 286 阅读 · 0 评论 -
LeetCode1038. Binary Search Tree to Greater Sum Tree(思路及python解法)
Given the root of a binarysearchtree with distinct values, modify it so that everynodehas a new value equal to the sum of the values of the original tree that are greater than or equal tonode.val...原创 2020-01-14 17:53:53 · 281 阅读 · 0 评论 -
LeetCode29. Divide Two Integers(思路及python解法)
Given two integersdividendanddivisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividingdividendbydivisor.The integer division sho...原创 2020-01-12 21:52:09 · 533 阅读 · 1 评论 -
LeetCode146. LRU Cache(思路及python解法)
Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...原创 2020-01-12 19:15:50 · 373 阅读 · 0 评论 -
LeetCode328. Odd Even Linked List(思路及python解法)
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 p...原创 2020-01-12 18:27:02 · 308 阅读 · 0 评论 -
LeetCode134. Gas Station(思路及python解法)
There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its ...原创 2020-01-12 17:55:39 · 441 阅读 · 0 评论 -
LeetCode334. Increasing Triplet Subsequence(思路及python解法)
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there existsi, j, ksuch thatarr[i]<arr[j...原创 2020-01-12 17:00:22 · 233 阅读 · 0 评论 -
LeetCode395. Longest Substring with At Least K Repeating Characters(思路及python解法)
Find the length of the longest substringTof a given string (consists of lowercase letters only) such that every character inTappears no less thanktimes.Example 1:Input:s = "aaabb", k = 3...原创 2020-01-11 22:29:35 · 278 阅读 · 0 评论 -
LeetCode454. 4Sum II(思路及python解法)
Given four lists A, B, C, D of integer values, compute how many tuples(i, j, k, l)there are such thatA[i] + B[j] + C[k] + D[l]is zero.To make problem a bit easier, all A, B, C, D have same lengt...原创 2020-01-11 21:43:44 · 256 阅读 · 0 评论 -
LeetCode166. Fraction to Recurring Decimal(思路及python解法)
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.Exa...原创 2020-01-10 23:12:38 · 433 阅读 · 0 评论 -
LeetCode150. Evaluate Reverse Polish Notation(思路及python解法)
Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Note:Division between two integers ...原创 2020-01-10 22:29:07 · 311 阅读 · 0 评论 -
LeetCode322. Coin Change(思路及python解法)
You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money ...原创 2020-01-10 20:57:56 · 601 阅读 · 0 评论 -
LeetCode240. Search a 2D Matrix II(思路及python解法)
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Integers in each...原创 2020-01-09 23:21:48 · 270 阅读 · 0 评论 -
LeetCode227. Basic Calculator II(思路及python解法)
Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty spaces. The integer division should tru...原创 2020-01-08 22:20:18 · 355 阅读 · 0 评论 -
LeetCode222. Count Complete Tree Nodes (思路及python解法)
Given acompletebinary tree, count the number of nodes.Note:Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except possibly the last, is completely fil...原创 2020-01-04 21:00:28 · 311 阅读 · 0 评论 -
LeetCode404. Sum of Left Leaves(思路及python解法)
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....原创 2020-01-03 17:36:16 · 258 阅读 · 0 评论 -
LeetCode236. Lowest Common Ancestor of a Binary Tree(思路及python解法)
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p...原创 2020-01-02 22:45:10 · 355 阅读 · 0 评论 -
LeetCode179. Largest Number(思路及python解法)
Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: "210"Example 2:Input: [3,30,34,5,9]Output: "9534330"将数组中的数组合成一...原创 2020-01-02 18:47:46 · 482 阅读 · 0 评论 -
LeetCode131. Palindrome Partitioning(思路及python解法)
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.Example:Input:"aab"Output:[ ["aa","b"], ["a","a"...原创 2019-12-30 15:57:17 · 324 阅读 · 0 评论 -
LeetCode79. Word Search(思路及python解法)
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 n...原创 2019-12-29 21:54:46 · 317 阅读 · 0 评论 -
LeetCode39. Combination Sum(思路及python解法)
ShareGiven asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesame...原创 2019-12-29 01:09:12 · 330 阅读 · 0 评论 -
LeetCode54. Spiral Matrix(思路及python解法)
Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]...原创 2019-12-28 16:24:21 · 372 阅读 · 1 评论 -
LeetCode36. Valid Sudoku(思路及python解法)
Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must conta...原创 2019-12-27 16:38:29 · 243 阅读 · 0 评论 -
LeetCode22. Generate Parentheses(思路及python解法)
Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())"...原创 2019-12-26 21:25:45 · 217 阅读 · 0 评论 -
LeetCode15. 3Sum(思路及python解法)
Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not cont...原创 2019-12-26 20:59:11 · 328 阅读 · 0 评论 -
LeetCode73. Set Matrix Zeroes(思路及python解法)
Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]]将...原创 2019-12-21 15:58:32 · 293 阅读 · 0 评论 -
LeetCode56. Merge Intervals(思路及python解法)
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...原创 2019-12-20 22:56:30 · 1011 阅读 · 0 评论 -
LeetCode55. Jump Game(思路及python解法)
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.Determine if yo...原创 2019-12-20 21:20:12 · 244 阅读 · 0 评论 -
LeetCode50. Pow(x, n)(思路及python解法)
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...原创 2019-12-20 19:19:08 · 249 阅读 · 0 评论 -
LeetCode41. First Missing Positive(思路及python解法)
Given an unsorted integer array, find the smallest missingpositive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Outpu...原创 2019-12-20 18:22:50 · 259 阅读 · 0 评论 -
LeetCode49. Group Anagrams (思路及python解法)
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["bat"]]把相同字母,不同顺序的单词放在一起。思路就...原创 2019-12-20 18:03:02 · 393 阅读 · 0 评论 -
LeetCode34. Find First and Last Position of Element in Sorted Array (思路及python解法)
Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Your algorithm's runtime complexity must be in the order ofO(logn).If the...原创 2019-12-19 23:27:25 · 235 阅读 · 0 评论 -
LeetCode17. Letter Combinations of a Phone Number(思路及python解法)
Given a string containing digits from2-9inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is giv...原创 2019-12-19 23:27:49 · 156 阅读 · 0 评论 -
LeetCode11. Container With Most Water (思路及python解法)
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two...原创 2019-12-19 10:54:50 · 239 阅读 · 0 评论 -
LeetCode8. String to Integer (atoi)(思路及python解法)
Implementatoiwhichconverts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from thi...原创 2019-12-18 22:25:11 · 169 阅读 · 0 评论