![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode1
文章平均质量分 80
1.02^365的成长裂变
每天比别人努力一点,坚持下去就是裂变的威力~
展开
-
[LeetCode] Best Time to Buy and Sell Stock
[Problem]Say you have an array for which the ithelement is the price of a given stock on day i.If you were only permitted to complete at most one transaction(ie, buy one and sell one share of the原创 2017-09-10 20:40:34 · 3721 阅读 · 0 评论 -
[LeetCode] Binary Tree Inorder Traversal
[Problem]Given a binary tree, return the inorder traversal of itsnodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is triv原创 2017-09-10 20:40:36 · 3618 阅读 · 0 评论 -
[LeetCode] Balanced Binary Tree
[Problem]Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as abinary tree in which the depth of the two subtrees of everynode neve原创 2017-09-10 20:40:39 · 3562 阅读 · 0 评论 -
[LeetCode] Climbing Stairs
[Problem]You are climbing a stair case. It takes n steps to reachto the top.Each time you can either climb 1 or 2 steps. In how manydistinct ways can you climb to the top?[Analysis]Fibnocci Seq原创 2017-09-10 20:40:42 · 3569 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal
[Problem]Given a binary tree, return the level order traversal ofits nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 2原创 2017-09-10 20:40:45 · 3561 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal II
[Problem]Given a binary tree, return the bottom-up level ordertraversal of its nodes' values. (ie, from left to right, level bylevel from leaf to root).For example:Given binary tree {3,9,20,#,#,1原创 2017-09-10 20:40:48 · 3569 阅读 · 0 评论 -
[LeetCode] Binary Tree Zigzag Level Order Traversal
[Problem]Given a binary tree, return the zigzag level ordertraversal of its nodes' values. (ie, from left to right, then rightto left for the next level and alternate between).For example:Given b原创 2017-09-10 20:40:51 · 3602 阅读 · 0 评论 -
[LeetCode] Binary Tree Maximum Path Sum
[Problem]Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \2 3Return 6.[Analysis]第一步:在每个结点i原创 2017-09-10 20:40:54 · 3584 阅读 · 0 评论 -
[LeetCode] 3Sum Closest
[Problem]Given an array S of n integers, find threeintegers in S such that the sum is closest to a givennumber, target. Return the sum of the three integers. You mayassume that each input would ha原创 2017-09-10 20:40:57 · 3594 阅读 · 0 评论 -
[LeetCode] Add Binary
[Problem]Given two binary strings, return their sum (also a binarystring).For example,a = "11"b = "1"Return "100".[Analysis]二进制字符串加法,先将两个字符串反转,然后进行加法(注意二进制满二进一),最后将结果反转。[Solution]class Sol原创 2017-09-10 20:41:00 · 3555 阅读 · 0 评论 -
[LeetCode] Add Two Numbers
[Problem]You are given two linked lists representing two non-negativenumbers. The digits are stored in reverse order and each of theirnodes contain a single digit. Add the two numbers and return it原创 2017-09-10 20:41:03 · 3573 阅读 · 0 评论 -
[LeetCode] Anagrams
[Problem]Given an array of strings, return all groups of strings that areanagrams.Note: All inputs will be in lower-case.[Analysis]寻找兄弟字符串。两个字符串包含的字符完全一样,但是顺序不一定一致的字符串,称为兄弟字符串,例如"eat"和"aet"是兄弟字符原创 2017-09-10 20:41:06 · 3588 阅读 · 0 评论 -
[LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
[Problem]Given inorder and postorder traversal of a tree, construct thebinary tree.Note:You may assume that duplicates do not exist in the tree.[Solution]class Solution {public: // find elem原创 2017-09-10 20:41:09 · 3569 阅读 · 0 评论 -
[LeetCode] Construct Binary Tree from Preorder and Inorder Traversal
[Problem]Given preorder and inorder traversal of a tree, construct thebinary tree.Note:You may assume that duplicates do not exist in the tree.[Solution]class Solution {public: // find eleme原创 2017-09-10 20:41:12 · 3603 阅读 · 0 评论 -
[LeetCode] Container With Most Water
[Problem]Given n non-negative integersa1, a2, ...,an, where each represents a point at coordinate(i, ai). n vertical lines are drawnsuch that the two endpoints of line i is at (i,ai) and (i, 0).原创 2017-09-10 20:41:14 · 3556 阅读 · 0 评论 -
[LeetCode] Count and Say
[Problem]The count-and-say sequence is the sequence of integers beginningas follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or11.11 is read off as "two 1s" or21.21 is read off as原创 2017-09-10 20:41:17 · 3559 阅读 · 0 评论 -
[LeetCode] Combinations
[Problem]Given two integers n and k, return all possiblecombinations 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,原创 2017-09-10 20:41:20 · 3542 阅读 · 0 评论 -
[LeetCode] 4Sum
[Problem]Given an array S of n integers, are there elementsa, b, c, and d in S such thata + b + c + d = target? Find all uniquequadruplets in the array which gives the sum of target.Note:Elemen原创 2017-09-10 20:41:23 · 3558 阅读 · 0 评论 -
[LeetCode] Combination Sum II
[Problem]Given a collection of candidate numbers (C) and atarget number (T), find all unique combinations inC where the candidate numbers sums toT.Each number in C may only be used once inthe co原创 2017-09-10 20:41:25 · 3547 阅读 · 0 评论 -
[LeetCode] Combination Sum
[Problem]Given a set of candidate numbers (C) and a targetnumber (T), find all unique combinations inC where the candidate numbers sums toT.The same repeated number may be chosen fromC unlimited原创 2017-09-10 20:41:28 · 3541 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock II
[Problem]Say you have an array for which the ithelement is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may completeas many transactions as you like (ie,原创 2017-09-10 20:41:31 · 3568 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock III
[Problem]Say you have an array for which the ithelement is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may completeat most two transactions.Note:You m原创 2017-09-10 20:41:34 · 3555 阅读 · 0 评论 -
[LeetCode] Edit Distance
[Problem]Given two words word1 and word2, find the minimumnumber of steps required to convert word1 to word2.(each operation is counted as 1 step.)You have the following 3 operations permitted on原创 2017-09-10 20:41:37 · 3555 阅读 · 0 评论 -
[LeetCode] Flatten Binary Tree to Linked List
[Problem]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 \ 2 \ 3原创 2017-09-10 20:41:40 · 3546 阅读 · 0 评论 -
[LeetCode] Gray Code
[Problem]The gray code is a binary numeral system where two successivevalues differ in only one bit.Given a non-negative integer n representing the totalnumber of bits in the code, print the seque原创 2017-09-10 20:41:43 · 3564 阅读 · 0 评论 -
[LeetCode] Decode Ways
[Problem]A message containing letters from A-Z is beingencoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the tota原创 2017-09-10 20:41:45 · 3565 阅读 · 0 评论 -
[LeetCode] Generate Parentheses
[Problem]Given n pairs of parentheses, write a function togenerate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())","原创 2017-09-10 20:41:49 · 3633 阅读 · 0 评论 -
[LeetCode] Implement strStr()
[Problem]Implement strStr().Returns a pointer to the first occurrence of needle in haystack,or null if needle is not part of haystack.[Solution]class Solution {public: char *strStr(char *hayst原创 2017-09-10 20:41:51 · 3561 阅读 · 0 评论 -
[LeetCode] Insert Interval
[Problem]Given a set of non-overlapping intervals, insert a newinterval into the intervals (merge if necessary).You may assume that the intervals were initially sortedaccording to their start time原创 2017-09-10 20:41:54 · 3553 阅读 · 0 评论 -
[LeetCode] First Missing Positive
[Problem]Given an unsorted integer array, find the first missing positiveinteger.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and usesconsta原创 2017-09-10 20:41:57 · 3561 阅读 · 0 评论 -
[LeetCode] Length of Last Word
[Problem]Given a string s consists of upper/lower-case alphabetsand empty space characters ' ', return the length oflast word in the string.If the last word does not exist, return 0.Note: A word原创 2017-09-10 20:42:00 · 3585 阅读 · 0 评论 -
[LeetCode] Longest Consecutive Sequence
[Problem]Given an unsorted array of integers, find the length of thelongest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1,原创 2017-09-10 20:42:03 · 3561 阅读 · 0 评论 -
[LeetCode] Distinct Subsequences
[Problem]Given a string S and a string T, count the numberof distinct subsequences of T in S.A subsequence of a string is a new string which is formed fromthe original string by deleting some (can原创 2017-09-10 20:42:05 · 3552 阅读 · 0 评论 -
[LeetCode] Jump Game
[Problem]Given an array of non-negative integers, you are initiallypositioned at the first index of the array.Each element in the array represents your maximum jump length atthat position.Determi原创 2017-09-10 20:42:08 · 3543 阅读 · 0 评论 -
[LeetCode] Jump Game II
[Problem]Given an array of non-negative integers, you are initiallypositioned at the first index of the array.Each element in the array represents your maximum jump length atthat position.Your go原创 2017-09-10 20:42:11 · 3568 阅读 · 0 评论 -
[LeetCode] Longest Valid Parentheses
[Problem]Given a string containing just the characters '('and ')', find the length of the longest valid(well-formed) parentheses substring.For "(()", the longest valid parentheses substringis "()原创 2017-09-10 20:42:14 · 3579 阅读 · 0 评论 -
[LeetCode] Integer to Roman
[Problem]Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.[Solution]class Solution {public: string intToRoman(int num) { // Start原创 2017-09-10 20:42:17 · 3566 阅读 · 0 评论 -
[LeetCode] Divide Two Integers
[Problem]Divide two integers without using multiplication, division and modoperator.[Analysis]注意以下几点:(1)被除数和除数为0(2)被除数或除数为0(3)正负号,确定正负号后,最好将被除数和除数都转换为正数操作(4)将int dividend 和 int divisor转换成unsi原创 2017-09-10 20:42:20 · 3576 阅读 · 0 评论 -
[LeetCode] Largest Rectangle in Histogram
[Problem]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原创 2017-09-10 20:42:23 · 3587 阅读 · 0 评论 -
[LeetCode] Letter Combinations of a Phone Number
[Problem]Given a digit string, return all possible letter combinationsthat the number could represent.A mapping of digit to letters (just like on the telephonebuttons) is given below.Input:Digit原创 2017-09-10 20:42:26 · 3588 阅读 · 0 评论