From 7a7d3f20b2969469e2f5d720200bf9a7dfd764d0 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Tue, 20 Oct 2020 11:19:27 +0000 Subject: [PATCH] docs: prettify code --- .docsifytopdfrc.js | 12 +- README.md | 6 +- README_EN.md | 13 +- basic/README.md | 2 +- basic/README_EN.md | 2 +- basic/sorting/BubbleSort/README.md | 2 +- basic/sorting/MergeSort/README.md | 2 +- basic/sorting/QuickSort/README.md | 3 +- basic/summary.md | 10 +- lcci/01.01.Is Unique/README.md | 10 +- lcci/01.01.Is Unique/README_EN.md | 8 +- lcci/01.02.Check Permutation/README.md | 9 +- lcci/01.02.Check Permutation/README_EN.md | 18 +- lcci/01.03.String to URL/README.md | 11 +- lcci/01.03.String to URL/README_EN.md | 22 +- lcci/01.04.Palindrome Permutation/README.md | 9 +- .../01.04.Palindrome Permutation/README_EN.md | 11 +- lcci/01.05.One Away/README.md | 9 +- lcci/01.05.One Away/README_EN.md | 10 +- lcci/01.06.Compress String/README.md | 9 +- lcci/01.06.Compress String/README_EN.md | 13 +- lcci/01.07.Rotate Matrix/README.md | 8 +- lcci/01.07.Rotate Matrix/README_EN.md | 18 +- lcci/01.08.Zero Matrix/README.md | 14 +- lcci/01.08.Zero Matrix/README_EN.md | 24 +- lcci/01.09.String Rotation/README.md | 7 +- lcci/01.09.String Rotation/README_EN.md | 21 +- lcci/02.01.Remove Duplicate Node/README.md | 9 +- lcci/02.01.Remove Duplicate Node/README_EN.md | 17 +- .../02.02.Kth Node From End of List/README.md | 9 +- .../README_EN.md | 14 +- lcci/02.03.Delete Middle Node/README.md | 9 +- lcci/02.03.Delete Middle Node/README_EN.md | 14 +- lcci/02.04.Partition List/README.md | 9 +- lcci/02.04.Partition List/README_EN.md | 12 +- lcci/02.05.Sum Lists/README.md | 9 +- lcci/02.05.Sum Lists/README_EN.md | 20 +- lcci/02.06.Palindrome Linked List/README.md | 9 +- .../02.06.Palindrome Linked List/README_EN.md | 19 +- .../README.md | 8 +- .../README_EN.md | 18 +- lcci/02.08.Linked List Cycle/README.md | 8 +- lcci/02.08.Linked List Cycle/README_EN.md | 24 +- lcci/03.01.Three in One/README.md | 17 +- lcci/03.01.Three in One/README_EN.md | 28 +- lcci/03.02.Min Stack/README.md | 17 +- lcci/03.02.Min Stack/README_EN.md | 20 +- lcci/03.03.Stack of Plates/README.md | 9 +- lcci/03.03.Stack of Plates/README_EN.md | 18 +- .../README.md | 16 +- .../README_EN.md | 28 +- lcci/03.05.Sort of Stacks/README.md | 17 +- lcci/03.05.Sort of Stacks/README_EN.md | 28 +- lcci/03.06.Animal Shelter/README.md | 17 +- lcci/03.06.Animal Shelter/README_EN.md | 32 +- lcci/04.01.Route Between Nodes/README.md | 9 +- lcci/04.01.Route Between Nodes/README_EN.md | 20 +- lcci/04.02.Minimum Height Tree/README.md | 8 +- lcci/04.02.Minimum Height Tree/README_EN.md | 12 +- lcci/04.03.List of Depth/README.md | 9 +- lcci/04.03.List of Depth/README_EN.md | 14 +- lcci/04.04.Check Balance/README.md | 8 +- lcci/04.04.Check Balance/README_EN.md | 18 +- lcci/04.05.Legal Binary Search Tree/README.md | 8 +- .../README_EN.md | 16 +- lcci/04.06.Successor/README.md | 9 +- lcci/04.06.Successor/README_EN.md | 18 +- lcci/04.08.First Common Ancestor/README.md | 8 +- lcci/04.08.First Common Ancestor/README_EN.md | 22 +- lcci/04.09.BST Sequences/README.md | 9 +- lcci/04.09.BST Sequences/README_EN.md | 16 +- lcci/04.10.Check SubTree/README.md | 11 +- lcci/04.10.Check SubTree/README_EN.md | 24 +- lcci/04.12.Paths with Sum/README.md | 16 +- lcci/04.12.Paths with Sum/README_EN.md | 25 +- lcci/05.01.Insert Into Bits/README.md | 9 +- lcci/05.01.Insert Into Bits/README_EN.md | 16 +- lcci/05.02.Bianry Number to String/README.md | 9 +- .../README_EN.md | 20 +- lcci/05.03.Reverse Bits/README.md | 9 +- lcci/05.03.Reverse Bits/README_EN.md | 16 +- lcci/05.04.Closed Number/README.md | 9 +- lcci/05.04.Closed Number/README_EN.md | 20 +- lcci/05.06.Convert Integer/README.md | 9 +- lcci/05.06.Convert Integer/README_EN.md | 20 +- lcci/05.07.Exchange/README.md | 9 +- lcci/05.07.Exchange/README_EN.md | 20 +- lcci/05.08.Draw Line/README.md | 9 +- lcci/05.08.Draw Line/README_EN.md | 16 +- lcci/08.01.Three Steps Problem/README.md | 9 +- lcci/08.01.Three Steps Problem/README_EN.md | 15 +- lcci/08.02.Robot in a Grid/README.md | 9 +- lcci/08.02.Robot in a Grid/README_EN.md | 14 +- lcci/08.03.Magic Index/README.md | 9 +- lcci/08.03.Magic Index/README_EN.md | 18 +- lcci/08.04.Power Set/README.md | 9 +- lcci/08.04.Power Set/README_EN.md | 14 +- lcci/08.05.Recursive Mulitply/README.md | 9 +- lcci/08.05.Recursive Mulitply/README_EN.md | 20 +- lcci/08.06.Hanota/README.md | 9 +- lcci/08.06.Hanota/README_EN.md | 24 +- lcci/08.07.Permutation I/README.md | 9 +- lcci/08.07.Permutation I/README_EN.md | 20 +- lcci/08.08.Permutation II/README.md | 9 +- lcci/08.08.Permutation II/README_EN.md | 20 +- lcci/08.09.Bracket/README.md | 11 +- lcci/08.09.Bracket/README_EN.md | 14 +- lcci/08.10.Color Fill/README.md | 9 +- lcci/08.10.Color Fill/README_EN.md | 16 +- lcci/08.11.Coin/README.md | 9 +- lcci/08.11.Coin/README_EN.md | 21 +- lcci/08.12.Eight Queens/README.md | 9 +- lcci/08.12.Eight Queens/README_EN.md | 14 +- lcci/08.13.Pile Box/README.md | 9 +- lcci/08.13.Pile Box/README_EN.md | 10 +- lcci/08.14.Boolean Evaluation/README.md | 9 +- lcci/08.14.Boolean Evaluation/README_EN.md | 18 +- lcci/10.01.Sorted Merge/README.md | 9 +- lcci/10.01.Sorted Merge/README_EN.md | 14 +- lcci/10.02.Group Anagrams/README.md | 9 +- lcci/10.02.Group Anagrams/README_EN.md | 18 +- lcci/10.03.Search Rotate Array/README.md | 9 +- lcci/10.03.Search Rotate Array/README_EN.md | 18 +- lcci/10.05.Sparse Array Search/README.md | 9 +- lcci/10.05.Sparse Array Search/README_EN.md | 19 +- lcci/10.09.Sorted Matrix Search/README.md | 9 +- lcci/10.09.Sorted Matrix Search/README_EN.md | 18 +- lcci/10.10.Rank from Stream/README.md | 9 +- lcci/10.10.Rank from Stream/README_EN.md | 16 +- lcci/10.11.Peaks and Valleys/README.md | 9 +- lcci/10.11.Peaks and Valleys/README_EN.md | 14 +- lcci/16.01.Swap Numbers/README.md | 9 +- lcci/16.01.Swap Numbers/README_EN.md | 16 +- lcci/16.02.Words Frequency/README.md | 9 +- lcci/16.02.Words Frequency/README_EN.md | 28 +- lcci/16.03.Intersection/README.md | 9 +- lcci/16.03.Intersection/README_EN.md | 24 +- lcci/16.04.Tic-Tac-Toe/README.md | 9 +- lcci/16.04.Tic-Tac-Toe/README_EN.md | 30 +- lcci/16.05.Factorial Zeros/README.md | 9 +- lcci/16.05.Factorial Zeros/README_EN.md | 18 +- lcci/16.06.Smallest Difference/README.md | 11 +- lcci/16.06.Smallest Difference/README_EN.md | 18 +- lcci/16.07.Maximum/README.md | 9 +- lcci/16.07.Maximum/README_EN.md | 12 +- lcci/16.08.English Int/README.md | 9 +- lcci/16.08.English Int/README_EN.md | 24 +- lcci/16.09.Operations/README.md | 9 +- lcci/16.09.Operations/README_EN.md | 24 +- lcci/16.10.Living People/README.md | 9 +- lcci/16.10.Living People/README_EN.md | 18 +- lcci/16.11.Diving Board/README.md | 9 +- lcci/16.11.Diving Board/README_EN.md | 18 +- lcci/16.13.Bisect Squares/README.md | 9 +- lcci/16.13.Bisect Squares/README_EN.md | 20 +- lcci/16.14.Best Line/README.md | 9 +- lcci/16.14.Best Line/README_EN.md | 18 +- lcci/16.15.Master Mind/README.md | 9 +- lcci/16.15.Master Mind/README_EN.md | 26 +- lcci/16.16.Sub Sort/README.md | 9 +- lcci/16.16.Sub Sort/README_EN.md | 18 +- lcci/16.17.Contiguous Sequence/README.md | 9 +- lcci/16.17.Contiguous Sequence/README_EN.md | 16 +- lcci/16.18.Pattern Matching/README.md | 9 +- lcci/16.18.Pattern Matching/README_EN.md | 28 +- lcci/16.19.Pond Sizes/README.md | 9 +- lcci/16.19.Pond Sizes/README_EN.md | 16 +- lcci/16.20.T9/README.md | 11 +- lcci/16.20.T9/README_EN.md | 19 +- lcci/16.21.Sum Swap/README.md | 9 +- lcci/16.21.Sum Swap/README_EN.md | 22 +- lcci/16.22.Langtons Ant/README.md | 9 +- lcci/16.22.Langtons Ant/README_EN.md | 34 +- lcci/16.24.Pairs With Sum/README.md | 9 +- lcci/16.24.Pairs With Sum/README_EN.md | 20 +- lcci/16.25.LRU Cache/README.md | 11 +- lcci/16.25.LRU Cache/README_EN.md | 16 +- lcci/16.26.Calculator/README.md | 9 +- lcci/16.26.Calculator/README_EN.md | 26 +- lcci/17.01.Add Without Plus/README.md | 9 +- lcci/17.01.Add Without Plus/README_EN.md | 18 +- lcci/17.04.Missing Number/README.md | 9 +- lcci/17.04.Missing Number/README_EN.md | 20 +- lcci/17.05.Find Longest Subarray/README.md | 11 +- lcci/17.05.Find Longest Subarray/README_EN.md | 22 +- lcci/17.06.Number Of 2s In Range/README.md | 11 +- lcci/17.06.Number Of 2s In Range/README_EN.md | 16 +- lcci/17.07.Baby Names/README.md | 9 +- lcci/17.07.Baby Names/README_EN.md | 16 +- lcci/17.08.Circus Tower/README.md | 9 +- lcci/17.08.Circus Tower/README_EN.md | 16 +- lcci/17.09.Get Kth Magic Number/README.md | 9 +- lcci/17.09.Get Kth Magic Number/README_EN.md | 12 +- lcci/17.10.Find Majority Element/README.md | 9 +- lcci/17.10.Find Majority Element/README_EN.md | 24 +- lcci/17.11.Find Closest/README.md | 9 +- lcci/17.11.Find Closest/README_EN.md | 15 +- lcci/17.12.BiNode/README.md | 9 +- lcci/17.12.BiNode/README_EN.md | 22 +- lcci/17.13.Re-Space/README.md | 9 +- lcci/17.13.Re-Space/README_EN.md | 20 +- lcci/17.14.Smallest K/README.md | 11 +- lcci/17.14.Smallest K/README_EN.md | 16 +- lcci/17.15.Longest Word/README.md | 9 +- lcci/17.15.Longest Word/README_EN.md | 16 +- lcci/17.16.The Masseuse/README.md | 10 +- lcci/17.16.The Masseuse/README_EN.md | 24 +- lcci/17.17.Multi Search/README.md | 9 +- lcci/17.17.Multi Search/README_EN.md | 16 +- lcci/17.18.Shortest Supersequence/README.md | 9 +- .../17.18.Shortest Supersequence/README_EN.md | 22 +- lcci/17.19.Missing Two/README.md | 15 +- lcci/17.19.Missing Two/README_EN.md | 26 +- lcci/17.20.Continuous Median/README.md | 15 +- lcci/17.20.Continuous Median/README_EN.md | 28 +- lcci/17.21.Volume of Histogram/README.md | 9 +- lcci/17.21.Volume of Histogram/README_EN.md | 16 +- lcci/17.22.Word Transformer/README.md | 9 +- lcci/17.22.Word Transformer/README_EN.md | 18 +- lcci/17.23.Max Black Square/README.md | 9 +- lcci/17.23.Max Black Square/README_EN.md | 22 +- lcci/17.24.Max Submatrix/README.md | 9 +- lcci/17.24.Max Submatrix/README_EN.md | 20 +- lcci/17.25.Word Rectangle/README.md | 9 +- lcci/17.25.Word Rectangle/README_EN.md | 22 +- lcci/17.26.Sparse Similarity/README.md | 9 +- lcci/17.26.Sparse Similarity/README_EN.md | 18 +- lcci/README.md | 227 +- lcci/README_EN.md | 231 +- lcci/summary.md | 218 +- lcci/summary_en.md | 218 +- lcof/README.md | 162 +- lcof/README_EN.md | 7 +- lcof/README_TEMPLATE.md | 7 +- lcof/summary.md | 150 +- .../README.md" | 29 +- .../Solution.js" | 14 +- .../README.md" | 49 +- .../Solution.js" | 30 +- .../README.md" | 15 +- .../Solution.js" | 6 +- .../README.md" | 11 +- .../Solution.js" | 18 +- .../README.md" | 52 +- .../Solution.js" | 40 +- .../README.md" | 57 +- .../Solution.js" | 38 +- .../README.md" | 35 +- .../Solution.js" | 22 +- .../README.md" | 37 +- .../Solution.js" | 22 +- .../README.md" | 43 +- .../Solution.js" | 30 +- .../README.md" | 82 +- .../Solution.js" | 68 +- .../README.md" | 85 +- .../Solution.js" | 70 +- .../README.md" | 56 +- .../Solution.js" | 40 +- .../README.md" | 47 +- .../Solution.js" | 34 +- .../README.md" | 27 +- .../Solution.js" | 16 +- .../README.md" | 53 +- .../Solution.js" | 32 +- .../README.md" | 23 +- .../Solution.js" | 14 +- .../README.md" | 38 +- .../Solution.js" | 30 +- .../README.md" | 55 +- .../Solution.js" | 34 +- .../README.md" | 16 +- .../Solution.js" | 6 +- .../README.md" | 40 +- .../Solution.js" | 30 +- .../README.md" | 61 +- .../Solution.js" | 48 +- .../README.md" | 32 +- .../Solution.js" | 22 +- .../README.md" | 80 +- .../Solution.js" | 70 +- .../README.md" | 67 +- .../Solution.js" | 52 +- .../README.md" | 33 +- .../Solution.js" | 22 +- .../README.md" | 33 +- .../Solution.js" | 18 +- .../README.md" | 75 +- .../Solution.js" | 65 +- .../README.md" | 56 +- .../Solution.js" | 38 +- .../README.md" | 52 +- .../Solution.js" | 38 +- .../README.md" | 35 +- .../Solution.js" | 24 +- .../README.md" | 43 +- .../Solution.js" | 34 +- .../README.md" | 57 +- .../Solution.js" | 46 +- .../README.md" | 43 +- .../Solution.js" | 27 +- .../README.md" | 47 +- .../Solution.js" | 30 +- .../README.md" | 40 +- .../Solution.js" | 26 +- .../README.md" | 58 +- .../Solution.js" | 48 +- .../README.md" | 82 +- .../Solution.js" | 66 +- .../README.md" | 44 +- .../Solution.js" | 34 +- .../README.md" | 38 +- .../Solution.js" | 28 +- .../README.md" | 72 +- .../Solution.js" | 62 +- .../README.md" | 60 +- .../Solution.js" | 40 +- .../README.md" | 32 +- .../Solution.js" | 20 +- .../README.md" | 51 +- .../Solution.js" | 35 +- .../README.md" | 50 +- .../Solution.js" | 34 +- .../README.md" | 36 +- .../Solution.js" | 20 +- .../README.md" | 42 +- .../Solution.js" | 32 +- .../README.md" | 30 +- .../Solution.js" | 20 +- .../README.md" | 52 +- .../Solution.js" | 40 +- .../README.md" | 52 +- .../Solution.js" | 35 +- .../README.md" | 34 +- .../Solution.js" | 22 +- .../README.md" | 62 +- .../Solution.js" | 52 +- .../README.md" | 31 +- .../Solution.js" | 18 +- .../README.md" | 65 +- .../Solution.js" | 51 +- .../README.md" | 38 +- .../Solution.js" | 26 +- .../README.md" | 35 +- .../Solution.js" | 24 +- .../README.md" | 34 +- .../Solution.js" | 24 +- .../README.md" | 26 +- .../Solution.js" | 16 +- .../README.md" | 51 +- .../Solution.js" | 38 +- .../README.md" | 26 +- .../Solution.js" | 18 +- .../README.md" | 56 +- .../Solution.js" | 46 +- .../README.md" | 41 +- .../Solution.js" | 27 +- .../README.md" | 18 +- .../Solution.js" | 10 +- .../README.md" | 16 +- .../Solution.js" | 6 +- .../README.md" | 62 +- .../Solution.js" | 46 +- .../README.md" | 92 +- .../Solution.js" | 62 +- .../README.md" | 44 +- .../Solution.js" | 30 +- .../README.md" | 53 +- .../Solution.js" | 36 +- .../README.md" | 33 +- .../Solution.js" | 16 +- .../README.md" | 26 +- .../Solution.js" | 18 +- .../README.md" | 18 +- .../Solution.js" | 6 +- .../README.md" | 23 +- .../Solution.js" | 8 +- .../README.md" | 38 +- .../Solution.js" | 28 +- .../README.md" | 64 +- .../Solution.js" | 39 +- .../README.md" | 31 +- .../Solution.js" | 20 +- .../README.md" | 31 +- .../Solution.js" | 20 +- solution/0000-0099/0001.Two Sum/README.md | 10 +- solution/0000-0099/0001.Two Sum/README_EN.md | 14 +- solution/0000-0099/0001.Two Sum/Solution.js | 18 +- .../0000-0099/0002.Add Two Numbers/README.md | 10 +- .../0002.Add Two Numbers/README_EN.md | 14 +- .../0002.Add Two Numbers/Solution.js | 53 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../Solution.js | 37 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../Solution.js | 105 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../Solution.js | 50 +- .../0006.ZigZag Conversion/README.md | 10 +- .../0006.ZigZag Conversion/README_EN.md | 24 +- .../0006.ZigZag Conversion/Solution.js | 44 +- .../0000-0099/0007.Reverse Integer/README.md | 10 +- .../0007.Reverse Integer/README_EN.md | 22 +- .../0007.Reverse Integer/Solution.js | 37 +- .../0008.String to Integer (atoi)/README.md | 12 +- .../README_EN.md | 46 +- .../0008.String to Integer (atoi)/Solution.js | 25 +- .../0009.Palindrome Number/README.md | 10 +- .../0009.Palindrome Number/README_EN.md | 24 +- .../0009.Palindrome Number/Solution.js | 21 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0011.Container With Most Water/README.md | 10 +- .../README_EN.md | 17 +- .../Solution.js | 20 +- .../0000-0099/0012.Integer to Roman/README.md | 10 +- .../0012.Integer to Roman/README_EN.md | 44 +- .../0000-0099/0013.Roman to Integer/README.md | 10 +- .../0013.Roman to Integer/README_EN.md | 44 +- .../0013.Roman to Integer/Solution.js | 26 +- .../0014.Longest Common Prefix/README.md | 10 +- .../0014.Longest Common Prefix/README_EN.md | 22 +- .../0014.Longest Common Prefix/Solution.js | 14 +- solution/0000-0099/0015.3Sum/README.md | 10 +- solution/0000-0099/0015.3Sum/README_EN.md | 14 +- .../0000-0099/0016.3Sum Closest/README.md | 10 +- .../0000-0099/0016.3Sum Closest/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 17 +- solution/0000-0099/0018.4Sum/README.md | 10 +- solution/0000-0099/0018.4Sum/README_EN.md | 16 +- .../README.md | 12 +- .../README_EN.md | 20 +- .../Solution.js | 20 +- .../0020.Valid Parentheses/README.md | 10 +- .../0020.Valid Parentheses/README_EN.md | 38 +- .../0020.Valid Parentheses/Solution.js | 16 +- .../0021.Merge Two Sorted Lists/README.md | 10 +- .../0021.Merge Two Sorted Lists/README_EN.md | 8 +- .../0021.Merge Two Sorted Lists/Solution.js | 7 +- .../0022.Generate Parentheses/README.md | 10 +- .../0022.Generate Parentheses/README_EN.md | 8 +- .../0023.Merge k Sorted Lists/README.md | 12 +- .../0023.Merge k Sorted Lists/README_EN.md | 12 +- .../0024.Swap Nodes in Pairs/README.md | 10 +- .../0024.Swap Nodes in Pairs/README_EN.md | 16 +- .../0025.Reverse Nodes in k-Group/README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../Solution.js | 8 +- .../0000-0099/0027.Remove Element/README.md | 10 +- .../0027.Remove Element/README_EN.md | 28 +- .../0000-0099/0027.Remove Element/Solution.js | 26 +- .../0028.Implement strStr()/README.md | 12 +- .../0028.Implement strStr()/README_EN.md | 26 +- .../0028.Implement strStr()/Solution.js | 28 +- .../0029.Divide Two Integers/README.md | 10 +- .../0029.Divide Two Integers/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0000-0099/0031.Next Permutation/README.md | 10 +- .../0031.Next Permutation/README_EN.md | 16 +- .../0032.Longest Valid Parentheses/README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../Solution.js | 12 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0035.Search Insert Position/README.md | 10 +- .../0035.Search Insert Position/README_EN.md | 26 +- .../0035.Search Insert Position/Solution.js | 4 +- .../0000-0099/0036.Valid Sudoku/README.md | 10 +- .../0000-0099/0036.Valid Sudoku/README_EN.md | 40 +- .../0000-0099/0036.Valid Sudoku/Solution.js | 100 +- .../0000-0099/0037.Sudoku Solver/README.md | 10 +- .../0000-0099/0037.Sudoku Solver/README_EN.md | 34 +- .../0000-0099/0038.Count and Say/README.md | 10 +- .../0000-0099/0038.Count and Say/README_EN.md | 7 +- .../0000-0099/0038.Count and Say/Solution.js | 18 +- .../0000-0099/0039.Combination Sum/README.md | 10 +- .../0039.Combination Sum/README_EN.md | 26 +- .../0040.Combination Sum II/README.md | 10 +- .../0040.Combination Sum II/README_EN.md | 26 +- .../0041.First Missing Positive/README.md | 10 +- .../0041.First Missing Positive/README_EN.md | 24 +- .../0042.Trapping Rain Water/README.md | 10 +- .../0042.Trapping Rain Water/README_EN.md | 13 +- .../0000-0099/0043.Multiply Strings/README.md | 10 +- .../0043.Multiply Strings/README_EN.md | 28 +- .../0044.Wildcard Matching/README.md | 10 +- .../0044.Wildcard Matching/README_EN.md | 40 +- .../0000-0099/0045.Jump Game II/README.md | 10 +- .../0000-0099/0045.Jump Game II/README_EN.md | 20 +- .../0000-0099/0046.Permutations/README.md | 10 +- .../0000-0099/0046.Permutations/README_EN.md | 12 +- .../0000-0099/0047.Permutations II/README.md | 10 +- .../0047.Permutations II/README_EN.md | 12 +- .../0000-0099/0048.Rotate Image/README.md | 10 +- .../0000-0099/0048.Rotate Image/README_EN.md | 22 +- .../0000-0099/0048.Rotate Image/Solution.js | 24 +- .../0000-0099/0049.Group Anagrams/README.md | 10 +- .../0049.Group Anagrams/README_EN.md | 20 +- solution/0000-0099/0050.Pow(x, n)/README.md | 12 +- .../0000-0099/0050.Pow(x, n)/README_EN.md | 30 +- solution/0000-0099/0050.Pow(x, n)/Solution.js | 18 +- solution/0000-0099/0051.N-Queens/README.md | 12 +- solution/0000-0099/0051.N-Queens/README_EN.md | 15 +- solution/0000-0099/0052.N-Queens II/README.md | 12 +- .../0000-0099/0052.N-Queens II/README_EN.md | 14 +- .../0000-0099/0053.Maximum Subarray/README.md | 10 +- .../0053.Maximum Subarray/README_EN.md | 16 +- .../0053.Maximum Subarray/Solution.js | 15 +- .../0000-0099/0054.Spiral Matrix/README.md | 10 +- .../0000-0099/0054.Spiral Matrix/README_EN.md | 12 +- solution/0000-0099/0055.Jump Game/README.md | 10 +- .../0000-0099/0055.Jump Game/README_EN.md | 20 +- .../0000-0099/0056.Merge Intervals/README.md | 10 +- .../0056.Merge Intervals/README_EN.md | 18 +- .../0000-0099/0057.Insert Interval/README.md | 10 +- .../0057.Insert Interval/README_EN.md | 20 +- .../0058.Length of Last Word/README.md | 10 +- .../0058.Length of Last Word/README_EN.md | 7 +- .../0058.Length of Last Word/Solution.js | 18 +- .../0000-0099/0059.Spiral Matrix II/README.md | 10 +- .../0059.Spiral Matrix II/README_EN.md | 12 +- .../0060.Permutation Sequence/README.md | 12 +- .../0060.Permutation Sequence/README_EN.md | 42 +- solution/0000-0099/0061.Rotate List/README.md | 10 +- .../0000-0099/0061.Rotate List/README_EN.md | 16 +- .../0000-0099/0062.Unique Paths/README.md | 10 +- .../0000-0099/0062.Unique Paths/README_EN.md | 7 +- .../0000-0099/0063.Unique Paths II/README.md | 15 +- .../0063.Unique Paths II/README_EN.md | 207 +- .../0000-0099/0064.Minimum Path Sum/README.md | 10 +- .../0064.Minimum Path Sum/README_EN.md | 14 +- .../0000-0099/0065.Valid Number/README.md | 10 +- .../0000-0099/0065.Valid Number/README_EN.md | 28 +- solution/0000-0099/0066.Plus One/README.md | 10 +- solution/0000-0099/0066.Plus One/README_EN.md | 18 +- solution/0000-0099/0066.Plus One/Solution.js | 10 +- solution/0000-0099/0067.Add Binary/README.md | 10 +- .../0000-0099/0067.Add Binary/README_EN.md | 18 +- .../0068.Text Justification/README.md | 10 +- .../0068.Text Justification/README_EN.md | 36 +- solution/0000-0099/0069.Sqrt(x)/README.md | 12 +- solution/0000-0099/0069.Sqrt(x)/README_EN.md | 22 +- solution/0000-0099/0069.Sqrt(x)/Solution.js | 26 +- .../0000-0099/0070.Climbing Stairs/README.md | 10 +- .../0070.Climbing Stairs/README_EN.md | 20 +- .../0070.Climbing Stairs/Solution.js | 8 +- .../0000-0099/0071.Simplify Path/README.md | 10 +- .../0000-0099/0071.Simplify Path/README_EN.md | 38 +- .../0000-0099/0072.Edit Distance/README.md | 10 +- .../0000-0099/0072.Edit Distance/README_EN.md | 26 +- .../0073.Set Matrix Zeroes/README.md | 10 +- .../0073.Set Matrix Zeroes/README_EN.md | 26 +- .../0074.Search a 2D Matrix/README.md | 10 +- .../0074.Search a 2D Matrix/README_EN.md | 22 +- solution/0000-0099/0075.Sort Colors/README.md | 10 +- .../0000-0099/0075.Sort Colors/README_EN.md | 26 +- .../0076.Minimum Window Substring/README.md | 10 +- .../README_EN.md | 20 +- .../0000-0099/0077.Combinations/README.md | 10 +- .../0000-0099/0077.Combinations/README_EN.md | 12 +- solution/0000-0099/0078.Subsets/README.md | 10 +- solution/0000-0099/0078.Subsets/README_EN.md | 14 +- solution/0000-0099/0079.Word Search/README.md | 10 +- .../0000-0099/0079.Word Search/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../Solution.js | 19 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0085.Maximal Rectangle/README.md | 10 +- .../0085.Maximal Rectangle/README_EN.md | 12 +- .../0000-0099/0086.Partition List/README.md | 10 +- .../0086.Partition List/README_EN.md | 14 +- .../0000-0099/0087.Scramble String/README.md | 10 +- .../0087.Scramble String/README_EN.md | 36 +- .../0088.Merge Sorted Array/README.md | 10 +- .../0088.Merge Sorted Array/README_EN.md | 18 +- .../0088.Merge Sorted Array/Solution.js | 31 +- solution/0000-0099/0089.Gray Code/README.md | 10 +- .../0000-0099/0089.Gray Code/README_EN.md | 18 +- solution/0000-0099/0090.Subsets II/README.md | 10 +- .../0000-0099/0090.Subsets II/README_EN.md | 14 +- solution/0000-0099/0091.Decode Ways/README.md | 10 +- .../0000-0099/0091.Decode Ways/README_EN.md | 20 +- .../0092.Reverse Linked List II/README.md | 10 +- .../0092.Reverse Linked List II/README_EN.md | 14 +- .../0093.Restore IP Addresses/README.md | 12 +- .../0093.Restore IP Addresses/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0096.Unique Binary Search Trees/README.md | 10 +- .../README_EN.md | 12 +- .../0097.Interleaving String/README.md | 10 +- .../0097.Interleaving String/README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../Solution.js | 24 +- .../0099.Recover Binary Search Tree/README.md | 10 +- .../README_EN.md | 26 +- solution/0100-0199/0100.Same Tree/README.md | 10 +- .../0100-0199/0100.Same Tree/README_EN.md | 22 +- .../0100-0199/0101.Symmetric Tree/README.md | 10 +- .../0101.Symmetric Tree/README_EN.md | 22 +- .../0100-0199/0101.Symmetric Tree/Solution.js | 21 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../Solution.js | 36 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../Solution.js | 27 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../Solution.js | 20 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0110.Balanced Binary Tree/README.md | 10 +- .../0110.Balanced Binary Tree/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 20 +- solution/0100-0199/0112.Path Sum/README.md | 10 +- solution/0100-0199/0112.Path Sum/README_EN.md | 18 +- solution/0100-0199/0113.Path Sum II/README.md | 10 +- .../0100-0199/0113.Path Sum II/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../0115.Distinct Subsequences/README.md | 10 +- .../0115.Distinct Subsequences/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0118.Pascal's Triangle/README.md | 10 +- .../0118.Pascal's Triangle/README_EN.md | 14 +- .../0118.Pascal's Triangle/Solution.js | 29 +- .../0119.Pascal's Triangle II/README.md | 10 +- .../0119.Pascal's Triangle II/README_EN.md | 20 +- solution/0100-0199/0120.Triangle/README.md | 10 +- solution/0100-0199/0120.Triangle/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../Solution.js | 10 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../Solution.js | 10 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0100-0199/0125.Valid Palindrome/README.md | 10 +- .../0125.Valid Palindrome/README_EN.md | 18 +- .../0125.Valid Palindrome/Solution.js | 48 +- .../0100-0199/0126.Word Ladder II/README.md | 10 +- .../0126.Word Ladder II/README_EN.md | 38 +- solution/0100-0199/0127.Word Ladder/README.md | 10 +- .../0100-0199/0127.Word Ladder/README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0129.Sum Root to Leaf Numbers/README.md | 10 +- .../README_EN.md | 22 +- .../0130.Surrounded Regions/README.md | 10 +- .../0130.Surrounded Regions/README_EN.md | 22 +- .../0131.Palindrome Partitioning/README.md | 10 +- .../0131.Palindrome Partitioning/README_EN.md | 14 +- .../0132.Palindrome Partitioning II/README.md | 10 +- .../README_EN.md | 14 +- solution/0100-0199/0133.Clone Graph/README.md | 10 +- .../0100-0199/0133.Clone Graph/README_EN.md | 7 +- solution/0100-0199/0134.Gas Station/README.md | 10 +- .../0100-0199/0134.Gas Station/README_EN.md | 30 +- solution/0100-0199/0135.Candy/README.md | 10 +- solution/0100-0199/0135.Candy/README_EN.md | 26 +- .../0100-0199/0136.Single Number/README.md | 9 +- .../0100-0199/0136.Single Number/README_EN.md | 20 +- .../0100-0199/0136.Single Number/Solution.js | 20 +- .../0100-0199/0137.Single Number II/README.md | 9 +- .../0137.Single Number II/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/0100-0199/0139.Word Break/README.md | 10 +- .../0100-0199/0139.Word Break/README_EN.md | 28 +- .../0100-0199/0140.Word Break II/README.md | 10 +- .../0100-0199/0140.Word Break II/README_EN.md | 28 +- .../0141.Linked List Cycle/README.md | 11 +- .../0141.Linked List Cycle/README_EN.md | 34 +- .../0141.Linked List Cycle/Solution.js | 21 +- .../0142.Linked List Cycle II/README.md | 11 +- .../0142.Linked List Cycle II/README_EN.md | 7 +- .../0100-0199/0143.Reorder List/README.md | 10 +- .../0100-0199/0143.Reorder List/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 14 +- solution/0100-0199/0146.Lru Cache/README.md | 12 +- .../0100-0199/0146.Lru Cache/README_EN.md | 20 +- .../0147.Insertion Sort List/README.md | 10 +- .../0147.Insertion Sort List/README_EN.md | 32 +- solution/0100-0199/0148.Sort List/README.md | 10 +- .../0100-0199/0148.Sort List/README_EN.md | 16 +- .../0149.Max Points on a Line/README.md | 10 +- .../0149.Max Points on a Line/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../0151.Reverse Words in a String/README.md | 10 +- .../README_EN.md | 38 +- .../0152.Maximum Product Subarray/README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 30 +- solution/0100-0199/0155.Min Stack/README.md | 10 +- .../0100-0199/0155.Min Stack/README_EN.md | 26 +- solution/0100-0199/0155.Min Stack/Solution.js | 58 +- .../0156.Binary Tree Upside Down/README.md | 10 +- .../0156.Binary Tree Upside Down/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../Solution.js | 51 +- .../0161.One Edit Distance/README.md | 10 +- .../0161.One Edit Distance/README_EN.md | 7 +- .../0162.Find Peak Element/README.md | 10 +- .../0162.Find Peak Element/README_EN.md | 26 +- .../0100-0199/0163.Missing Ranges/README.md | 10 +- .../0163.Missing Ranges/README_EN.md | 7 +- solution/0100-0199/0164.Maximum Gap/README.md | 10 +- .../0100-0199/0164.Maximum Gap/README_EN.md | 26 +- .../0165.Compare Version Numbers/README.md | 10 +- .../0165.Compare Version Numbers/README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../0168.Excel Sheet Column Title/README.md | 12 +- .../README_EN.md | 22 +- .../0100-0199/0169.Majority Element/README.md | 10 +- .../0169.Majority Element/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0171.Excel Sheet Column Number/README.md | 12 +- .../README_EN.md | 22 +- .../0172.Factorial Trailing Zeroes/README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../0100-0199/0174.Dungeon Game/README.md | 69 +- .../0100-0199/0174.Dungeon Game/README_EN.md | 66 +- .../0175.Combine Two Tables/README.md | 7 +- .../0175.Combine Two Tables/README_EN.md | 18 +- .../0176.Second Highest Salary/README.md | 7 +- .../0176.Second Highest Salary/README_EN.md | 13 +- .../0177.Nth Highest Salary/README.md | 7 +- .../0177.Nth Highest Salary/README_EN.md | 11 +- solution/0100-0199/0178.Rank Scores/README.md | 5 +- .../0100-0199/0178.Rank Scores/README_EN.md | 11 +- .../0100-0199/0179.Largest Number/README.md | 10 +- .../0179.Largest Number/README_EN.md | 18 +- .../0180.Consecutive Numbers/README.md | 7 +- .../0180.Consecutive Numbers/README_EN.md | 11 +- .../README.md | 5 +- .../README_EN.md | 11 +- .../0100-0199/0182.Duplicate Emails/README.md | 5 +- .../0182.Duplicate Emails/README_EN.md | 13 +- .../0183.Customers Who Never Order/README.md | 7 +- .../README_EN.md | 19 +- .../0184.Department Highest Salary/README.md | 5 +- .../README_EN.md | 19 +- .../README.md | 5 +- .../README_EN.md | 19 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0187.Repeated DNA Sequences/README.md | 12 +- .../0187.Repeated DNA Sequences/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0100-0199/0189.Rotate Array/README.md | 9 +- .../0100-0199/0189.Rotate Array/README_EN.md | 18 +- .../0100-0199/0190.Reverse Bits/README.md | 10 +- .../0100-0199/0190.Reverse Bits/README_EN.md | 7 +- .../0100-0199/0190.Reverse Bits/Solution.js | 9 +- .../0100-0199/0191.Number of 1 Bits/README.md | 12 +- .../0191.Number of 1 Bits/README_EN.md | 38 +- .../0191.Number of 1 Bits/Solution.js | 6 +- .../0100-0199/0192.Word Frequency/README.md | 10 +- .../0192.Word Frequency/README_EN.md | 36 +- .../0193.Valid Phone Numbers/README.md | 10 +- .../0193.Valid Phone Numbers/README_EN.md | 22 +- .../0100-0199/0194.Transpose File/README.md | 10 +- .../0194.Transpose File/README_EN.md | 22 +- solution/0100-0199/0195.Tenth Line/README.md | 10 +- .../0100-0199/0195.Tenth Line/README_EN.md | 20 +- .../0196.Delete Duplicate Emails/README.md | 5 +- .../0196.Delete Duplicate Emails/README_EN.md | 15 +- .../0197.Rising Temperature/README.md | 7 +- .../0197.Rising Temperature/README_EN.md | 13 +- .../0100-0199/0198.House Robber/README.md | 10 +- .../0100-0199/0198.House Robber/README_EN.md | 18 +- .../README.md | 8 +- .../README_EN.md | 8 +- .../0200.Number of Islands/README.md | 10 +- .../0200.Number of Islands/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0200-0299/0202.Happy Number/README.md | 10 +- .../0200-0299/0202.Happy Number/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0200-0299/0204.Count Primes/README.md | 10 +- .../0200-0299/0204.Count Primes/README_EN.md | 12 +- .../0200-0299/0204.Count Primes/Solution.js | 16 +- .../0205.Isomorphic Strings/README.md | 10 +- .../0205.Isomorphic Strings/README_EN.md | 26 +- .../0206.Reverse Linked List/README.md | 31 +- .../0206.Reverse Linked List/README_EN.md | 40 +- .../0206.Reverse Linked List/Solution.js | 20 +- .../0200-0299/0207.Course Schedule/README.md | 10 +- .../0207.Course Schedule/README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 22 +- .../0209.Minimum Size Subarray Sum/README.md | 10 +- .../README_EN.md | 16 +- .../0210.Course Schedule II/README.md | 10 +- .../0210.Course Schedule II/README_EN.md | 30 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../0200-0299/0212.Word Search II/README.md | 10 +- .../0212.Word Search II/README_EN.md | 26 +- .../0200-0299/0213.House Robber II/README.md | 10 +- .../0213.House Robber II/README_EN.md | 18 +- .../0214.Shortest Palindrome/README.md | 10 +- .../0214.Shortest Palindrome/README_EN.md | 14 +- .../README.md | 12 +- .../README_EN.md | 18 +- .../0216.Combination Sum III/README.md | 10 +- .../0216.Combination Sum III/README_EN.md | 22 +- .../0217.Contains Duplicate/README.md | 10 +- .../0217.Contains Duplicate/README_EN.md | 22 +- .../0217.Contains Duplicate/Solution.js | 20 +- .../0218.The Skyline Problem/README.md | 10 +- .../0218.The Skyline Problem/README_EN.md | 21 +- .../0219.Contains Duplicate II/README.md | 10 +- .../0219.Contains Duplicate II/README_EN.md | 20 +- .../0220.Contains Duplicate III/README.md | 10 +- .../0220.Contains Duplicate III/README_EN.md | 18 +- .../0200-0299/0221.Maximal Square/README.md | 10 +- .../0221.Maximal Square/README_EN.md | 10 +- .../0222.Count Complete Tree Nodes/README.md | 10 +- .../README_EN.md | 16 +- .../0200-0299/0223.Rectangle Area/README.md | 10 +- .../0223.Rectangle Area/README_EN.md | 20 +- .../0200-0299/0224.Basic Calculator/README.md | 10 +- .../0224.Basic Calculator/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0226.Invert Binary Tree/README.md | 10 +- .../0226.Invert Binary Tree/README_EN.md | 22 +- .../0227.Basic Calculator II/README.md | 10 +- .../0227.Basic Calculator II/README_EN.md | 30 +- .../0200-0299/0228.Summary Ranges/README.md | 10 +- .../0228.Summary Ranges/README_EN.md | 16 +- .../0229.Majority Element II/README.md | 10 +- .../0229.Majority Element II/README_EN.md | 18 +- .../README.md | 12 +- .../README_EN.md | 20 +- .../0200-0299/0231.Power of Two/README.md | 12 +- .../0200-0299/0231.Power of Two/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0233.Number of Digit One/README.md | 10 +- .../0233.Number of Digit One/README_EN.md | 12 +- .../0234.Palindrome Linked List/README.md | 14 +- .../0234.Palindrome Linked List/README_EN.md | 20 +- .../0234.Palindrome Linked List/Solution.js | 46 +- .../README.md | 7 +- .../README_EN.md | 24 +- .../README.md | 11 +- .../README_EN.md | 26 +- .../README.md | 15 +- .../README_EN.md | 30 +- .../Solution.js | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0239.Sliding Window Maximum/README.md | 10 +- .../0239.Sliding Window Maximum/README_EN.md | 14 +- .../0240.Search a 2D Matrix II/README.md | 10 +- .../0240.Search a 2D Matrix II/README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0200-0299/0242.Valid Anagram/README.md | 10 +- .../0200-0299/0242.Valid Anagram/README_EN.md | 20 +- .../0200-0299/0242.Valid Anagram/Solution.js | 25 +- .../0243.Shortest Word Distance/README.md | 10 +- .../0243.Shortest Word Distance/README_EN.md | 7 +- .../0244.Shortest Word Distance II/README.md | 10 +- .../README_EN.md | 7 +- .../0245.Shortest Word Distance III/README.md | 10 +- .../README_EN.md | 7 +- .../0246.Strobogrammatic Number/README.md | 10 +- .../0246.Strobogrammatic Number/README_EN.md | 6 +- .../0247.Strobogrammatic Number II/README.md | 7 +- .../README_EN.md | 4 +- .../0248.Strobogrammatic Number III/README.md | 10 +- .../README_EN.md | 7 +- .../0249.Group Shifted Strings/README.md | 10 +- .../0249.Group Shifted Strings/README_EN.md | 7 +- .../0250.Count Univalue Subtrees/README.md | 10 +- .../0250.Count Univalue Subtrees/README_EN.md | 7 +- .../0251.Flatten 2D Vector/README.md | 10 +- .../0251.Flatten 2D Vector/README_EN.md | 7 +- .../0200-0299/0252.Meeting Rooms/README.md | 10 +- .../0200-0299/0252.Meeting Rooms/README_EN.md | 7 +- .../0200-0299/0253.Meeting Rooms II/README.md | 10 +- .../0253.Meeting Rooms II/README_EN.md | 7 +- .../0254.Factor Combinations/README.md | 10 +- .../0254.Factor Combinations/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/0200-0299/0256.Paint House/README.md | 10 +- .../0200-0299/0256.Paint House/README_EN.md | 7 +- .../0257.Binary Tree Paths/README.md | 10 +- .../0257.Binary Tree Paths/README_EN.md | 12 +- solution/0200-0299/0258.Add Digits/README.md | 10 +- .../0200-0299/0258.Add Digits/README_EN.md | 12 +- .../0200-0299/0259.3Sum Smaller/README.md | 10 +- .../0200-0299/0259.3Sum Smaller/README_EN.md | 7 +- .../0260.Single Number III/README.md | 10 +- .../0260.Single Number III/README_EN.md | 18 +- .../0200-0299/0261.Graph Valid Tree/README.md | 10 +- .../0261.Graph Valid Tree/README_EN.md | 7 +- .../0200-0299/0262.Trips and Users/README.md | 7 +- .../0262.Trips and Users/README_EN.md | 6 +- solution/0200-0299/0263.Ugly Number/README.md | 10 +- .../0200-0299/0263.Ugly Number/README_EN.md | 28 +- .../0200-0299/0264.Ugly Number II/README.md | 10 +- .../0264.Ugly Number II/README_EN.md | 20 +- .../0200-0299/0265.Paint House II/README.md | 10 +- .../0265.Paint House II/README_EN.md | 7 +- .../0266.Palindrome Permutation/README.md | 10 +- .../0266.Palindrome Permutation/README_EN.md | 7 +- .../0267.Palindrome Permutation II/README.md | 10 +- .../README_EN.md | 7 +- .../0200-0299/0268.Missing Number/README.md | 10 +- .../0268.Missing Number/README_EN.md | 16 +- .../0200-0299/0268.Missing Number/Solution.js | 9 +- .../0200-0299/0269.Alien Dictionary/README.md | 10 +- .../0269.Alien Dictionary/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0271.Encode and Decode Strings/README.md | 10 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0273.Integer to English Words/README.md | 10 +- .../README_EN.md | 24 +- solution/0200-0299/0274.H-Index/README.md | 12 +- solution/0200-0299/0274.H-Index/README_EN.md | 16 +- solution/0200-0299/0275.H-Index II/README.md | 12 +- .../0200-0299/0275.H-Index II/README_EN.md | 26 +- solution/0200-0299/0276.Paint Fence/README.md | 10 +- .../0200-0299/0276.Paint Fence/README_EN.md | 7 +- .../0277.Find the Celebrity/README.md | 10 +- .../0277.Find the Celebrity/README_EN.md | 7 +- .../0278.First Bad Version/README.md | 10 +- .../0278.First Bad Version/README_EN.md | 16 +- .../0278.First Bad Version/Solution.js | 31 +- .../0200-0299/0279.Perfect Squares/README.md | 10 +- .../0279.Perfect Squares/README_EN.md | 14 +- solution/0200-0299/0280.Wiggle Sort/README.md | 10 +- .../0200-0299/0280.Wiggle Sort/README_EN.md | 7 +- .../0200-0299/0281.Zigzag Iterator/README.md | 10 +- .../0281.Zigzag Iterator/README_EN.md | 7 +- .../0282.Expression Add Operators/README.md | 10 +- .../README_EN.md | 28 +- solution/0200-0299/0283.Move Zeroes/README.md | 10 +- .../0200-0299/0283.Move Zeroes/README_EN.md | 18 +- .../0200-0299/0283.Move Zeroes/Solution.js | 12 +- .../0200-0299/0284.Peeking Iterator/README.md | 10 +- .../0284.Peeking Iterator/README_EN.md | 14 +- .../0285.Inorder Successor in BST/README.md | 10 +- .../README_EN.md | 7 +- .../0200-0299/0286.Walls and Gates/README.md | 10 +- .../0286.Walls and Gates/README_EN.md | 7 +- .../0287.Find the Duplicate Number/README.md | 10 +- .../README_EN.md | 28 +- .../0288.Unique Word Abbreviation/README.md | 10 +- .../README_EN.md | 7 +- .../0200-0299/0289.Game of Life/README.md | 10 +- .../0200-0299/0289.Game of Life/README_EN.md | 34 +- .../0200-0299/0290.Word Pattern/README.md | 10 +- .../0200-0299/0290.Word Pattern/README_EN.md | 28 +- .../0200-0299/0291.Word Pattern II/README.md | 10 +- .../0291.Word Pattern II/README_EN.md | 7 +- solution/0200-0299/0292.Nim Game/README.md | 10 +- solution/0200-0299/0292.Nim Game/README_EN.md | 12 +- solution/0200-0299/0293.Flip Game/README.md | 10 +- .../0200-0299/0293.Flip Game/README_EN.md | 7 +- .../0200-0299/0294.Flip Game II/README.md | 10 +- .../0200-0299/0294.Flip Game II/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../0296.Best Meeting Point/README.md | 10 +- .../0296.Best Meeting Point/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../0200-0299/0299.Bulls and Cows/README.md | 10 +- .../0299.Bulls and Cows/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../0301.Remove Invalid Parentheses/README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../README.md | 11 +- .../README_EN.md | 12 +- .../0305.Number of Islands II/README.md | 10 +- .../0305.Number of Islands II/README_EN.md | 7 +- .../0300-0399/0306.Additive Number/README.md | 10 +- .../0306.Additive Number/README_EN.md | 7 +- .../0307.Range Sum Query - Mutable/README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 11 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0310.Minimum Height Trees/README.md | 10 +- .../0310.Minimum Height Trees/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0300-0399/0312.Burst Balloons/README.md | 10 +- .../0312.Burst Balloons/README_EN.md | 20 +- .../0313.Super Ugly Number/README.md | 10 +- .../0313.Super Ugly Number/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0316.Remove Duplicate Letters/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0300-0399/0319.Bulb Switcher/README.md | 10 +- .../0300-0399/0319.Bulb Switcher/README_EN.md | 12 +- .../0320.Generalized Abbreviation/README.md | 10 +- .../README_EN.md | 7 +- .../0321.Create Maximum Number/README.md | 10 +- .../0321.Create Maximum Number/README_EN.md | 20 +- solution/0300-0399/0322.Coin Change/README.md | 29 +- .../0300-0399/0322.Coin Change/README_EN.md | 19 +- .../0300-0399/0322.Coin Change/Solution.js | 18 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0300-0399/0324.Wiggle Sort II/README.md | 10 +- .../0324.Wiggle Sort II/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0300-0399/0326.Power of Three/README.md | 12 +- .../0326.Power of Three/README_EN.md | 24 +- .../0300-0399/0326.Power of Three/Solution.js | 18 +- .../0327.Count of Range Sum/README.md | 10 +- .../0327.Count of Range Sum/README_EN.md | 12 +- .../0328.Odd Even Linked List/README.md | 10 +- .../0328.Odd Even Linked List/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0300-0399/0330.Patching Array/README.md | 10 +- .../0330.Patching Array/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0332.Reconstruct Itinerary/README.md | 10 +- .../0332.Reconstruct Itinerary/README_EN.md | 26 +- .../0333.Largest BST Subtree/README.md | 10 +- .../0333.Largest BST Subtree/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0300-0399/0335.Self Crossing/README.md | 10 +- .../0300-0399/0335.Self Crossing/README_EN.md | 24 +- .../0300-0399/0336.Palindrome Pairs/README.md | 10 +- .../0336.Palindrome Pairs/README_EN.md | 16 +- .../0300-0399/0337.House Robber III/README.md | 10 +- .../0337.House Robber III/README_EN.md | 16 +- .../0300-0399/0338.Counting Bits/README.md | 10 +- .../0300-0399/0338.Counting Bits/README_EN.md | 24 +- .../0339.Nested List Weight Sum/README.md | 10 +- .../0339.Nested List Weight Sum/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0300-0399/0342.Power of Four/README.md | 12 +- .../0300-0399/0342.Power of Four/README_EN.md | 16 +- .../0300-0399/0342.Power of Four/Solution.js | 2 +- .../0300-0399/0343.Integer Break/README.md | 10 +- .../0300-0399/0343.Integer Break/README_EN.md | 16 +- .../0300-0399/0344.Reverse String/README.md | 10 +- .../0344.Reverse String/README_EN.md | 22 +- .../0300-0399/0344.Reverse String/Solution.js | 6 +- .../0345.Reverse Vowels of a String/README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0347.Top K Frequent Elements/README.md | 10 +- .../0347.Top K Frequent Elements/README_EN.md | 24 +- .../0348.Design Tic-Tac-Toe/README.md | 10 +- .../0348.Design Tic-Tac-Toe/README_EN.md | 21 +- .../0349.Intersection of Two Arrays/README.md | 10 +- .../README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../Solution.js | 10 +- .../0351.Android Unlock Patterns/README.md | 10 +- .../0351.Android Unlock Patterns/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0353.Design Snake Game/README.md | 10 +- .../0353.Design Snake Game/README_EN.md | 7 +- .../0354.Russian Doll Envelopes/README.md | 10 +- .../0354.Russian Doll Envelopes/README_EN.md | 16 +- .../0300-0399/0355.Design Twitter/README.md | 10 +- .../0355.Design Twitter/README_EN.md | 10 +- .../0300-0399/0356.Line Reflection/README.md | 10 +- .../0356.Line Reflection/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../0359.Logger Rate Limiter/README.md | 10 +- .../0359.Logger Rate Limiter/README_EN.md | 6 +- .../0360.Sort Transformed Array/README.md | 10 +- .../0360.Sort Transformed Array/README_EN.md | 6 +- solution/0300-0399/0361.Bomb Enemy/README.md | 10 +- .../0300-0399/0361.Bomb Enemy/README_EN.md | 11 +- .../0362.Design Hit Counter/README.md | 10 +- .../0362.Design Hit Counter/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0364.Nested List Weight Sum II/README.md | 10 +- .../README_EN.md | 7 +- .../0365.Water and Jug Problem/README.md | 10 +- .../0365.Water and Jug Problem/README_EN.md | 26 +- .../0366.Find Leaves of Binary Tree/README.md | 10 +- .../README_EN.md | 7 +- .../0367.Valid Perfect Square/README.md | 10 +- .../0367.Valid Perfect Square/README_EN.md | 16 +- .../0368.Largest Divisible Subset/README.md | 10 +- .../README_EN.md | 18 +- .../0369.Plus One Linked List/README.md | 10 +- .../0369.Plus One Linked List/README_EN.md | 7 +- .../0300-0399/0370.Range Addition/README.md | 10 +- .../0370.Range Addition/README_EN.md | 6 +- .../0371.Sum of Two Integers/README.md | 10 +- .../0371.Sum of Two Integers/README_EN.md | 16 +- solution/0300-0399/0372.Super Pow/README.md | 10 +- .../0300-0399/0372.Super Pow/README_EN.md | 14 +- .../README.md | 12 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0376.Wiggle Subsequence/README.md | 10 +- .../0376.Wiggle Subsequence/README_EN.md | 26 +- .../0377.Combination Sum IV/README.md | 10 +- .../0377.Combination Sum IV/README_EN.md | 18 +- .../README.md | 12 +- .../README_EN.md | 12 +- .../0379.Design Phone Directory/README.md | 10 +- .../0379.Design Phone Directory/README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 12 +- .../README.md | 12 +- .../README_EN.md | 10 +- .../0382.Linked List Random Node/README.md | 10 +- .../0382.Linked List Random Node/README_EN.md | 10 +- solution/0300-0399/0383.Ransom Note/README.md | 10 +- .../0300-0399/0383.Ransom Note/README_EN.md | 16 +- .../0300-0399/0384.Shuffle an Array/README.md | 10 +- .../0384.Shuffle an Array/README_EN.md | 8 +- .../0384.Shuffle an Array/Solution.js | 32 +- solution/0300-0399/0385.Mini Parser/README.md | 10 +- .../0300-0399/0385.Mini Parser/README_EN.md | 14 +- .../0386.Lexicographical Numbers/README.md | 10 +- .../0386.Lexicographical Numbers/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../Solution.js | 39 +- .../0388.Longest Absolute File Path/README.md | 10 +- .../README_EN.md | 28 +- .../0389.Find the Difference/README.md | 10 +- .../0389.Find the Difference/README_EN.md | 12 +- .../0300-0399/0390.Elimination Game/README.md | 10 +- .../0390.Elimination Game/README_EN.md | 14 +- .../0391.Perfect Rectangle/README.md | 10 +- .../0391.Perfect Rectangle/README_EN.md | 35 +- .../0300-0399/0392.Is Subsequence/README.md | 10 +- .../0392.Is Subsequence/README_EN.md | 18 +- .../0300-0399/0393.UTF-8 Validation/README.md | 10 +- .../0393.UTF-8 Validation/README_EN.md | 12 +- .../0300-0399/0394.Decode String/README.md | 10 +- .../0300-0399/0394.Decode String/README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 10 +- .../0300-0399/0396.Rotate Function/README.md | 10 +- .../0396.Rotate Function/README_EN.md | 20 +- .../0397.Integer Replacement/README.md | 10 +- .../0397.Integer Replacement/README_EN.md | 16 +- .../0398.Random Pick Index/README.md | 10 +- .../0398.Random Pick Index/README_EN.md | 14 +- .../0399.Evaluate Division/README.md | 10 +- .../0399.Evaluate Division/README_EN.md | 20 +- solution/0400-0499/0400.Nth Digit/README.md | 12 +- .../0400-0499/0400.Nth Digit/README_EN.md | 12 +- .../0400-0499/0401.Binary Watch/README.md | 10 +- .../0400-0499/0401.Binary Watch/README_EN.md | 12 +- .../0400-0499/0402.Remove K Digits/README.md | 12 +- .../0402.Remove K Digits/README_EN.md | 14 +- solution/0400-0499/0403.Frog Jump/README.md | 10 +- .../0400-0499/0403.Frog Jump/README_EN.md | 16 +- .../0404.Sum of Left Leaves/README.md | 10 +- .../0404.Sum of Left Leaves/README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../0407.Trapping Rain Water II/README.md | 10 +- .../0407.Trapping Rain Water II/README_EN.md | 7 +- .../0408.Valid Word Abbreviation/README.md | 10 +- .../0408.Valid Word Abbreviation/README_EN.md | 8 +- .../0409.Longest Palindrome/README.md | 10 +- .../0409.Longest Palindrome/README_EN.md | 12 +- .../0410.Split Array Largest Sum/README.md | 10 +- .../0410.Split Array Largest Sum/README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/0400-0499/0412.Fizz Buzz/README.md | 10 +- .../0400-0499/0412.Fizz Buzz/README_EN.md | 10 +- solution/0400-0499/0412.Fizz Buzz/Solution.js | 12 +- .../0413.Arithmetic Slices/README.md | 10 +- .../0413.Arithmetic Slices/README_EN.md | 20 +- .../0414.Third Maximum Number/README.md | 10 +- .../0414.Third Maximum Number/README_EN.md | 12 +- solution/0400-0499/0415.Add Strings/README.md | 10 +- .../0400-0499/0415.Add Strings/README_EN.md | 8 +- .../0416.Partition Equal Subset Sum/README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0418.Sentence Screen Fitting/README.md | 10 +- .../0418.Sentence Screen Fitting/README_EN.md | 17 +- .../0419.Battleships in a Board/README.md | 10 +- .../0419.Battleships in a Board/README_EN.md | 12 +- .../0420.Strong Password Checker/README.md | 10 +- .../0420.Strong Password Checker/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0422.Valid Word Square/README.md | 10 +- .../0422.Valid Word Square/README_EN.md | 9 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../0400-0499/0425.Word Squares/README.md | 10 +- .../0400-0499/0425.Word Squares/README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0427.Construct Quad Tree/README.md | 10 +- .../0427.Construct Quad Tree/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 27 +- .../README_EN.md | 7 +- .../README.md | 9 +- .../README_EN.md | 9 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0432.All O`one Data Structure/README.md | 10 +- .../README_EN.md | 10 +- .../0433.Minimum Genetic Mutation/README.md | 10 +- .../README_EN.md | 46 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0435.Non-overlapping Intervals/README.md | 10 +- .../README_EN.md | 7 +- .../0436.Find Right Interval/README.md | 10 +- .../0436.Find Right Interval/README_EN.md | 38 +- .../0400-0499/0437.Path Sum III/README.md | 10 +- .../0400-0499/0437.Path Sum III/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0439.Ternary Expression Parser/README.md | 10 +- .../README_EN.md | 9 +- .../README.md | 12 +- .../README_EN.md | 12 +- .../0400-0499/0441.Arranging Coins/README.md | 10 +- .../0441.Arranging Coins/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0443.String Compression/README.md | 10 +- .../0443.String Compression/README_EN.md | 42 +- .../0444.Sequence Reconstruction/README.md | 10 +- .../0444.Sequence Reconstruction/README_EN.md | 7 +- .../0445.Add Two Numbers II/README.md | 10 +- .../0445.Add Two Numbers II/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0447.Number of Boomerangs/README.md | 10 +- .../0447.Number of Boomerangs/README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0450.Delete Node in a BST/README.md | 10 +- .../0450.Delete Node in a BST/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 8 +- solution/0400-0499/0454.4Sum II/README.md | 10 +- solution/0400-0499/0454.4Sum II/README_EN.md | 16 +- .../0400-0499/0455.Assign Cookies/README.md | 10 +- .../0455.Assign Cookies/README_EN.md | 12 +- solution/0400-0499/0456.132 Pattern/README.md | 12 +- .../0400-0499/0456.132 Pattern/README_EN.md | 14 +- .../0457.Circular Array Loop/README.md | 10 +- .../0457.Circular Array Loop/README_EN.md | 40 +- solution/0400-0499/0458.Poor Pigs/README.md | 10 +- .../0400-0499/0458.Poor Pigs/README_EN.md | 26 +- .../0459.Repeated Substring Pattern/README.md | 10 +- .../README_EN.md | 22 +- solution/0400-0499/0460.LFU Cache/README.md | 12 +- .../0400-0499/0460.LFU Cache/README_EN.md | 7 +- .../0400-0499/0461.Hamming Distance/README.md | 10 +- .../0461.Hamming Distance/README_EN.md | 12 +- .../0461.Hamming Distance/Solution.js | 8 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0400-0499/0463.Island Perimeter/README.md | 9 +- .../0463.Island Perimeter/README_EN.md | 16 +- solution/0400-0499/0464.Can I Win/README.md | 10 +- .../0400-0499/0464.Can I Win/README_EN.md | 16 +- .../0465.Optimal Account Balancing/README.md | 10 +- .../README_EN.md | 12 +- .../0466.Count The Repetitions/README.md | 10 +- .../0466.Count The Repetitions/README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../0468.Validate IP Address/README.md | 12 +- .../0468.Validate IP Address/README_EN.md | 30 +- .../0400-0499/0469.Convex Polygon/README.md | 10 +- .../0469.Convex Polygon/README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0472.Concatenated Words/README.md | 10 +- .../0472.Concatenated Words/README_EN.md | 10 +- .../0473.Matchsticks to Square/README.md | 10 +- .../0473.Matchsticks to Square/README_EN.md | 14 +- .../0400-0499/0474.Ones and Zeroes/README.md | 10 +- .../0474.Ones and Zeroes/README_EN.md | 34 +- solution/0400-0499/0475.Heaters/README.md | 10 +- solution/0400-0499/0475.Heaters/README_EN.md | 38 +- .../0476.Number Complement/README.md | 10 +- .../0476.Number Complement/README_EN.md | 7 +- .../0477.Total Hamming Distance/README.md | 10 +- .../0477.Total Hamming Distance/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0479.Largest Palindrome Product/README.md | 10 +- .../README_EN.md | 26 +- .../0480.Sliding Window Median/README.md | 10 +- .../0480.Sliding Window Median/README_EN.md | 7 +- .../0400-0499/0481.Magical String/README.md | 10 +- .../0481.Magical String/README_EN.md | 26 +- .../0482.License Key Formatting/README.md | 10 +- .../0482.License Key Formatting/README_EN.md | 18 +- .../0483.Smallest Good Base/README.md | 10 +- .../0483.Smallest Good Base/README_EN.md | 38 +- .../0400-0499/0484.Find Permutation/README.md | 10 +- .../0484.Find Permutation/README_EN.md | 6 +- .../0485.Max Consecutive Ones/README.md | 12 +- .../0485.Max Consecutive Ones/README_EN.md | 10 +- .../0485.Max Consecutive Ones/Solution.js | 28 +- .../0486.Predict the Winner/README.md | 10 +- .../0486.Predict the Winner/README_EN.md | 14 +- .../0487.Max Consecutive Ones II/README.md | 12 +- .../0487.Max Consecutive Ones II/README_EN.md | 6 +- solution/0400-0499/0488.Zuma Game/README.md | 10 +- .../0400-0499/0488.Zuma Game/README_EN.md | 7 +- .../0489.Robot Room Cleaner/README.md | 10 +- .../0489.Robot Room Cleaner/README_EN.md | 7 +- solution/0400-0499/0490.The Maze/README.md | 10 +- solution/0400-0499/0490.The Maze/README_EN.md | 7 +- .../0491.Increasing Subsequences/README.md | 10 +- .../0491.Increasing Subsequences/README_EN.md | 7 +- .../0492.Construct the Rectangle/README.md | 10 +- .../0492.Construct the Rectangle/README_EN.md | 12 +- .../0400-0499/0493.Reverse Pairs/README.md | 10 +- .../0400-0499/0493.Reverse Pairs/README_EN.md | 14 +- solution/0400-0499/0494.Target Sum/README.md | 10 +- .../0400-0499/0494.Target Sum/README_EN.md | 16 +- .../0400-0499/0495.Teemo Attacking/README.md | 10 +- .../0495.Teemo Attacking/README_EN.md | 32 +- .../0496.Next Greater Element I/README.md | 10 +- .../0496.Next Greater Element I/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../0498.Diagonal Traverse/README.md | 10 +- .../0498.Diagonal Traverse/README_EN.md | 19 +- .../0400-0499/0499.The Maze III/README.md | 10 +- .../0400-0499/0499.The Maze III/README_EN.md | 7 +- .../0500-0599/0500.Keyboard Row/README.md | 22 +- .../0500-0599/0500.Keyboard Row/README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 32 +- solution/0500-0599/0502.IPO/README.md | 10 +- solution/0500-0599/0502.IPO/README_EN.md | 16 +- .../0503.Next Greater Element II/README.md | 10 +- .../0503.Next Greater Element II/README_EN.md | 10 +- solution/0500-0599/0504.Base 7/README.md | 10 +- solution/0500-0599/0504.Base 7/README_EN.md | 12 +- solution/0500-0599/0505.The Maze II/README.md | 10 +- .../0500-0599/0505.The Maze II/README_EN.md | 7 +- .../0500-0599/0506.Relative Ranks/README.md | 10 +- .../0506.Relative Ranks/README_EN.md | 12 +- .../0500-0599/0507.Perfect Number/README.md | 10 +- .../0507.Perfect Number/README_EN.md | 12 +- .../0508.Most Frequent Subtree Sum/README.md | 10 +- .../README_EN.md | 12 +- .../0500-0599/0509.Fibonacci Number/README.md | 10 +- .../0509.Fibonacci Number/README_EN.md | 32 +- .../0509.Fibonacci Number/Solution.js | 14 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0511.Game Play Analysis I/README.md | 5 +- .../0511.Game Play Analysis I/README_EN.md | 3 +- .../0512.Game Play Analysis II/README.md | 5 +- .../0512.Game Play Analysis II/README_EN.md | 3 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0500-0599/0514.Freedom Trail/README.md | 29 +- .../0500-0599/0514.Freedom Trail/README_EN.md | 25 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0517.Super Washing Machines/README.md | 10 +- .../0517.Super Washing Machines/README_EN.md | 22 +- .../0500-0599/0518.Coin Change 2/README.md | 10 +- .../0500-0599/0518.Coin Change 2/README_EN.md | 40 +- .../0519.Random Flip Matrix/README.md | 10 +- .../0519.Random Flip Matrix/README_EN.md | 32 +- .../0500-0599/0520.Detect Capital/README.md | 10 +- .../0520.Detect Capital/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0523.Continuous Subarray Sum/README.md | 10 +- .../0523.Continuous Subarray Sum/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0500-0599/0525.Contiguous Array/README.md | 10 +- .../0525.Contiguous Array/README_EN.md | 14 +- .../0526.Beautiful Arrangement/README.md | 10 +- .../0526.Beautiful Arrangement/README_EN.md | 32 +- .../0527.Word Abbreviation/README.md | 10 +- .../0527.Word Abbreviation/README_EN.md | 8 +- .../0528.Random Pick with Weight/README.md | 10 +- .../0528.Random Pick with Weight/README_EN.md | 30 +- solution/0500-0599/0529.Minesweeper/README.md | 41 +- .../0500-0599/0529.Minesweeper/README_EN.md | 27 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0500-0599/0531.Lonely Pixel I/README.md | 10 +- .../0531.Lonely Pixel I/README_EN.md | 7 +- .../0532.K-diff Pairs in an Array/README.md | 12 +- .../README_EN.md | 16 +- .../0500-0599/0533.Lonely Pixel II/README.md | 10 +- .../0533.Lonely Pixel II/README_EN.md | 20 +- .../0534.Game Play Analysis III/README.md | 5 +- .../0534.Game Play Analysis III/README_EN.md | 3 +- .../0535.Encode and Decode TinyURL/README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0539.Minimum Time Difference/README.md | 10 +- .../0539.Minimum Time Difference/README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0541.Reverse String II/README.md | 10 +- .../0541.Reverse String II/README_EN.md | 10 +- solution/0500-0599/0542.01 Matrix/README.md | 10 +- .../0500-0599/0542.01 Matrix/README_EN.md | 32 +- .../0543.Diameter of Binary Tree/README.md | 10 +- .../0543.Diameter of Binary Tree/README_EN.md | 10 +- .../0544.Output Contest Matches/README.md | 10 +- .../0544.Output Contest Matches/README_EN.md | 8 +- .../0545.Boundary of Binary Tree/README.md | 10 +- .../0545.Boundary of Binary Tree/README_EN.md | 7 +- .../0500-0599/0546.Remove Boxes/README.md | 10 +- .../0500-0599/0546.Remove Boxes/README_EN.md | 18 +- .../0500-0599/0547.Friend Circles/README.md | 10 +- .../0547.Friend Circles/README_EN.md | 18 +- .../0548.Split Array with Equal Sum/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0550.Game Play Analysis IV/README.md | 5 +- .../0550.Game Play Analysis IV/README_EN.md | 3 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../0500-0599/0553.Optimal Division/README.md | 10 +- .../0553.Optimal Division/README_EN.md | 12 +- solution/0500-0599/0554.Brick Wall/README.md | 25 +- .../0500-0599/0554.Brick Wall/README_EN.md | 25 +- .../0555.Split Concatenated Strings/README.md | 10 +- .../README_EN.md | 7 +- .../0556.Next Greater Element III/README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 25 +- .../README_EN.md | 7 +- .../0560.Subarray Sum Equals K/README.md | 12 +- .../0560.Subarray Sum Equals K/README_EN.md | 12 +- .../0561.Array Partition I/README.md | 10 +- .../0561.Array Partition I/README_EN.md | 10 +- .../0561.Array Partition I/Solution.js | 33 +- .../README.md | 12 +- .../README_EN.md | 6 +- .../0500-0599/0563.Binary Tree Tilt/README.md | 10 +- .../0563.Binary Tree Tilt/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0500-0599/0565.Array Nesting/README.md | 10 +- .../0500-0599/0565.Array Nesting/README_EN.md | 28 +- .../0566.Reshape the Matrix/README.md | 10 +- .../0566.Reshape the Matrix/README_EN.md | 18 +- .../0567.Permutation in String/README.md | 10 +- .../0567.Permutation in String/README_EN.md | 28 +- .../0568.Maximum Vacation Days/README.md | 10 +- .../0568.Maximum Vacation Days/README_EN.md | 7 +- .../0569.Median Employee Salary/README.md | 10 +- .../0569.Median Employee Salary/README_EN.md | 6 +- .../README.md | 9 +- .../README_EN.md | 5 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../0572.Subtree of Another Tree/README.md | 10 +- .../0572.Subtree of Another Tree/README_EN.md | 14 +- .../0573.Squirrel Simulation/README.md | 10 +- .../0573.Squirrel Simulation/README_EN.md | 8 +- .../0574.Winning Candidate/README.md | 7 +- .../0574.Winning Candidate/README_EN.md | 5 +- .../0575.Distribute Candies/README.md | 10 +- .../0575.Distribute Candies/README_EN.md | 12 +- .../0576.Out of Boundary Paths/README.md | 21 +- .../0576.Out of Boundary Paths/README_EN.md | 20 +- .../0500-0599/0577.Employee Bonus/README.md | 5 +- .../0577.Employee Bonus/README_EN.md | 3 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../README.md | 7 +- .../README_EN.md | 5 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0500-0599/0582.Kill Process/README.md | 10 +- .../0500-0599/0582.Kill Process/README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0584.Find Customer Referee/README.md | 5 +- .../0584.Find Customer Referee/README_EN.md | 3 +- .../0585.Investments in 2016/README.md | 7 +- .../0585.Investments in 2016/README_EN.md | 3 +- .../README.md | 7 +- .../README_EN.md | 5 +- .../0500-0599/0587.Erect the Fence/README.md | 21 +- .../0587.Erect the Fence/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 23 +- .../README_EN.md | 7 +- .../README.md | 22 +- .../README_EN.md | 8 +- .../0500-0599/0591.Tag Validator/README.md | 10 +- .../0500-0599/0591.Tag Validator/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0500-0599/0593.Valid Square/README.md | 10 +- .../0500-0599/0593.Valid Square/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0500-0599/0595.Big Countries/README.md | 5 +- .../0500-0599/0595.Big Countries/README_EN.md | 17 +- .../README.md | 9 +- .../README_EN.md | 21 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 11 +- .../README_EN.md | 9 +- .../0598.Range Addition II/README.md | 10 +- .../0598.Range Addition II/README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 12 +- .../README_EN.md | 12 +- .../0601.Human Traffic of Stadium/README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 9 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0605.Can Place Flowers/README.md | 10 +- .../0605.Can Place Flowers/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0600-0699/0607.Sales Person/README.md | 9 +- .../0600-0699/0607.Sales Person/README_EN.md | 7 +- solution/0600-0699/0608.Tree Node/README.md | 9 +- .../0600-0699/0608.Tree Node/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 54 +- .../0610.Triangle Judgement/README.md | 5 +- .../0610.Triangle Judgement/README_EN.md | 3 +- .../0611.Valid Triangle Number/README.md | 10 +- .../0611.Valid Triangle Number/README_EN.md | 12 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../0614.Second Degree Follower/README.md | 7 +- .../0614.Second Degree Follower/README_EN.md | 5 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../0616.Add Bold Tag in String/README.md | 10 +- .../0616.Add Bold Tag in String/README_EN.md | 8 +- .../0617.Merge Two Binary Trees/README.md | 10 +- .../0617.Merge Two Binary Trees/README_EN.md | 18 +- .../README.md | 11 +- .../README_EN.md | 9 +- .../0619.Biggest Single Number/README.md | 5 +- .../0619.Biggest Single Number/README_EN.md | 3 +- .../0620.Not Boring Movies/README.md | 5 +- .../0620.Not Boring Movies/README_EN.md | 15 +- .../0600-0699/0621.Task Scheduler/README.md | 10 +- .../0621.Task Scheduler/README_EN.md | 28 +- .../0622.Design Circular Queue/README.md | 10 +- .../0622.Design Circular Queue/README_EN.md | 44 +- .../0623.Add One Row to Tree/README.md | 10 +- .../0623.Add One Row to Tree/README_EN.md | 16 +- .../0624.Maximum Distance in Arrays/README.md | 10 +- .../README_EN.md | 6 +- .../0625.Minimum Factorization/README.md | 10 +- .../0625.Minimum Factorization/README_EN.md | 7 +- .../0600-0699/0626.Exchange Seats/README.md | 5 +- .../0626.Exchange Seats/README_EN.md | 19 +- solution/0600-0699/0627.Swap Salary/README.md | 5 +- .../0600-0699/0627.Swap Salary/README_EN.md | 15 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../0629.K Inverse Pairs Array/README.md | 12 +- .../0629.K Inverse Pairs Array/README_EN.md | 32 +- .../0630.Course Schedule III/README.md | 10 +- .../0630.Course Schedule III/README_EN.md | 26 +- .../0631.Design Excel Sum Formula/README.md | 10 +- .../README_EN.md | 17 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0633.Sum of Square Numbers/README.md | 10 +- .../0633.Sum of Square Numbers/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../0635.Design Log Storage System/README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0600-0699/0638.Shopping Offers/README.md | 10 +- .../0638.Shopping Offers/README_EN.md | 20 +- .../0600-0699/0639.Decode Ways II/README.md | 10 +- .../0639.Decode Ways II/README_EN.md | 26 +- .../0640.Solve the Equation/README.md | 10 +- .../0640.Solve the Equation/README_EN.md | 18 +- .../0641.Design Circular Deque/README.md | 10 +- .../0641.Design Circular Deque/README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0643.Maximum Average Subarray I/README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../0600-0699/0645.Set Mismatch/README.md | 9 +- .../0600-0699/0645.Set Mismatch/README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../0647.Palindromic Substrings/README.md | 10 +- .../0647.Palindromic Substrings/README_EN.md | 28 +- .../0600-0699/0648.Replace Words/README.md | 10 +- .../0600-0699/0648.Replace Words/README_EN.md | 34 +- .../0600-0699/0649.Dota2 Senate/README.md | 21 +- .../0600-0699/0649.Dota2 Senate/README_EN.md | 48 +- .../0600-0699/0650.2 Keys Keyboard/README.md | 10 +- .../0650.2 Keys Keyboard/README_EN.md | 32 +- .../0600-0699/0651.4 Keys Keyboard/README.md | 12 +- .../0651.4 Keys Keyboard/README_EN.md | 10 +- .../0652.Find Duplicate Subtrees/README.md | 10 +- .../0652.Find Duplicate Subtrees/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0654.Maximum Binary Tree/README.md | 10 +- .../0654.Maximum Binary Tree/README_EN.md | 14 +- .../0655.Print Binary Tree/README.md | 10 +- .../0655.Print Binary Tree/README_EN.md | 18 +- solution/0600-0699/0656.Coin Path/README.md | 10 +- .../0600-0699/0656.Coin Path/README_EN.md | 7 +- .../0657.Robot Return to Origin/README.md | 10 +- .../0657.Robot Return to Origin/README_EN.md | 22 +- .../0658.Find K Closest Elements/README.md | 10 +- .../0658.Find K Closest Elements/README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/0600-0699/0660.Remove 9/README.md | 10 +- solution/0600-0699/0660.Remove 9/README_EN.md | 7 +- .../0600-0699/0661.Image Smoother/README.md | 10 +- .../0661.Image Smoother/README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0663.Equal Tree Partition/README.md | 10 +- .../0663.Equal Tree Partition/README_EN.md | 25 +- .../0600-0699/0664.Strange Printer/README.md | 10 +- .../0664.Strange Printer/README_EN.md | 18 +- .../0665.Non-decreasing Array/README.md | 10 +- .../0665.Non-decreasing Array/README_EN.md | 14 +- solution/0600-0699/0666.Path Sum IV/README.md | 10 +- .../0600-0699/0666.Path Sum IV/README_EN.md | 7 +- .../0667.Beautiful Arrangement II/README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 12 +- .../README_EN.md | 20 +- .../0669.Trim a Binary Search Tree/README.md | 10 +- .../README_EN.md | 10 +- .../0600-0699/0670.Maximum Swap/README.md | 10 +- .../0600-0699/0670.Maximum Swap/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0600-0699/0672.Bulb Switcher II/README.md | 10 +- .../0672.Bulb Switcher II/README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0676.Implement Magic Dictionary/README.md | 10 +- .../README_EN.md | 14 +- .../0600-0699/0677.Map Sum Pairs/README.md | 10 +- .../0600-0699/0677.Map Sum Pairs/README_EN.md | 14 +- .../0678.Valid Parenthesis String/README.md | 10 +- .../README_EN.md | 16 +- solution/0600-0699/0679.24 Game/README.md | 10 +- solution/0600-0699/0679.24 Game/README_EN.md | 14 +- .../0680.Valid Palindrome II/README.md | 10 +- .../0680.Valid Palindrome II/README_EN.md | 14 +- .../0681.Next Closest Time/README.md | 10 +- .../0681.Next Closest Time/README_EN.md | 6 +- .../0600-0699/0682.Baseball Game/README.md | 10 +- .../0600-0699/0682.Baseball Game/README_EN.md | 18 +- .../0600-0699/0683.K Empty Slots/README.md | 10 +- .../0600-0699/0683.K Empty Slots/README_EN.md | 7 +- .../0684.Redundant Connection/README.md | 10 +- .../0684.Redundant Connection/README_EN.md | 16 +- .../0685.Redundant Connection II/README.md | 10 +- .../0685.Redundant Connection II/README_EN.md | 12 +- .../0686.Repeated String Match/README.md | 10 +- .../0686.Repeated String Match/README_EN.md | 14 +- .../0687.Longest Univalue Path/README.md | 10 +- .../0687.Longest Univalue Path/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 29 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../0690.Employee Importance/README.md | 10 +- .../0690.Employee Importance/README_EN.md | 28 +- .../0691.Stickers to Spell Word/README.md | 10 +- .../0691.Stickers to Spell Word/README_EN.md | 24 +- .../0692.Top K Frequent Words/README.md | 12 +- .../0692.Top K Frequent Words/README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0694.Number of Distinct Islands/README.md | 10 +- .../README_EN.md | 6 +- .../0695.Max Area of Island/README.md | 10 +- .../0695.Max Area of Island/README_EN.md | 20 +- .../0696.Count Binary Substrings/README.md | 10 +- .../0696.Count Binary Substrings/README_EN.md | 14 +- .../0697.Degree of an Array/README.md | 10 +- .../0697.Degree of an Array/README_EN.md | 14 +- .../README.md | 12 +- .../README_EN.md | 24 +- .../0600-0699/0699.Falling Squares/README.md | 10 +- .../0699.Falling Squares/README_EN.md | 46 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 16 +- .../0700-0799/0704.Binary Search/README.md | 10 +- .../0700-0799/0704.Binary Search/README_EN.md | 28 +- .../0700-0799/0705.Design HashSet/README.md | 10 +- .../0705.Design HashSet/README_EN.md | 32 +- .../0700-0799/0706.Design HashMap/README.md | 10 +- .../0706.Design HashMap/README_EN.md | 32 +- .../0707.Design Linked List/README.md | 10 +- .../0707.Design Linked List/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0700-0799/0709.To Lower Case/README.md | 10 +- .../0700-0799/0709.To Lower Case/README_EN.md | 20 +- .../0710.Random Pick with Blacklist/README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 12 +- .../README_EN.md | 14 +- .../README.md | 12 +- .../README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0700-0799/0715.Range Module/README.md | 10 +- .../0700-0799/0715.Range Module/README_EN.md | 20 +- solution/0700-0799/0716.Max Stack/README.md | 10 +- .../0700-0799/0716.Max Stack/README_EN.md | 6 +- .../0717.1-bit and 2-bit Characters/README.md | 12 +- .../README_EN.md | 14 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../0720.Longest Word in Dictionary/README.md | 10 +- .../README_EN.md | 12 +- .../0700-0799/0721.Accounts Merge/README.md | 10 +- .../0721.Accounts Merge/README_EN.md | 14 +- .../0700-0799/0722.Remove Comments/README.md | 10 +- .../0722.Remove Comments/README_EN.md | 26 +- solution/0700-0799/0723.Candy Crush/README.md | 10 +- .../0700-0799/0723.Candy Crush/README_EN.md | 7 +- .../0700-0799/0724.Find Pivot Index/README.md | 10 +- .../0724.Find Pivot Index/README_EN.md | 34 +- .../0725.Split Linked List in Parts/README.md | 10 +- .../README_EN.md | 18 +- .../0700-0799/0726.Number of Atoms/README.md | 10 +- .../0726.Number of Atoms/README_EN.md | 20 +- .../0727.Minimum Window Subsequence/README.md | 10 +- .../README_EN.md | 6 +- .../0728.Self Dividing Numbers/README.md | 10 +- .../0728.Self Dividing Numbers/README_EN.md | 8 +- .../0700-0799/0729.My Calendar I/README.md | 10 +- .../0700-0799/0729.My Calendar I/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0700-0799/0731.My Calendar II/README.md | 10 +- .../0731.My Calendar II/README_EN.md | 28 +- .../0700-0799/0732.My Calendar III/README.md | 10 +- .../0732.My Calendar III/README_EN.md | 28 +- solution/0700-0799/0733.Flood Fill/README.md | 10 +- .../0700-0799/0733.Flood Fill/README_EN.md | 10 +- .../0734.Sentence Similarity/README.md | 10 +- .../0734.Sentence Similarity/README_EN.md | 7 +- .../0735.Asteroid Collision/README.md | 10 +- .../0735.Asteroid Collision/README_EN.md | 20 +- .../0736.Parse Lisp Expression/README.md | 10 +- .../0736.Parse Lisp Expression/README_EN.md | 10 +- .../0737.Sentence Similarity II/README.md | 10 +- .../0737.Sentence Similarity II/README_EN.md | 7 +- .../0738.Monotone Increasing Digits/README.md | 10 +- .../README_EN.md | 14 +- .../0739.Daily Temperatures/README.md | 10 +- .../0739.Daily Temperatures/README_EN.md | 10 +- .../0700-0799/0740.Delete and Earn/README.md | 12 +- .../0740.Delete and Earn/README_EN.md | 34 +- .../0700-0799/0741.Cherry Pickup/README.md | 10 +- .../0700-0799/0741.Cherry Pickup/README_EN.md | 60 +- .../README.md | 10 +- .../README_EN.md | 9 +- .../0743.Network Delay Time/README.md | 10 +- .../0743.Network Delay Time/README_EN.md | 23 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../0745.Prefix and Suffix Search/README.md | 10 +- .../README_EN.md | 32 +- .../0746.Min Cost Climbing Stairs/README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../0748.Shortest Completing Word/README.md | 10 +- .../README_EN.md | 20 +- .../0700-0799/0749.Contain Virus/README.md | 10 +- .../0700-0799/0749.Contain Virus/README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/0700-0799/0751.IP to CIDR/README.md | 10 +- .../0700-0799/0751.IP to CIDR/README_EN.md | 9 +- .../0700-0799/0752.Open the Lock/README.md | 10 +- .../0700-0799/0752.Open the Lock/README_EN.md | 18 +- .../0753.Cracking the Safe/README.md | 10 +- .../0753.Cracking the Safe/README_EN.md | 7 +- .../0700-0799/0754.Reach a Number/README.md | 10 +- .../0754.Reach a Number/README_EN.md | 16 +- solution/0700-0799/0755.Pour Water/README.md | 15 +- .../0700-0799/0755.Pour Water/README_EN.md | 94 +- .../0756.Pyramid Transition Matrix/README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 12 +- .../README_EN.md | 12 +- .../0758.Bold Words in String/README.md | 10 +- .../0758.Bold Words in String/README_EN.md | 7 +- .../0759.Employee Free Time/README.md | 10 +- .../0759.Employee Free Time/README_EN.md | 7 +- .../0760.Find Anagram Mappings/README.md | 10 +- .../0760.Find Anagram Mappings/README_EN.md | 6 +- .../0761.Special Binary String/README.md | 10 +- .../0761.Special Binary String/README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 14 +- .../0700-0799/0763.Partition Labels/README.md | 10 +- .../0763.Partition Labels/README_EN.md | 12 +- .../0764.Largest Plus Sign/README.md | 10 +- .../0764.Largest Plus Sign/README_EN.md | 26 +- .../0765.Couples Holding Hands/README.md | 10 +- .../0765.Couples Holding Hands/README_EN.md | 16 +- .../0700-0799/0766.Toeplitz Matrix/README.md | 10 +- .../0766.Toeplitz Matrix/README_EN.md | 36 +- .../0767.Reorganize String/README.md | 10 +- .../0767.Reorganize String/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0769.Max Chunks To Make Sorted/README.md | 10 +- .../README_EN.md | 28 +- .../0770.Basic Calculator IV/README.md | 10 +- .../0770.Basic Calculator IV/README_EN.md | 44 +- .../0771.Jewels and Stones/README.md | 10 +- .../0771.Jewels and Stones/README_EN.md | 26 +- .../0772.Basic Calculator III/README.md | 10 +- .../0772.Basic Calculator III/README_EN.md | 7 +- .../0700-0799/0773.Sliding Puzzle/README.md | 10 +- .../0773.Sliding Puzzle/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 32 +- solution/0700-0799/0776.Split BST/README.md | 10 +- .../0700-0799/0776.Split BST/README_EN.md | 6 +- .../0777.Swap Adjacent in LR String/README.md | 12 +- .../README_EN.md | 20 +- .../0778.Swim in Rising Water/README.md | 10 +- .../0778.Swim in Rising Water/README_EN.md | 28 +- .../0779.K-th Symbol in Grammar/README.md | 12 +- .../0779.K-th Symbol in Grammar/README_EN.md | 20 +- .../0700-0799/0780.Reaching Points/README.md | 10 +- .../0780.Reaching Points/README_EN.md | 18 +- .../0781.Rabbits in Forest/README.md | 10 +- .../0781.Rabbits in Forest/README_EN.md | 20 +- .../0782.Transform to Chessboard/README.md | 10 +- .../0782.Transform to Chessboard/README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0784.Letter Case Permutation/README.md | 10 +- .../0784.Letter Case Permutation/README_EN.md | 18 +- .../0785.Is Graph Bipartite/README.md | 10 +- .../0785.Is Graph Bipartite/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0700-0799/0788.Rotated Digits/README.md | 10 +- .../0788.Rotated Digits/README_EN.md | 20 +- .../0789.Escape The Ghosts/README.md | 10 +- .../0789.Escape The Ghosts/README_EN.md | 28 +- .../0790.Domino and Tromino Tiling/README.md | 10 +- .../README_EN.md | 26 +- .../0791.Custom Sort String/README.md | 10 +- .../0791.Custom Sort String/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 12 +- .../README_EN.md | 18 +- .../0794.Valid Tic-Tac-Toe State/README.md | 10 +- .../0794.Valid Tic-Tac-Toe State/README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../0700-0799/0796.Rotate String/README.md | 10 +- .../0700-0799/0796.Rotate String/README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0700-0799/0799.Champagne Tower/README.md | 10 +- .../0799.Champagne Tower/README_EN.md | 24 +- .../0800.Similar RGB Color/README.md | 10 +- .../0800.Similar RGB Color/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0802.Find Eventual Safe States/README.md | 10 +- .../README_EN.md | 21 +- .../0803.Bricks Falling When Hit/README.md | 10 +- .../0803.Bricks Falling When Hit/README_EN.md | 30 +- .../0804.Unique Morse Code Words/README.md | 10 +- .../0804.Unique Morse Code Words/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 22 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0800-0899/0808.Soup Servings/README.md | 10 +- .../0800-0899/0808.Soup Servings/README_EN.md | 36 +- .../0800-0899/0809.Expressive Words/README.md | 10 +- .../0809.Expressive Words/README_EN.md | 34 +- .../0810.Chalkboard XOR Game/README.md | 10 +- .../0810.Chalkboard XOR Game/README_EN.md | 24 +- .../0811.Subdomain Visit Count/README.md | 10 +- .../0811.Subdomain Visit Count/README_EN.md | 30 +- .../0812.Largest Triangle Area/README.md | 10 +- .../0812.Largest Triangle Area/README_EN.md | 15 +- .../0813.Largest Sum of Averages/README.md | 10 +- .../0813.Largest Sum of Averages/README_EN.md | 26 +- .../0814.Binary Tree Pruning/README.md | 10 +- .../0814.Binary Tree Pruning/README_EN.md | 16 +- solution/0800-0899/0815.Bus Routes/README.md | 10 +- .../0800-0899/0815.Bus Routes/README_EN.md | 22 +- .../0816.Ambiguous Coordinates/README.md | 10 +- .../0816.Ambiguous Coordinates/README_EN.md | 32 +- .../0817.Linked List Components/README.md | 10 +- .../0817.Linked List Components/README_EN.md | 32 +- solution/0800-0899/0818.Race Car/README.md | 10 +- solution/0800-0899/0818.Race Car/README_EN.md | 30 +- .../0800-0899/0819.Most Common Word/README.md | 10 +- .../0819.Most Common Word/README_EN.md | 36 +- .../0820.Short Encoding of Words/README.md | 10 +- .../0820.Short Encoding of Words/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0822.Card Flipping Game/README.md | 10 +- .../0822.Card Flipping Game/README_EN.md | 34 +- .../0823.Binary Trees With Factors/README.md | 10 +- .../README_EN.md | 32 +- solution/0800-0899/0824.Goat Latin/README.md | 10 +- .../0800-0899/0824.Goat Latin/README_EN.md | 52 +- .../README.md | 10 +- .../README_EN.md | 46 +- .../0826.Most Profit Assigning Work/README.md | 10 +- .../README_EN.md | 30 +- .../0827.Making A Large Island/README.md | 10 +- .../0827.Making A Large Island/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0829.Consecutive Numbers Sum/README.md | 10 +- .../0829.Consecutive Numbers Sum/README_EN.md | 22 +- .../0830.Positions of Large Groups/README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 64 +- .../0832.Flipping an Image/README.md | 10 +- .../0832.Flipping an Image/README_EN.md | 28 +- .../0832.Flipping an Image/Solution.js | 26 +- .../0833.Find And Replace in String/README.md | 10 +- .../README_EN.md | 36 +- .../0834.Sum of Distances in Tree/README.md | 10 +- .../README_EN.md | 18 +- .../0800-0899/0835.Image Overlap/README.md | 10 +- .../0800-0899/0835.Image Overlap/README_EN.md | 26 +- .../0836.Rectangle Overlap/README.md | 10 +- .../0836.Rectangle Overlap/README_EN.md | 28 +- solution/0800-0899/0837.New 21 Game/README.md | 12 +- .../0800-0899/0837.New 21 Game/README_EN.md | 36 +- .../0800-0899/0838.Push Dominoes/README.md | 10 +- .../0800-0899/0838.Push Dominoes/README_EN.md | 32 +- .../0839.Similar String Groups/README.md | 10 +- .../0839.Similar String Groups/README_EN.md | 7 +- .../0840.Magic Squares In Grid/README.md | 10 +- .../0840.Magic Squares In Grid/README_EN.md | 26 +- .../0800-0899/0841.Keys and Rooms/README.md | 10 +- .../0841.Keys and Rooms/README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 50 +- .../0800-0899/0843.Guess the Word/README.md | 10 +- .../0843.Guess the Word/README_EN.md | 22 +- .../0844.Backspace String Compare/README.md | 10 +- .../README_EN.md | 40 +- .../0845.Longest Mountain in Array/README.md | 10 +- .../README_EN.md | 44 +- .../0846.Hand of Straights/README.md | 10 +- .../0846.Hand of Straights/README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../0800-0899/0848.Shifting Letters/README.md | 10 +- .../0848.Shifting Letters/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../0850.Rectangle Area II/README.md | 10 +- .../0850.Rectangle Area II/README_EN.md | 19 +- .../0800-0899/0851.Loud and Rich/README.md | 10 +- .../0800-0899/0851.Loud and Rich/README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 34 +- solution/0800-0899/0853.Car Fleet/README.md | 10 +- .../0800-0899/0853.Car Fleet/README_EN.md | 38 +- .../0854.K-Similar Strings/README.md | 10 +- .../0854.K-Similar Strings/README_EN.md | 34 +- solution/0800-0899/0855.Exam Room/README.md | 10 +- .../0800-0899/0855.Exam Room/README_EN.md | 30 +- .../0856.Score of Parentheses/README.md | 10 +- .../0856.Score of Parentheses/README_EN.md | 44 +- .../README.md | 10 +- .../README_EN.md | 44 +- .../0858.Mirror Reflection/README.md | 10 +- .../0858.Mirror Reflection/README_EN.md | 23 +- .../0800-0899/0859.Buddy Strings/README.md | 10 +- .../0800-0899/0859.Buddy Strings/README_EN.md | 42 +- .../0800-0899/0860.Lemonade Change/README.md | 10 +- .../0860.Lemonade Change/README_EN.md | 44 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 12 +- .../README_EN.md | 24 +- .../0800-0899/0866.Prime Palindrome/README.md | 10 +- .../0866.Prime Palindrome/README_EN.md | 40 +- .../0800-0899/0867.Transpose Matrix/README.md | 10 +- .../0867.Transpose Matrix/README_EN.md | 26 +- .../0867.Transpose Matrix/Solution.js | 10 +- solution/0800-0899/0868.Binary Gap/README.md | 10 +- .../0800-0899/0868.Binary Gap/README_EN.md | 38 +- .../0869.Reordered Power of 2/README.md | 10 +- .../0869.Reordered Power of 2/README_EN.md | 42 +- .../0870.Advantage Shuffle/README.md | 10 +- .../0870.Advantage Shuffle/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 44 +- .../0872.Leaf-Similar Trees/README.md | 10 +- .../0872.Leaf-Similar Trees/README_EN.md | 21 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../0874.Walking Robot Simulation/README.md | 10 +- .../README_EN.md | 50 +- .../0875.Koko Eating Bananas/README.md | 10 +- .../0875.Koko Eating Bananas/README_EN.md | 42 +- .../0876.Middle of the Linked List/README.md | 10 +- .../README_EN.md | 28 +- solution/0800-0899/0877.Stone Game/README.md | 10 +- .../0800-0899/0877.Stone Game/README_EN.md | 32 +- .../0878.Nth Magical Number/README.md | 10 +- .../0878.Nth Magical Number/README_EN.md | 42 +- .../0879.Profitable Schemes/README.md | 10 +- .../0879.Profitable Schemes/README_EN.md | 44 +- .../0880.Decoded String at Index/README.md | 10 +- .../0880.Decoded String at Index/README_EN.md | 46 +- .../0881.Boats to Save People/README.md | 10 +- .../0881.Boats to Save People/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 53 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../0885.Spiral Matrix III/README.md | 10 +- .../0885.Spiral Matrix III/README_EN.md | 32 +- .../0886.Possible Bipartition/README.md | 10 +- .../0886.Possible Bipartition/README_EN.md | 46 +- .../0800-0899/0887.Super Egg Drop/README.md | 10 +- .../0887.Super Egg Drop/README_EN.md | 44 +- .../0800-0899/0888.Fair Candy Swap/README.md | 10 +- .../0888.Fair Candy Swap/README_EN.md | 50 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../0890.Find and Replace Pattern/README.md | 10 +- .../README_EN.md | 32 +- .../0891.Sum of Subsequence Widths/README.md | 10 +- .../README_EN.md | 30 +- .../0892.Surface Area of 3D Shapes/README.md | 10 +- .../README_EN.md | 46 +- .../README.md | 10 +- .../README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0895.Maximum Frequency Stack/README.md | 10 +- .../0895.Maximum Frequency Stack/README_EN.md | 48 +- .../0800-0899/0896.Monotonic Array/README.md | 10 +- .../0896.Monotonic Array/README_EN.md | 46 +- .../0896.Monotonic Array/Solution.js | 13 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0898.Bitwise ORs of Subarrays/README.md | 10 +- .../README_EN.md | 36 +- .../0800-0899/0899.Orderly Queue/README.md | 10 +- .../0800-0899/0899.Orderly Queue/README_EN.md | 32 +- .../0900-0999/0900.RLE Iterator/README.md | 10 +- .../0900-0999/0900.RLE Iterator/README_EN.md | 34 +- .../0901.Online Stock Span/README.md | 10 +- .../0901.Online Stock Span/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../0904.Fruit Into Baskets/README.md | 10 +- .../0904.Fruit Into Baskets/README_EN.md | 50 +- .../0905.Sort Array By Parity/README.md | 10 +- .../0905.Sort Array By Parity/README_EN.md | 26 +- .../0905.Sort Array By Parity/Solution.js | 4 +- .../0906.Super Palindromes/README.md | 10 +- .../0906.Super Palindromes/README_EN.md | 32 +- .../0907.Sum of Subarray Minimums/README.md | 10 +- .../README_EN.md | 28 +- .../0900-0999/0908.Smallest Range I/README.md | 10 +- .../0908.Smallest Range I/README_EN.md | 38 +- .../0909.Snakes and Ladders/README.md | 10 +- .../0909.Snakes and Ladders/README_EN.md | 25 +- .../0910.Smallest Range II/README.md | 10 +- .../0910.Smallest Range II/README_EN.md | 38 +- .../0900-0999/0911.Online Election/README.md | 10 +- .../0911.Online Election/README_EN.md | 34 +- .../0900-0999/0912.Sort an Array/README.md | 10 +- .../0900-0999/0912.Sort an Array/README_EN.md | 7 +- .../0900-0999/0913.Cat and Mouse/README.md | 10 +- .../0900-0999/0913.Cat and Mouse/README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../0900-0999/0916.Word Subsets/README.md | 10 +- .../0900-0999/0916.Word Subsets/README_EN.md | 52 +- .../0917.Reverse Only Letters/README.md | 10 +- .../0917.Reverse Only Letters/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 44 +- .../README.md | 10 +- .../README_EN.md | 46 +- .../0920.Number of Music Playlists/README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 48 +- .../0922.Sort Array By Parity II/README.md | 10 +- .../0922.Sort Array By Parity II/README_EN.md | 30 +- .../0922.Sort Array By Parity II/Solution.js | 20 +- .../0923.3Sum With Multiplicity/README.md | 10 +- .../0923.3Sum With Multiplicity/README_EN.md | 30 +- .../0924.Minimize Malware Spread/README.md | 10 +- .../0924.Minimize Malware Spread/README_EN.md | 7 +- .../0925.Long Pressed Name/README.md | 10 +- .../0925.Long Pressed Name/README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../Solution.js | 6 +- .../0927.Three Equal Parts/README.md | 10 +- .../0927.Three Equal Parts/README_EN.md | 44 +- .../0928.Minimize Malware Spread II/README.md | 10 +- .../README_EN.md | 46 +- .../0929.Unique Email Addresses/README.md | 10 +- .../0929.Unique Email Addresses/README_EN.md | 42 +- .../0929.Unique Email Addresses/Solution.js | 48 +- .../0930.Binary Subarrays With Sum/README.md | 10 +- .../README_EN.md | 24 +- .../Solution.js | 24 +- .../0931.Minimum Falling Path Sum/README.md | 10 +- .../README_EN.md | 34 +- .../0900-0999/0932.Beautiful Array/README.md | 10 +- .../0932.Beautiful Array/README_EN.md | 30 +- .../0933.Number of Recent Calls/README.md | 10 +- .../0933.Number of Recent Calls/README_EN.md | 34 +- .../0900-0999/0934.Shortest Bridge/README.md | 10 +- .../0934.Shortest Bridge/README_EN.md | 36 +- .../0900-0999/0935.Knight Dialer/README.md | 12 +- .../0900-0999/0935.Knight Dialer/README_EN.md | 42 +- .../0936.Stamping The Sequence/README.md | 10 +- .../0936.Stamping The Sequence/README_EN.md | 38 +- .../0937.Reorder Data in Log Files/README.md | 10 +- .../README_EN.md | 7 +- .../0900-0999/0938.Range Sum of BST/README.md | 10 +- .../0938.Range Sum of BST/README_EN.md | 28 +- .../0939.Minimum Area Rectangle/README.md | 10 +- .../0939.Minimum Area Rectangle/README_EN.md | 32 +- .../0940.Distinct Subsequences II/README.md | 10 +- .../README_EN.md | 38 +- .../0941.Valid Mountain Array/README.md | 10 +- .../0941.Valid Mountain Array/README_EN.md | 50 +- .../0900-0999/0942.DI String Match/README.md | 10 +- .../0942.DI String Match/README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../0946.Validate Stack Sequences/README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../0900-0999/0948.Bag of Tokens/README.md | 10 +- .../0900-0999/0948.Bag of Tokens/README_EN.md | 46 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../0954.Array of Doubled Pairs/README.md | 10 +- .../0954.Array of Doubled Pairs/README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../0956.Tallest Billboard/README.md | 10 +- .../0956.Tallest Billboard/README_EN.md | 38 +- .../0957.Prison Cells After N Days/README.md | 10 +- .../README_EN.md | 46 +- .../README.md | 10 +- .../README_EN.md | 27 +- .../0959.Regions Cut By Slashes/README.md | 10 +- .../0959.Regions Cut By Slashes/README_EN.md | 31 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../Solution.js | 16 +- .../0962.Maximum Width Ramp/README.md | 10 +- .../0962.Maximum Width Ramp/README_EN.md | 32 +- .../0963.Minimum Area Rectangle II/README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 48 +- .../0965.Univalued Binary Tree/README.md | 10 +- .../0965.Univalued Binary Tree/README_EN.md | 22 +- .../0966.Vowel Spellchecker/README.md | 37 +- .../0966.Vowel Spellchecker/README_EN.md | 76 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0968.Binary Tree Cameras/README.md | 12 +- .../0968.Binary Tree Cameras/README_EN.md | 22 +- .../0900-0999/0969.Pancake Sorting/README.md | 10 +- .../0969.Pancake Sorting/README_EN.md | 30 +- .../0970.Powerful Integers/README.md | 10 +- .../0970.Powerful Integers/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 41 +- .../0972.Equal Rational Numbers/README.md | 10 +- .../0972.Equal Rational Numbers/README_EN.md | 54 +- .../0973.K Closest Points to Origin/README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../0900-0999/0975.Odd Even Jump/README.md | 10 +- .../0900-0999/0975.Odd Even Jump/README_EN.md | 44 +- .../0976.Largest Perimeter Triangle/README.md | 10 +- .../README_EN.md | 38 +- .../0977.Squares of a Sorted Array/README.md | 10 +- .../README_EN.md | 28 +- .../Solution.js | 46 +- .../0978.Longest Turbulent Subarray/README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 35 +- .../0900-0999/0980.Unique Paths III/README.md | 10 +- .../0980.Unique Paths III/README_EN.md | 40 +- .../0981.Time Based Key-Value Store/README.md | 10 +- .../README_EN.md | 50 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../0983.Minimum Cost For Tickets/README.md | 10 +- .../README_EN.md | 48 +- .../0984.String Without AAA or BBB/README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../Solution.js | 14 +- .../README.md | 10 +- .../README_EN.md | 27 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 50 +- .../0991.Broken Calculator/README.md | 10 +- .../0991.Broken Calculator/README_EN.md | 44 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0993.Cousins in Binary Tree/README.md | 10 +- .../0993.Cousins in Binary Tree/README_EN.md | 35 +- .../0900-0999/0994.Rotting Oranges/README.md | 10 +- .../0994.Rotting Oranges/README_EN.md | 33 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../0996.Number of Squareful Arrays/README.md | 10 +- .../README_EN.md | 28 +- .../0997.Find the Town Judge/README.md | 10 +- .../0997.Find the Town Judge/README_EN.md | 60 +- .../0998.Maximum Binary Tree II/README.md | 11 +- .../0998.Maximum Binary Tree II/README_EN.md | 35 +- .../README.md | 11 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1001.Grid Illumination/README.md | 10 +- .../1001.Grid Illumination/README_EN.md | 34 +- .../1002.Find Common Characters/README.md | 10 +- .../1002.Find Common Characters/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../1004.Max Consecutive Ones III/README.md | 12 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1000-1099/1006.Clumsy Factorial/README.md | 10 +- .../1006.Clumsy Factorial/README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1014.Best Sightseeing Pair/README.md | 10 +- .../1014.Best Sightseeing Pair/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../1017.Convert to Base -2/README.md | 10 +- .../1017.Convert to Base -2/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1020.Number of Enclaves/README.md | 10 +- .../1020.Number of Enclaves/README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../1023.Camelcase Matching/README.md | 10 +- .../1023.Camelcase Matching/README_EN.md | 38 +- .../1000-1099/1024.Video Stitching/README.md | 10 +- .../1024.Video Stitching/README_EN.md | 42 +- .../1000-1099/1025.Divisor Game/README.md | 10 +- .../1000-1099/1025.Divisor Game/README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 37 +- .../1029.Two City Scheduling/README.md | 10 +- .../1029.Two City Scheduling/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 46 +- .../1032.Stream of Characters/README.md | 10 +- .../1032.Stream of Characters/README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 46 +- .../1034.Coloring A Border/README.md | 10 +- .../1034.Coloring A Border/README_EN.md | 44 +- .../1000-1099/1035.Uncrossed Lines/README.md | 10 +- .../1035.Uncrossed Lines/README_EN.md | 35 +- .../1036.Escape a Large Maze/README.md | 10 +- .../1036.Escape a Large Maze/README_EN.md | 40 +- .../1000-1099/1037.Valid Boomerang/README.md | 10 +- .../1037.Valid Boomerang/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 33 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../1041.Robot Bounded In Circle/README.md | 10 +- .../1041.Robot Bounded In Circle/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../1046.Last Stone Weight/README.md | 10 +- .../1046.Last Stone Weight/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../1048.Longest String Chain/README.md | 10 +- .../1048.Longest String Chain/README_EN.md | 32 +- .../1049.Last Stone Weight II/README.md | 10 +- .../1049.Last Stone Weight II/README_EN.md | 32 +- .../README.md | 5 +- .../README_EN.md | 3 +- .../1000-1099/1051.Height Checker/README.md | 10 +- .../1051.Height Checker/README_EN.md | 7 +- .../1052.Grumpy Bookstore Owner/README.md | 10 +- .../1052.Grumpy Bookstore Owner/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1000-1099/1054.Distant Barcodes/README.md | 10 +- .../1054.Distant Barcodes/README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1000-1099/1056.Confusing Number/README.md | 10 +- .../1056.Confusing Number/README_EN.md | 6 +- .../1000-1099/1057.Campus Bikes/README.md | 10 +- .../1000-1099/1057.Campus Bikes/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1063.Number of Valid Subarrays/README.md | 10 +- .../README_EN.md | 6 +- solution/1000-1099/1064.Fixed Point/README.md | 10 +- .../1000-1099/1064.Fixed Point/README_EN.md | 7 +- .../1065.Index Pairs of a String/README.md | 10 +- .../1065.Index Pairs of a String/README_EN.md | 6 +- .../1000-1099/1066.Campus Bikes II/README.md | 10 +- .../1066.Campus Bikes II/README_EN.md | 6 +- .../1067.Digit Count in Range/README.md | 10 +- .../1067.Digit Count in Range/README_EN.md | 7 +- .../1068.Product Sales Analysis I/README.md | 4 +- .../README_EN.md | 3 +- .../1069.Product Sales Analysis II/README.md | 5 +- .../README_EN.md | 2 +- .../1070.Product Sales Analysis III/README.md | 7 +- .../README_EN.md | 5 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1075.Project Employees I/README.md | 5 +- .../1075.Project Employees I/README_EN.md | 3 +- .../1076.Project Employees II/README.md | 7 +- .../1076.Project Employees II/README_EN.md | 3 +- .../1077.Project Employees III/README.md | 7 +- .../1077.Project Employees III/README_EN.md | 5 +- .../1078.Occurrences After Bigram/README.md | 10 +- .../README_EN.md | 34 +- .../1079.Letter Tile Possibilities/README.md | 10 +- .../README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 31 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1000-1099/1082.Sales Analysis I/README.md | 7 +- .../1082.Sales Analysis I/README_EN.md | 5 +- .../1083.Sales Analysis II/README.md | 5 +- .../1083.Sales Analysis II/README_EN.md | 3 +- .../1084.Sales Analysis III/README.md | 7 +- .../1084.Sales Analysis III/README_EN.md | 3 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/1000-1099/1086.High Five/README.md | 10 +- .../1000-1099/1086.High Five/README_EN.md | 6 +- .../1000-1099/1087.Brace Expansion/README.md | 10 +- .../1087.Brace Expansion/README_EN.md | 7 +- .../1088.Confusing Number II/README.md | 10 +- .../1088.Confusing Number II/README_EN.md | 7 +- .../1000-1099/1089.Duplicate Zeros/README.md | 10 +- .../1089.Duplicate Zeros/README_EN.md | 30 +- .../1090.Largest Values From Labels/README.md | 10 +- .../README_EN.md | 46 +- .../README.md | 12 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/1000-1099/1094.Car Pooling/README.md | 10 +- .../1000-1099/1094.Car Pooling/README_EN.md | 7 +- .../1095.Find in Mountain Array/README.md | 10 +- .../1095.Find in Mountain Array/README_EN.md | 7 +- .../1096.Brace Expansion II/README.md | 29 +- .../1096.Brace Expansion II/README_EN.md | 18 +- .../1097.Game Play Analysis V/README.md | 10 +- .../1097.Game Play Analysis V/README_EN.md | 6 +- .../1000-1099/1098.Unpopular Books/README.md | 10 +- .../1098.Unpopular Books/README_EN.md | 6 +- .../1099.Two Sum Less Than K/README.md | 10 +- .../1099.Two Sum Less Than K/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1105.Filling Bookcase Shelves/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1107.New Users Daily Count/README.md | 10 +- .../1107.New Users Daily Count/README_EN.md | 6 +- .../1108.Defanging an IP Address/README.md | 10 +- .../1108.Defanging an IP Address/README_EN.md | 14 +- .../1109.Corporate Flight Bookings/README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1100-1199/1113.Reported Posts/README.md | 10 +- .../1113.Reported Posts/README_EN.md | 6 +- .../1100-1199/1114.Print in Order/README.md | 10 +- .../1114.Print in Order/README_EN.md | 7 +- .../1115.Print FooBar Alternately/README.md | 12 +- .../README_EN.md | 7 +- .../1116.Print Zero Even Odd/README.md | 10 +- .../1116.Print Zero Even Odd/README_EN.md | 7 +- .../1100-1199/1117.Building H2O/README.md | 10 +- .../1100-1199/1117.Building H2O/README_EN.md | 7 +- .../1118.Number of Days in a Month/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1120.Maximum Average Subtree/README.md | 10 +- .../1120.Maximum Average Subtree/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1122.Relative Sort Array/README.md | 10 +- .../1122.Relative Sort Array/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1125.Smallest Sufficient Team/README.md | 10 +- .../README_EN.md | 7 +- .../1126.Active Businesses/README.md | 10 +- .../1126.Active Businesses/README_EN.md | 6 +- .../1127.User Purchase Platform/README.md | 10 +- .../1127.User Purchase Platform/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 12 +- .../1132.Reported Posts II/README.md | 10 +- .../1132.Reported Posts II/README_EN.md | 6 +- .../1133.Largest Unique Number/README.md | 10 +- .../1133.Largest Unique Number/README_EN.md | 7 +- .../1100-1199/1134.Armstrong Number/README.md | 10 +- .../1134.Armstrong Number/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1100-1199/1136.Parallel Courses/README.md | 10 +- .../1136.Parallel Courses/README_EN.md | 7 +- .../1137.N-th Tribonacci Number/README.md | 10 +- .../1137.N-th Tribonacci Number/README_EN.md | 26 +- .../1138.Alphabet Board Path/README.md | 10 +- .../1138.Alphabet Board Path/README_EN.md | 19 +- .../1139.Largest 1-Bordered Square/README.md | 10 +- .../README_EN.md | 24 +- .../1100-1199/1140.Stone Game II/README.md | 10 +- .../1100-1199/1140.Stone Game II/README_EN.md | 26 +- .../README.md | 12 +- .../README_EN.md | 6 +- .../README.md | 12 +- .../README_EN.md | 6 +- .../1143.Longest Common Subsequence/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1145.Binary Tree Coloring Game/README.md | 10 +- .../README_EN.md | 7 +- .../1100-1199/1146.Snapshot Array/README.md | 10 +- .../1146.Snapshot Array/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../1100-1199/1148.Article Views I/README.md | 10 +- .../1148.Article Views I/README_EN.md | 6 +- .../1100-1199/1149.Article Views II/README.md | 10 +- .../1149.Article Views II/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1100-1199/1154.Day of the Year/README.md | 10 +- .../1154.Day of the Year/README_EN.md | 32 +- .../1154.Day of the Year/Solution.js | 18 +- .../README.md | 12 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 44 +- .../1158.Market Analysis I/README.md | 10 +- .../1158.Market Analysis I/README_EN.md | 6 +- .../1159.Market Analysis II/README.md | 10 +- .../1159.Market Analysis II/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 23 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1165.Single-Row Keyboard/README.md | 10 +- .../1165.Single-Row Keyboard/README_EN.md | 7 +- .../1166.Design File System/README.md | 10 +- .../1166.Design File System/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1169.Invalid Transactions/README.md | 10 +- .../1169.Invalid Transactions/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../1172.Dinner Plate Stacks/README.md | 10 +- .../1172.Dinner Plate Stacks/README_EN.md | 7 +- .../1173.Immediate Food Delivery I/README.md | 10 +- .../README_EN.md | 6 +- .../1174.Immediate Food Delivery II/README.md | 10 +- .../README_EN.md | 6 +- .../1175.Prime Arrangements/README.md | 10 +- .../1175.Prime Arrangements/README_EN.md | 7 +- .../1176.Diet Plan Performance/README.md | 10 +- .../1176.Diet Plan Performance/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../1179.Reformat Department Table/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1181.Before and After Puzzle/README.md | 10 +- .../1181.Before and After Puzzle/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1183.Maximum Number of Ones/README.md | 10 +- .../1183.Maximum Number of Ones/README_EN.md | 7 +- .../1184.Distance Between Bus Stops/README.md | 10 +- .../README_EN.md | 28 +- .../1100-1199/1185.Day of the Week/README.md | 10 +- .../1185.Day of the Week/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1189.Maximum Number of Balloons/README.md | 10 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1193.Monthly Transactions I/README.md | 10 +- .../1193.Monthly Transactions I/README_EN.md | 6 +- .../1194.Tournament Winners/README.md | 10 +- .../1194.Tournament Winners/README_EN.md | 6 +- .../1195.Fizz Buzz Multithreaded/README.md | 10 +- .../1195.Fizz Buzz Multithreaded/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1197.Minimum Knight Moves/README.md | 10 +- .../1197.Minimum Knight Moves/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1200-1299/1201.Ugly Number III/README.md | 10 +- .../1201.Ugly Number III/README_EN.md | 7 +- .../1202.Smallest String With Swaps/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1205.Monthly Transactions II/README.md | 12 +- .../1205.Monthly Transactions II/README_EN.md | 6 +- .../1200-1299/1206.Design Skiplist/README.md | 10 +- .../1206.Design Skiplist/README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1200-1299/1214.Two Sum BSTs/README.md | 10 +- .../1200-1299/1214.Two Sum BSTs/README_EN.md | 7 +- .../1200-1299/1215.Stepping Numbers/README.md | 10 +- .../1215.Stepping Numbers/README_EN.md | 7 +- .../1216.Valid Palindrome III/README.md | 10 +- .../1216.Valid Palindrome III/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1219.Path with Maximum Gold/README.md | 10 +- .../1219.Path with Maximum Gold/README_EN.md | 38 +- .../1220.Count Vowels Permutation/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1223.Dice Roll Simulation/README.md | 10 +- .../1223.Dice Roll Simulation/README_EN.md | 7 +- .../1224.Maximum Equal Frequency/README.md | 10 +- .../1224.Maximum Equal Frequency/README_EN.md | 7 +- .../1225.Report Contiguous Dates/README.md | 10 +- .../1225.Report Contiguous Dates/README_EN.md | 6 +- .../1226.The Dining Philosophers/README.md | 10 +- .../1226.The Dining Philosophers/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1229.Meeting Scheduler/README.md | 10 +- .../1229.Meeting Scheduler/README_EN.md | 7 +- .../1230.Toss Strange Coins/README.md | 10 +- .../1230.Toss Strange Coins/README_EN.md | 7 +- .../1200-1299/1231.Divide Chocolate/README.md | 10 +- .../1231.Divide Chocolate/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- solution/1200-1299/1236.Web Crawler/README.md | 10 +- .../1200-1299/1236.Web Crawler/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1242.Web Crawler Multithreaded/README.md | 10 +- .../README_EN.md | 6 +- .../1243.Array Transformation/README.md | 10 +- .../1243.Array Transformation/README_EN.md | 7 +- .../1244.Design A Leaderboard/README.md | 25 +- .../1244.Design A Leaderboard/README_EN.md | 7 +- .../1200-1299/1245.Tree Diameter/README.md | 10 +- .../1200-1299/1245.Tree Diameter/README_EN.md | 7 +- .../1246.Palindrome Removal/README.md | 10 +- .../1246.Palindrome Removal/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1251.Average Selling Price/README.md | 10 +- .../1251.Average Selling Price/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1254.Number of Closed Islands/README.md | 10 +- .../README_EN.md | 25 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1200-1299/1256.Encode Number/README.md | 10 +- .../1200-1299/1256.Encode Number/README_EN.md | 6 +- .../1257.Smallest Common Region/README.md | 10 +- .../1257.Smallest Common Region/README_EN.md | 7 +- .../1258.Synonymous Sentences/README.md | 10 +- .../1258.Synonymous Sentences/README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1200-1299/1260.Shift 2D Grid/README.md | 10 +- .../1200-1299/1260.Shift 2D Grid/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1264.Page Recommendations/README.md | 10 +- .../1264.Page Recommendations/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1268.Search Suggestions System/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 6 +- solution/1200-1299/1271.Hexspeak/README.md | 10 +- solution/1200-1299/1271.Hexspeak/README_EN.md | 7 +- .../1200-1299/1272.Remove Interval/README.md | 10 +- .../1272.Remove Interval/README_EN.md | 7 +- .../1273.Delete Tree Nodes/README.md | 10 +- .../1273.Delete Tree Nodes/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 58 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1280.Students and Examinations/README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1286.Iterator for Combination/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 16 +- .../Solution.js | 20 +- .../1288.Remove Covered Intervals/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 7 +- .../README.md | 12 +- .../README_EN.md | 30 +- .../1291.Sequential Digits/README.md | 10 +- .../1291.Sequential Digits/README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 8 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 32 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 70 +- .../README.md | 10 +- .../README_EN.md | 16 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../1302.Deepest Leaves Sum/README.md | 10 +- .../1302.Deepest Leaves Sum/README_EN.md | 11 +- .../1303.Find the Team Size/README.md | 10 +- .../1303.Find the Team Size/README_EN.md | 6 +- .../README.md | 12 +- .../README_EN.md | 24 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1300-1399/1306.Jump Game III/README.md | 10 +- .../1300-1399/1306.Jump Game III/README_EN.md | 30 +- .../1307.Verbal Arithmetic Puzzle/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../1310.XOR Queries of a Subarray/README.md | 10 +- .../README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1300-1399/1314.Matrix Block Sum/README.md | 10 +- .../1314.Matrix Block Sum/README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 17 +- .../1316.Distinct Echo Substrings/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 42 +- .../README.md | 10 +- .../README_EN.md | 20 +- .../README.md | 10 +- .../README_EN.md | 27 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../1321.Restaurant Growth/README.md | 10 +- .../1321.Restaurant Growth/README_EN.md | 6 +- .../1300-1399/1322.Ads Performance/README.md | 10 +- .../1322.Ads Performance/README_EN.md | 6 +- .../1323.Maximum 69 Number/README.md | 10 +- .../1323.Maximum 69 Number/README_EN.md | 28 +- .../1324.Print Words Vertically/README.md | 10 +- .../1324.Print Words Vertically/README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 33 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../1328.Break a Palindrome/README.md | 10 +- .../1328.Break a Palindrome/README_EN.md | 24 +- .../1329.Sort the Matrix Diagonally/README.md | 10 +- .../README_EN.md | 12 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../1331.Rank Transform of an Array/README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 21 +- .../README.md | 10 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 38 +- .../README.md | 10 +- .../README_EN.md | 31 +- solution/1300-1399/1340.Jump Game V/README.md | 10 +- .../1300-1399/1340.Jump Game V/README_EN.md | 36 +- .../1300-1399/1341.Movie Rating/README.md | 10 +- .../1300-1399/1341.Movie Rating/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 40 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1300-1399/1345.Jump Game IV/README.md | 10 +- .../1300-1399/1345.Jump Game IV/README_EN.md | 48 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1348.Tweet Counts Per Frequency/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1355.Activity Participants/README.md | 10 +- .../1355.Activity Participants/README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 50 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1361.Validate Binary Tree Nodes/README.md | 10 +- .../README_EN.md | 7 +- .../1300-1399/1362.Closest Divisors/README.md | 10 +- .../1362.Closest Divisors/README_EN.md | 7 +- .../1363.Largest Multiple of Three/README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 28 +- .../1366.Rank Teams by Votes/README.md | 10 +- .../1366.Rank Teams by Votes/README_EN.md | 48 +- .../1367.Linked List in Binary Tree/README.md | 10 +- .../README_EN.md | 28 +- .../README.md | 11 +- .../README_EN.md | 8 +- .../README.md | 10 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../README.md | 10 +- .../README_EN.md | 30 +- .../README.md | 10 +- .../README_EN.md | 33 +- .../README.md | 10 +- .../README_EN.md | 26 +- .../1375.Bulb Switcher III/README.md | 10 +- .../1375.Bulb Switcher III/README_EN.md | 7 +- .../README.md | 11 +- .../README_EN.md | 7 +- .../README.md | 10 +- .../README_EN.md | 25 +- .../README.md | 12 +- .../README_EN.md | 6 +- .../README.md | 10 +- .../README_EN.md | 7 +- .../1380.Lucky Numbers in a Matrix/README.md | 9 +- .../README_EN.md | 34 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../README.md | 10 +- .../README_EN.md | 18 +- .../README.md | 10 +- .../README_EN.md | 36 +- .../1384.Total Sales Amount by Year/README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 194 +- .../1386.Cinema Seat Allocation/README.md | 5 +- .../1386.Cinema Seat Allocation/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 229 +- .../1388.Pizza With 3n Slices/README.md | 5 +- .../1388.Pizza With 3n Slices/README_EN.md | 41 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1300-1399/1390.Four Divisors/README.md | 5 +- .../1300-1399/1390.Four Divisors/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 9 +- .../1392.Longest Happy Prefix/README.md | 5 +- .../1392.Longest Happy Prefix/README_EN.md | 8 +- .../1393.Capital Gain/Loss/README.md | 5 +- .../1393.Capital Gain/Loss/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 186 +- .../1395.Count Number of Teams/README.md | 5 +- .../1395.Count Number of Teams/README_EN.md | 169 +- .../1396.Design Underground System/README.md | 5 +- .../README_EN.md | 8 +- .../1397.Find All Good Strings/README.md | 5 +- .../1397.Find All Good Strings/README_EN.md | 8 +- .../README.md | 7 +- .../README_EN.md | 7 +- .../1399.Count Largest Group/README.md | 5 +- .../1399.Count Largest Group/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 198 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1400-1499/1402.Reducing Dishes/README.md | 5 +- .../1402.Reducing Dishes/README_EN.md | 177 +- .../README.md | 5 +- .../README_EN.md | 153 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1405.Longest Happy String/README.md | 5 +- .../1405.Longest Happy String/README_EN.md | 8 +- .../1400-1499/1406.Stone Game III/README.md | 5 +- .../1406.Stone Game III/README_EN.md | 211 +- .../1400-1499/1407.Top Travellers/README.md | 5 +- .../1407.Top Travellers/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 158 +- .../README.md | 5 +- .../README_EN.md | 177 +- .../1410.HTML Entity Parser/README.md | 5 +- .../1410.HTML Entity Parser/README_EN.md | 8 +- .../README.md" | 5 +- .../README_EN.md" | 9 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 174 +- .../README.md | 5 +- .../README_EN.md | 167 +- .../README.md | 5 +- .../README_EN.md | 211 +- .../1416.Restore The Array/README.md | 5 +- .../1416.Restore The Array/README_EN.md | 200 +- .../1417.Reformat The String/README.md | 5 +- .../1417.Reformat The String/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 35 +- solution/1400-1499/1421.NPV Queries/README.md | 5 +- .../1400-1499/1421.NPV Queries/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1424.Diagonal Traverse II/README.md | 5 +- .../1424.Diagonal Traverse II/README_EN.md | 9 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1426.Counting Elements/README.md | 5 +- .../1426.Counting Elements/README_EN.md | 7 +- .../1427.Perform String Shifts/README.md | 5 +- .../1427.Perform String Shifts/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1429.First Unique Number/README.md | 5 +- .../1429.First Unique Number/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 155 +- .../README.md | 5 +- .../README_EN.md | 192 +- .../1435.Create a Session Bar Chart/README.md | 5 +- .../README_EN.md | 7 +- .../1400-1499/1436.Destination City/README.md | 5 +- .../1436.Destination City/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 205 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 29 +- .../1400-1499/1445.Apples & Oranges/README.md | 5 +- .../1445.Apples & Oranges/README_EN.md | 7 +- .../1446.Consecutive Characters/README.md | 5 +- .../1446.Consecutive Characters/README_EN.md | 183 +- .../1447.Simplified Fractions/README.md | 5 +- .../1447.Simplified Fractions/README_EN.md | 153 +- .../README.md | 5 +- .../README_EN.md | 163 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 31 +- .../1400-1499/1454.Active Users/README.md | 7 +- .../1400-1499/1454.Active Users/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 196 +- .../README.md | 5 +- .../README_EN.md | 9 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1400-1499/1459.Rectangles Area/README.md | 5 +- .../1459.Rectangles Area/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1462.Course Schedule IV/README.md | 5 +- .../1462.Course Schedule IV/README_EN.md | 8 +- .../1400-1499/1463.Cherry Pickup II/README.md | 5 +- .../1463.Cherry Pickup II/README_EN.md | 9 +- .../README.md | 5 +- .../README_EN.md | 11 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 7 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1468.Calculate Salaries/README.md | 5 +- .../1468.Calculate Salaries/README_EN.md | 7 +- .../1469.Find All The Lonely Nodes/README.md | 5 +- .../README_EN.md | 7 +- .../1470.Shuffle the Array/README.md | 5 +- .../1470.Shuffle the Array/README_EN.md | 149 +- .../README.md | 5 +- .../README_EN.md | 219 +- .../1472.Design Browser History/README.md | 5 +- .../1472.Design Browser History/README_EN.md | 185 +- .../1400-1499/1473.Paint House III/README.md | 5 +- .../1473.Paint House III/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1476.Subrectangle Queries/README.md | 5 +- .../1476.Subrectangle Queries/README_EN.md | 285 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1478.Allocate Mailboxes/README.md | 5 +- .../1478.Allocate Mailboxes/README_EN.md | 32 +- .../1479.Sales by Day of the Week/README.md | 5 +- .../README_EN.md | 7 +- .../1480.Running Sum of 1d Array/README.md | 5 +- .../1480.Running Sum of 1d Array/README_EN.md | 143 +- .../README.md | 5 +- .../README_EN.md | 134 +- .../README.md | 5 +- .../README_EN.md | 233 +- .../README.md | 6 +- .../README_EN.md | 21 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1486.XOR Operation in an Array/README.md | 5 +- .../README_EN.md | 173 +- .../1487.Making File Names Unique/README.md | 5 +- .../README_EN.md | 223 +- .../1488.Avoid Flood in The City/README.md | 5 +- .../1488.Avoid Flood in The City/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1400-1499/1490.Clone N-ary Tree/README.md | 5 +- .../1490.Clone N-ary Tree/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 178 +- .../1492.The kth Factor of n/README.md | 5 +- .../1492.The kth Factor of n/README_EN.md | 193 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1494.Parallel Courses II/README.md | 5 +- .../1494.Parallel Courses II/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1400-1499/1496.Path Crossing/README.md | 5 +- .../1400-1499/1496.Path Crossing/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1499.Max Value of Equation/README.md | 5 +- .../1499.Max Value of Equation/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 233 +- .../README.md | 5 +- .../README_EN.md | 219 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1506.Find Root of N-Ary Tree/README.md | 5 +- .../1506.Find Root of N-Ary Tree/README_EN.md | 7 +- .../1500-1599/1507.Reformat Date/README.md | 5 +- .../1500-1599/1507.Reformat Date/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 169 +- .../1500-1599/1510.Stone Game IV/README.md | 5 +- .../1500-1599/1510.Stone Game IV/README_EN.md | 8 +- .../1511.Customer Order Frequency/README.md | 5 +- .../README_EN.md | 7 +- .../1512.Number of Good Pairs/README.md | 5 +- .../1512.Number of Good Pairs/README_EN.md | 153 +- .../README.md | 5 +- .../README_EN.md | 179 +- .../README.md | 5 +- .../README_EN.md | 30 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1500-1599/1518.Water Bottles/README.md | 5 +- .../1500-1599/1518.Water Bottles/README_EN.md | 184 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1522.Diameter of N-Ary Tree/README.md | 5 +- .../1522.Diameter of N-Ary Tree/README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 119 +- .../README.md | 5 +- .../README_EN.md | 195 +- .../README.md | 5 +- .../README_EN.md | 181 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1527.Patients With a Condition/README.md | 5 +- .../README_EN.md | 7 +- .../1500-1599/1528.Shuffle String/README.md | 5 +- .../1528.Shuffle String/README_EN.md | 33 +- .../1500-1599/1529.Bulb Switcher IV/README.md | 5 +- .../1529.Bulb Switcher IV/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 35 +- .../1531.String Compression II/README.md | 5 +- .../1531.String Compression II/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1534.Count Good Triplets/README.md | 5 +- .../1534.Count Good Triplets/README_EN.md | 162 +- .../README.md | 5 +- .../README_EN.md | 33 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1537.Get the Maximum Score/README.md | 5 +- .../1537.Get the Maximum Score/README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 138 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../1543.Fix Product Name Format/README.md | 5 +- .../1543.Fix Product Name Format/README_EN.md | 7 +- .../1544.Make The String Great/README.md | 5 +- .../1544.Make The String Great/README_EN.md | 180 +- .../README.md | 5 +- .../README_EN.md | 206 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 31 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../README.md | 5 +- .../README_EN.md | 7 +- .../1550.Three Consecutive Odds/README.md | 5 +- .../1550.Three Consecutive Odds/README_EN.md | 9 +- .../README.md | 5 +- .../README_EN.md | 136 +- .../README.md | 5 +- .../README_EN.md | 8 +- .../README.md | 5 +- .../README_EN.md | 35 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1556.Thousand Separator/README.md | 6 +- .../1556.Thousand Separator/README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 7 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1559.Detect Cycles in 2D Grid/README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 10 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1500-1599/1563.Stone Game V/README.md | 6 +- .../1500-1599/1563.Stone Game V/README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1572.Matrix Diagonal Sum/README.md | 4 +- .../1572.Matrix Diagonal Sum/README_EN.md | 6 +- .../README.md | 4 +- .../README_EN.md | 6 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1575.Count All Possible Routes/README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 4 +- .../README_EN.md | 6 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1583.Count Unhappy Friends/README.md | 6 +- .../1583.Count Unhappy Friends/README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1590.Make Sum Divisible by P/README.md | 6 +- .../1590.Make Sum Divisible by P/README_EN.md | 8 +- .../1591.Strange Printer II/README.md | 6 +- .../1591.Strange Printer II/README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- .../1598.Crawler Log Folder/README.md | 6 +- .../1598.Crawler Log Folder/README_EN.md | 8 +- .../README.md | 6 +- .../README_EN.md | 8 +- solution/README.md | 3201 ++++++++-------- solution/README_EN.md | 3203 ++++++++-------- solution/README_TEMPLATE.md | 5 +- solution/README_TEMPLATE_EN.md | 7 +- solution/summary.md | 3250 ++++++++--------- solution/summary_en.md | 3250 ++++++++--------- summary.md | 6 +- summary_en.md | 6 +- 3656 files changed, 32055 insertions(+), 44820 deletions(-) diff --git a/.docsifytopdfrc.js b/.docsifytopdfrc.js index 9bc14f725dd6a..840480c979fec 100644 --- a/.docsifytopdfrc.js +++ b/.docsifytopdfrc.js @@ -1,7 +1,7 @@ module.exports = { - contents: [ "summary.md" ], - pathToPublic: "pdf/advanced-java.pdf", - pdfOptions: "", - removeTemp: true, - emulateMedia: "screen", -} \ No newline at end of file + contents: ["summary.md"], + pathToPublic: "pdf/advanced-java.pdf", + pdfOptions: "", + removeTemp: true, + emulateMedia: "screen", +}; diff --git a/README.md b/README.md index 93e39756c56dc..ffae4d15e7469 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ ## 加入我们 -刷编程题的最大好处就是可以锻炼解决问题的思维能力。相信我,「如何去思考」​本身也是一项需要不断学习和练习的技能。非常感谢前微软工程师、现蚂蚁金服技术专家 [@kfstorm](https://github.com/kfstorm) 贡献了本项目的所有 [C# 题解](https://github.com/doocs/leetcode/pull/245)。 +刷编程题的最大好处就是可以锻炼解决问题的思维能力。相信我,「如何去思考」​ 本身也是一项需要不断学习和练习的技能。非常感谢前微软工程师、现蚂蚁金服技术专家 [@kfstorm](https://github.com/kfstorm) 贡献了本项目的所有 [C# 题解](https://github.com/doocs/leetcode/pull/245)。 如果你对本项目感兴趣,并且希望加入我们刷题大军,欢迎随时提交 [PR](https://github.com/doocs/leetcode/pulls)。请参考如下步骤: @@ -111,10 +111,10 @@ -> "*You help the developer community practice for interviews, and there is nothing better we could ask for.*" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev) +> "_You help the developer community practice for interviews, and there is nothing better we could ask for._" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev) ## 许可证 知识共享 版权归属-相同方式共享 4.0 国际 公共许可证 -Creative Commons License \ No newline at end of file +Creative Commons License diff --git a/README_EN.md b/README_EN.md index 0725ac66e9ae9..3043f0ecfa29e 100644 --- a/README_EN.md +++ b/README_EN.md @@ -28,8 +28,8 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF ## Solutions 1. [LeetCode](/solution/README_EN.md) -1. [LCOF: *Coding Interviews, 2nd Edition*](/lcof/README_EN.md) -1. [LCCI: *Cracking the Coding Interview, 6th Edition*](/lcci/README_EN.md) +1. [LCOF: _Coding Interviews, 2nd Edition_](/lcof/README_EN.md) +1. [LCCI: _Cracking the Coding Interview, 6th Edition_](/lcci/README_EN.md) ## Basic Algorithms @@ -54,7 +54,6 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF 1. [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md) 1. [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md) - ### Math 1. [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md) @@ -65,7 +64,6 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF ### Misc - ## Maintainer [Yang Libin](https://github.com/yanglbme): Creator of [@Doocs](https://github.com/doocs) technical community; member of [@TheAlgorithms](https://github.com/TheAlgorithms) organization. @@ -89,7 +87,7 @@ You can also contribute to [doocs/leetcode](https://github.com/doocs/leetcode) u ## Contributors -This project exists thanks to all the people who contribute. +This project exists thanks to all the people who contribute. @@ -101,11 +99,10 @@ Thank you to all our backers and sponsors! - -> "*You help the developer community practice for interviews, and there is nothing better we could ask for.*" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev) +> "_You help the developer community practice for interviews, and there is nothing better we could ask for._" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev) ## License This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. -Creative Commons License \ No newline at end of file +Creative Commons License diff --git a/basic/README.md b/basic/README.md index 79ee9be29acc5..8c967d74817e9 100644 --- a/basic/README.md +++ b/basic/README.md @@ -5,4 +5,4 @@ - [冒泡排序](./sorting/BubbleSort/README.md) - [插入排序](./sorting/InsertionSort/README.md) - [归并排序](./sorting/MergeSort/README.md) -- [快速排序](./sorting/QuickSort/README.md) \ No newline at end of file +- [快速排序](./sorting/QuickSort/README.md) diff --git a/basic/README_EN.md b/basic/README_EN.md index 21374108453f2..4a0a0af8a1d68 100644 --- a/basic/README_EN.md +++ b/basic/README_EN.md @@ -5,4 +5,4 @@ - [Bubble Sort](./sorting/BubbleSort/README.md) - [Insertion Sort](./sorting/InsertionSort/README.md) - [Merge Sort](./sorting/MergeSort/README.md) -- [Quick Sort](./sorting/QuickSort/README.md) \ No newline at end of file +- [Quick Sort](./sorting/QuickSort/README.md) diff --git a/basic/sorting/BubbleSort/README.md b/basic/sorting/BubbleSort/README.md index 72023f532e83a..3208134ce91a8 100644 --- a/basic/sorting/BubbleSort/README.md +++ b/basic/sorting/BubbleSort/README.md @@ -58,4 +58,4 @@ public class BubbleSort { 因此,时间复杂度是 O(n²),这是一种稳定的排序算法。 -> 稳定是指,两个相等的数,在排序过后,相对位置保持不变。 \ No newline at end of file +> 稳定是指,两个相等的数,在排序过后,相对位置保持不变。 diff --git a/basic/sorting/MergeSort/README.md b/basic/sorting/MergeSort/README.md index d7a739bd895b5..5c826b9d3796c 100644 --- a/basic/sorting/MergeSort/README.md +++ b/basic/sorting/MergeSort/README.md @@ -70,4 +70,4 @@ public class MergeSort { 由于合并 n 个元素需要分配一个大小为 n 的额外数组,所以空间复杂度为 O(n)。 -这是一种稳定的排序算法。 \ No newline at end of file +这是一种稳定的排序算法。 diff --git a/basic/sorting/QuickSort/README.md b/basic/sorting/QuickSort/README.md index 11b282271d4be..ba9ac23ef297f 100644 --- a/basic/sorting/QuickSort/README.md +++ b/basic/sorting/QuickSort/README.md @@ -1,4 +1,3 @@ - # 快速排序 快速排序也采用了分治的思想:把原始的数组筛选成较小和较大的两个子数组,然后递归地排序两个子数组。 @@ -68,4 +67,4 @@ public class QuickSort { 但是,如果每次在选择基准值的时候,都不幸地选择了子数组里的最大或最小值。即每次把把数组分成了两个更小长度的数组,其中一个长度为 1,另一个的长度是子数组的长度减 1。这样的算法复杂度变成 O(n²)。 -和归并排序不同,快速排序在每次递归的过程中,只需要开辟 O(1) 的存储空间来完成操作来实现对数组的修改;而递归次数为 logn,所以它的整体空间复杂度完全取决于压堆栈的次数。 \ No newline at end of file +和归并排序不同,快速排序在每次递归的过程中,只需要开辟 O(1) 的存储空间来完成操作来实现对数组的修改;而递归次数为 logn,所以它的整体空间复杂度完全取决于压堆栈的次数。 diff --git a/basic/summary.md b/basic/summary.md index ed536e82a946a..89d5ed56be31c 100644 --- a/basic/summary.md +++ b/basic/summary.md @@ -1,6 +1,6 @@ - 基础算法通关 - - 常见的排序算法 - - [冒泡排序](/basic/sorting/BubbleSort/README.md) - - [插入排序](/basic/sorting/InsertionSort/README.md) - - [归并排序](/basic/sorting/MergeSort/README.md) - - [快速排序](/basic/sorting/QuickSort/README.md) \ No newline at end of file + - 常见的排序算法 + - [冒泡排序](/basic/sorting/BubbleSort/README.md) + - [插入排序](/basic/sorting/InsertionSort/README.md) + - [归并排序](/basic/sorting/MergeSort/README.md) + - [快速排序](/basic/sorting/QuickSort/README.md) diff --git a/lcci/01.01.Is Unique/README.md b/lcci/01.01.Is Unique/README.md index 19664d7699e6d..3bf28d5b80943 100644 --- a/lcci/01.01.Is Unique/README.md +++ b/lcci/01.01.Is Unique/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.01.Is%20Unique/README_EN.md) ## 题目描述 +

实现一个算法,确定一个字符串 s 的所有字符是否全都不同。

@@ -23,15 +24,16 @@
  • 0 <= len(s) <= 100
  • 如果你不使用额外的数据结构,会很加分。
  • - + ## 解法 - + ### **Python3** + ```python @@ -42,6 +44,7 @@ class Solution: ``` ### **Java** + ```java @@ -62,8 +65,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.01.Is Unique/README_EN.md b/lcci/01.01.Is Unique/README_EN.md index 7fb79fcbd0fbd..23ad69d0c0f8f 100644 --- a/lcci/01.01.Is Unique/README_EN.md +++ b/lcci/01.01.Is Unique/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/lcci/01.01.Is%20Unique/README.md) ## Description +

    Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

    Example 1:

    @@ -31,12 +32,8 @@
  • 0 <= len(s) <= 100
  • - - - ## Solutions - ### **Python3** @@ -68,8 +65,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.02.Check Permutation/README.md b/lcci/01.02.Check Permutation/README.md index 998e1702d9eeb..f414e1a7ca8b8 100644 --- a/lcci/01.02.Check Permutation/README.md +++ b/lcci/01.02.Check Permutation/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.02.Check%20Permutation/README_EN.md) ## 题目描述 +

    给定两个字符串 s1s2,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。

    @@ -25,14 +26,14 @@
  • 0 <= len(s2) <= 100
  • - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ class Solution: ``` ### **Java** + ```java @@ -60,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.02.Check Permutation/README_EN.md b/lcci/01.02.Check Permutation/README_EN.md index fdd14e5e47a0a..b02a0a737fbdc 100644 --- a/lcci/01.02.Check Permutation/README_EN.md +++ b/lcci/01.02.Check Permutation/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/01.02.Check%20Permutation/README.md) ## Description -

    Given two strings,write a method to decide if one is a permutation of the other.

    - +

    Given two strings,write a method to decide if one is a permutation of the other.

    Example 1:

    - -
     
     Input: s1 = "abc", s2 = "bca"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: s1 = "abc", s2 = "bad"
    @@ -33,20 +26,14 @@
     
     
    - -

    Note:

    1. 0 <= len(s1) <= 100
    2. 0 <= len(s2) <= 100
    - - - ## Solutions - ### **Python3** @@ -75,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.03.String to URL/README.md b/lcci/01.03.String to URL/README.md index 34904733fbc63..63b5f66b1ff66 100644 --- a/lcci/01.03.String to URL/README.md +++ b/lcci/01.03.String to URL/README.md @@ -1,8 +1,9 @@ -# [面试题 01.03. URL化](https://leetcode-cn.com/problems/string-to-url-lcci) +# [面试题 01.03. URL 化](https://leetcode-cn.com/problems/string-to-url-lcci) [English Version](/lcci/01.03.String%20to%20URL/README_EN.md) ## 题目描述 +

    URL化。编写一种方法,将字符串中的空格全部替换为%20。假定该字符串尾部有足够的空间存放新增字符,并且知道字符串的“真实”长度。(注:用Java实现的话,请使用字符数组实现,以便直接在数组上操作。)

    @@ -24,14 +25,14 @@
  • 字符串长度在[0, 500000]范围内。
  • - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ class Solution: ``` ### **Java** + ```java @@ -64,8 +66,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.03.String to URL/README_EN.md b/lcci/01.03.String to URL/README_EN.md index 06dbca06e77e2..b5fb2000c453f 100644 --- a/lcci/01.03.String to URL/README_EN.md +++ b/lcci/01.03.String to URL/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/01.03.String%20to%20URL/README.md) ## Description -

    Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)

    - +

    Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)

    Example 1:

    - -
     
     Input: "Mr John Smith ", 13
    @@ -23,12 +20,8 @@ The missing numbers are [5,6,8,...], hence the third missing number is 8.
     
     
    - -

    Example 2:

    - -
     
     Input: "               ", 5
    @@ -37,26 +30,16 @@ The missing numbers are [5,6,8,...], hence the third missing number is 8.
     
     
    - -

     

    - -

    Note:

    - -
    1. 0 <= S.length <= 500000
    - - - ## Solutions - ### **Python3** @@ -90,8 +73,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.04.Palindrome Permutation/README.md b/lcci/01.04.Palindrome Permutation/README.md index 5e2166f976fa0..0e297d35bdd99 100644 --- a/lcci/01.04.Palindrome Permutation/README.md +++ b/lcci/01.04.Palindrome Permutation/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.04.Palindrome%20Permutation/README_EN.md) ## 题目描述 +

    给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一。

    @@ -20,14 +21,16 @@

     

    - ## 解法 + + 用哈希表存储每个字符出现的次数。若次数为奇数的字符超过 1 个,则不是回文排列。 ### **Python3** + ```python @@ -48,6 +51,7 @@ class Solution: ``` ### **Java** + ```java @@ -76,8 +80,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.04.Palindrome Permutation/README_EN.md b/lcci/01.04.Palindrome Permutation/README_EN.md index eda93b701a8f4..f1d8489ca5a54 100644 --- a/lcci/01.04.Palindrome Permutation/README_EN.md +++ b/lcci/01.04.Palindrome Permutation/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/01.04.Palindrome%20Permutation/README.md) ## Description -

    Given a string, write a function to check if it is a permutation of a palin­ drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.

    - +

    Given a string, write a function to check if it is a permutation of a palin­ drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.

     

    - -

    Example1:

    - -
     
     Input: "tactcoa"
    @@ -25,7 +20,6 @@
     
     ## Solutions
     
    -
     
     
     ### **Python3**
    @@ -75,8 +69,9 @@ class Solution {
     ```
     
     ### **...**
    +
     ```
     
     ```
     
    -
    \ No newline at end of file
    +
    diff --git a/lcci/01.05.One Away/README.md b/lcci/01.05.One Away/README.md
    index 9dcf342160089..1dbca070bef9e 100644
    --- a/lcci/01.05.One Away/README.md	
    +++ b/lcci/01.05.One Away/README.md	
    @@ -3,6 +3,7 @@
     [English Version](/lcci/01.05.One%20Away/README_EN.md)
     
     ## 题目描述
    +
     
     

    字符串有三种编辑操作:插入一个字符、删除一个字符或者替换一个字符。 给定两个字符串,编写一个函数判定它们是否只需要一次(或者零次)编辑。

    @@ -25,14 +26,16 @@ second = "pal" 输出: False
    - ## 解法 + + 遍历两个字符串,逐个字符比较判断。 ### **Python3** + ```python @@ -53,6 +56,7 @@ class Solution: ``` ### **Java** + ```java @@ -80,8 +84,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.05.One Away/README_EN.md b/lcci/01.05.One Away/README_EN.md index 106e77685a38a..719353deadaea 100644 --- a/lcci/01.05.One Away/README_EN.md +++ b/lcci/01.05.One Away/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/lcci/01.05.One%20Away/README.md) ## Description +

    There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.

    Example 1:

    @@ -21,8 +22,6 @@ second = "ple"

    Example 2:

    - -
     
     Input: 
    @@ -35,12 +34,8 @@ second = "pal"
     
     
    - - - ## Solutions - ### **Python3** @@ -89,8 +84,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.06.Compress String/README.md b/lcci/01.06.Compress String/README.md index 1fb3207314bd6..a4705a433d59b 100644 --- a/lcci/01.06.Compress String/README.md +++ b/lcci/01.06.Compress String/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.06.Compress%20String/README_EN.md) ## 题目描述 +

    字符串压缩。利用字符重复出现的次数,编写一种方法,实现基本的字符串压缩功能。比如,字符串aabcccccaaa会变为a2b1c5a3。若“压缩”后的字符串没有变短,则返回原先的字符串。你可以假设字符串中只包含大小写英文字母(a至z)。

    @@ -27,14 +28,16 @@
  • 字符串长度在[0, 50000]范围内。
  • - ## 解法 + + 双指针遍历字符串求解。 ### **Python3** + ```python @@ -54,6 +57,7 @@ class Solution: ``` ### **Java** + ```java @@ -80,8 +84,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.06.Compress String/README_EN.md b/lcci/01.06.Compress String/README_EN.md index c85ad0c6537d3..5021260912e05 100644 --- a/lcci/01.06.Compress String/README_EN.md +++ b/lcci/01.06.Compress String/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/lcci/01.06.Compress%20String/README.md) ## Description -

    Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z).

    - +

    Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z).

    Example 1:

    @@ -17,12 +16,8 @@ - -

    Example 2:

    - -
     
     Input: "abbccd"
    @@ -39,11 +34,8 @@ The compressed string is "a1b2c2d1", which is longer than the original
     
     - `0 <= S.length <= 50000`
     
    -
    -
     ## Solutions
     
    -
     
     
     ### **Python3**
    @@ -90,8 +82,9 @@ class Solution {
     ```
     
     ### **...**
    +
     ```
     
     ```
     
    -
    \ No newline at end of file
    +
    diff --git a/lcci/01.07.Rotate Matrix/README.md b/lcci/01.07.Rotate Matrix/README.md
    index 5e4ac01c15358..54dd01dd0435c 100644
    --- a/lcci/01.07.Rotate Matrix/README.md	
    +++ b/lcci/01.07.Rotate Matrix/README.md	
    @@ -3,6 +3,7 @@
     [English Version](/lcci/01.07.Rotate%20Matrix/README_EN.md)
     
     ## 题目描述
    +
     
     

    给定一幅由N × N矩阵表示的图像,其中每个像素的大小为4字节,编写一种方法,将图像旋转90度。

    @@ -46,8 +47,8 @@ ]
    - ## 解法 + 原地旋转,i 的范围是 `[0, n/2)`,j 的范围是 `[i, n-1-i)`。 @@ -55,6 +56,7 @@ ### **Python3** + ```python @@ -75,6 +77,7 @@ class Solution: ``` ### **Java** + ```java @@ -95,8 +98,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.07.Rotate Matrix/README_EN.md b/lcci/01.07.Rotate Matrix/README_EN.md index 0332491567b97..82932f7f9867f 100644 --- a/lcci/01.07.Rotate Matrix/README_EN.md +++ b/lcci/01.07.Rotate Matrix/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/01.07.Rotate%20Matrix/README.md) ## Description -

    Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?

    - +

    Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?

     

    - -

    Example 1:

    - -
     
     Given matrix = 
    @@ -45,12 +40,8 @@ Rotate the matrix in place. It becomes:
     
     
    - -

    Example 2:

    - -
     
     Given matrix =
    @@ -85,12 +76,8 @@ Rotate the matrix in place. It becomes:
     
     
    - - - ## Solutions - ### **Python3** @@ -132,8 +119,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.08.Zero Matrix/README.md b/lcci/01.08.Zero Matrix/README.md index f62ee752dc9dc..3cef9fd644bf6 100644 --- a/lcci/01.08.Zero Matrix/README.md +++ b/lcci/01.08.Zero Matrix/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.08.Zero%20Matrix/README_EN.md) ## 题目描述 +

    编写一种算法,若M × N矩阵中某个元素为0,则将其所在的行与列清零。

    @@ -40,8 +41,8 @@ ] - ## 解法 + 用 set 记录需要清零的行 `zero_rows` 跟列 `zero_cols`,之后分别将需要清零的行、列上的所有元素清零。 @@ -49,6 +50,7 @@ ### **Python3** + ```python @@ -64,22 +66,23 @@ class Solution: if matrix[i][j] == 0: zero_rows.add(i) zero_cols.add(j) - + # 行清零 for i in zero_rows: for j in range(cols): matrix[i][j] = 0 - + # 列清零 for j in zero_cols: for i in range(rows): matrix[i][j] = 0 - + return matrix ``` ### **Java** + ```java @@ -115,8 +118,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.08.Zero Matrix/README_EN.md b/lcci/01.08.Zero Matrix/README_EN.md index 8906211c92db3..a1585a7f731aa 100644 --- a/lcci/01.08.Zero Matrix/README_EN.md +++ b/lcci/01.08.Zero Matrix/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/01.08.Zero%20Matrix/README.md) ## Description -

    Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.

    - +

    Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.

     

    - -

    Example 1:

    - -
     
     Input: 
    @@ -43,12 +38,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 
    @@ -77,12 +68,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -100,15 +87,15 @@ class Solution: if matrix[i][j] == 0: zero_rows.add(i) zero_cols.add(j) - + for i in zero_rows: for j in range(cols): matrix[i][j] = 0 - + for j in zero_cols: for i in range(rows): matrix[i][j] = 0 - + return matrix ``` @@ -146,8 +133,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.09.String Rotation/README.md b/lcci/01.09.String Rotation/README.md index da482b56ac57e..cfc517474fe86 100644 --- a/lcci/01.09.String Rotation/README.md +++ b/lcci/01.09.String Rotation/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/01.09.String%20Rotation/README_EN.md) ## 题目描述 +

    字符串轮转。给定两个字符串s1s2,请编写代码检查s2是否为s1旋转而成(比如,waterbottleerbottlewat旋转后的字符串)。

    @@ -33,8 +34,8 @@
  • 你能只调用一次检查子串的方法吗?
  • - ## 解法 + @@ -48,6 +49,7 @@ class Solution: ``` ### **Java** + ```java @@ -59,8 +61,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/01.09.String Rotation/README_EN.md b/lcci/01.09.String Rotation/README_EN.md index 79a4e66fe0135..331cac4234784 100644 --- a/lcci/01.09.String Rotation/README_EN.md +++ b/lcci/01.09.String Rotation/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/01.09.String%20Rotation/README.md) ## Description -

    Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?

    - +

    Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?

    Example 1:

    - -
     
     Input: s1 = "waterbottle", s2 = "erbottlewat"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: s1 = "aa", "aba"
    @@ -33,23 +26,14 @@
     
     
    - -

     

    - -

    Note:

    - -
    1. 0 <= s1.length, s1.length <= 100000
    - - - ## Solutions @@ -73,8 +57,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.01.Remove Duplicate Node/README.md b/lcci/02.01.Remove Duplicate Node/README.md index 78767407357db..159a271a25dd2 100644 --- a/lcci/02.01.Remove Duplicate Node/README.md +++ b/lcci/02.01.Remove Duplicate Node/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) ## 题目描述 +

    编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。

    @@ -31,14 +32,14 @@

    如果不得使用临时缓冲区,该怎么解决?

    - ## 解法 - + ### **Python3** + ```python @@ -66,6 +67,7 @@ class Solution: ``` ### **Java** + ```java @@ -101,8 +103,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.01.Remove Duplicate Node/README_EN.md b/lcci/02.01.Remove Duplicate Node/README_EN.md index b96f53871f779..1e86e25aa4ce8 100644 --- a/lcci/02.01.Remove Duplicate Node/README_EN.md +++ b/lcci/02.01.Remove Duplicate Node/README_EN.md @@ -3,11 +3,11 @@ [中文文档](/lcci/02.01.Remove%20Duplicate%20Node/README.md) ## Description +

    Write code to remove duplicates from an unsorted linked list.

    Example1:

    -
     
      Input: [1, 2, 3, 3, 2, 1]
    @@ -16,7 +16,6 @@
     
     
    -

    Example2:

    @@ -32,23 +31,16 @@
     
    1. The length of the list is within the range[0, 20000].
    2. -
    3. The values of the list elements are within the range [0, 20000].
    4. -
    - +
  • The values of the list elements are within the range [0, 20000].
  • +

    Follow Up:

    - -

    How would you solve this problem if a temporary buffer is not allowed?

    - - - ## Solutions - ### **Python3** @@ -112,8 +104,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.02.Kth Node From End of List/README.md b/lcci/02.02.Kth Node From End of List/README.md index cf2db402fe09f..abc4722c9aba6 100644 --- a/lcci/02.02.Kth Node From End of List/README.md +++ b/lcci/02.02.Kth Node From End of List/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) ## 题目描述 +

    实现一种算法,找出单向链表中倒数第 k 个节点。返回该节点的值。

    @@ -17,18 +18,18 @@

    给定的 k 保证是有效的。

    - ## 解法 + 定义 `p`、`q` 指针指向 `head`。 `p` 先向前走 `k` 步,接着 `p`、`q` 同时向前走,当 `p` 指向 `null` 时,`q` 指向的节点即为链表的倒数第 `k` 个节点。 - ### **Python3** + ```python @@ -49,6 +50,7 @@ class Solution: ``` ### **Java** + ```java @@ -76,8 +78,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.02.Kth Node From End of List/README_EN.md b/lcci/02.02.Kth Node From End of List/README_EN.md index 55686d61ea96b..464e16741d508 100644 --- a/lcci/02.02.Kth Node From End of List/README_EN.md +++ b/lcci/02.02.Kth Node From End of List/README_EN.md @@ -3,34 +3,25 @@ [中文文档](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) ## Description -

    Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element.

    - +

    Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element.

    Note: This problem is slightly different from the original one in the book.

    - -

    Example:

    - -
     
     Input:  1->2->3->4->5 和 k = 2
     
     Output:  4
    - -

    Note:

    k is always valid.

    - ## Solutions - ### **Python3** @@ -79,8 +70,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.03.Delete Middle Node/README.md b/lcci/02.03.Delete Middle Node/README.md index 65713efb2596f..55c35c3498679 100644 --- a/lcci/02.03.Delete Middle Node/README.md +++ b/lcci/02.03.Delete Middle Node/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) ## 题目描述 +

    实现一种算法,删除单向链表中间的某个节点(除了第一个和最后一个节点,不一定是中间节点),假定你只能访问该节点。

    @@ -15,14 +16,16 @@ 结果:不返回任何数据,但该链表变为a->b->d->e->f
    - ## 解法 + + 把 node 的下一个节点的值赋给 node,然后改变 node 的 next 指向。 ### **Python3** + ```python @@ -43,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -63,8 +67,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.03.Delete Middle Node/README_EN.md b/lcci/02.03.Delete Middle Node/README_EN.md index 566df34654de6..5b34c7d6518d8 100644 --- a/lcci/02.03.Delete Middle Node/README_EN.md +++ b/lcci/02.03.Delete Middle Node/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/02.03.Delete%20Middle%20Node/README.md) ## Description -

    Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node.

    - +

    Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node.

     

    - -

    Example:

    - -
     
     Input: the node c from the linked list a->b->c->d->e->f
    @@ -23,12 +18,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -70,8 +61,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.04.Partition List/README.md b/lcci/02.04.Partition List/README.md index 21a432be4fb2f..d0f07d23e3563 100644 --- a/lcci/02.04.Partition List/README.md +++ b/lcci/02.04.Partition List/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.04.Partition%20List/README_EN.md) ## 题目描述 +

    编写程序以 x 为基准分割链表,使得所有小于 x 的节点排在大于或等于 x 的节点之前。如果链表中包含 x,x 只需出现在小于 x 的元素之后(如下所示)。分割元素 x 只需处于“右半部分”即可,其不需要被置于左右两部分之间。

    @@ -12,14 +13,16 @@ 输出: 3->1->2->10->5->5->8 - ## 解法 + + 创建两个链表,一个存放小于 `x` 的节点,另一个存放大于等于 `x` 的节点,之后进行拼接即可。 ### **Python3** + ```python @@ -50,6 +53,7 @@ class Solution: ``` ### **Java** + ```java @@ -88,8 +92,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.04.Partition List/README_EN.md b/lcci/02.04.Partition List/README_EN.md index 5d6a566bc2813..b31db0fe31508 100644 --- a/lcci/02.04.Partition List/README_EN.md +++ b/lcci/02.04.Partition List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/02.04.Partition%20List/README.md) ## Description -

    Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the "right partition"; it does not need to appear between the left and right partitions.

    - +

    Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the "right partition"; it does not need to appear between the left and right partitions.

    Example:

    - -
     
     Input: head = 3->5->8->5->10->2->1, x = 5
    @@ -19,12 +16,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -94,8 +87,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.05.Sum Lists/README.md b/lcci/02.05.Sum Lists/README.md index 7064615920ee7..c56235b02ede9 100644 --- a/lcci/02.05.Sum Lists/README.md +++ b/lcci/02.05.Sum Lists/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.05.Sum%20Lists/README_EN.md) ## 题目描述 +

    给定两个用链表表示的整数,每个节点包含一个数位。

    这些数位是反向存放的,也就是个位排在链表首部。

    @@ -26,14 +27,16 @@ 输出:9 -> 1 -> 2,即912 - ## 解法 + + 同时遍历两链表,求节点的和与进位。 ### **Python3** + ```python @@ -61,6 +64,7 @@ class Solution: ``` ### **Java** + ```java @@ -92,8 +96,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.05.Sum Lists/README_EN.md b/lcci/02.05.Sum Lists/README_EN.md index 2df012bbb587a..61b5c8450bcc4 100644 --- a/lcci/02.05.Sum Lists/README_EN.md +++ b/lcci/02.05.Sum Lists/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/02.05.Sum%20Lists/README.md) ## Description -

    You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.

    - +

    You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.

     

    - -

    Example:

    - -
     
     Input: (7 -> 1 -> 6) + (5 -> 9 -> 2). That is, 617 + 295.
    @@ -23,16 +18,10 @@
     
     
    - -

    Follow Up: Suppose the digits are stored in forward order. Repeat the above problem.

    - -

    Example:

    - -
     
     Input: (6 -> 1 -> 7) + (2 -> 9 -> 5). That is, 617 + 295.
    @@ -41,12 +30,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -106,8 +91,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.06.Palindrome Linked List/README.md b/lcci/02.06.Palindrome Linked List/README.md index e1d3ef4b24ee3..9f342000a6f34 100644 --- a/lcci/02.06.Palindrome Linked List/README.md +++ b/lcci/02.06.Palindrome Linked List/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) ## 题目描述 +

    编写一个函数,检查输入的链表是否是回文的。

    @@ -25,14 +26,16 @@

    进阶:
    你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?

    - ## 解法 + + 先利用快慢指针找到链表中点,之后将后半部分链表利用头插法逆序,再比对前后两段链表得出结果。 ### **Python3** + ```python @@ -67,6 +70,7 @@ class Solution: ``` ### **Java** + ```java @@ -110,8 +114,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.06.Palindrome Linked List/README_EN.md b/lcci/02.06.Palindrome Linked List/README_EN.md index fc584bcb25a81..257f2a1635fa8 100644 --- a/lcci/02.06.Palindrome Linked List/README_EN.md +++ b/lcci/02.06.Palindrome Linked List/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/02.06.Palindrome%20Linked%20List/README.md) ## Description -

    Implement a function to check if a linked list is a palindrome.

    - +

    Implement a function to check if a linked list is a palindrome.

     

    - -

    Example 1:

    - -
     
     Input:  1->2
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:  1->2->2->1
    @@ -37,19 +28,14 @@
     
     
    - -

     

    - -

    Follow up:
    Could you do it in O(n) time and O(1) space?

    ## Solutions - ### **Python3** @@ -128,8 +114,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.07.Intersection of Two Linked Lists/README.md b/lcci/02.07.Intersection of Two Linked Lists/README.md index e59ed8c191153..f65c237ba6975 100644 --- a/lcci/02.07.Intersection of Two Linked Lists/README.md +++ b/lcci/02.07.Intersection of Two Linked Lists/README.md @@ -3,16 +3,20 @@ [English Version](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) ## 题目描述 +

    给定两个(单向)链表,判定它们是否相交并返回交点。请注意相交的定义基于节点的引用,而不是基于节点的值。换句话说,如果一个链表的第k个节点与另一个链表的第j个节点是同一节点(引用完全相同),则这两个链表相交。


    示例 1:

    输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
    输出:Reference of the node with value = 8
    输入解释:相交节点的值为 8 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。


    示例 2:

    输入:intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
    输出:Reference of the node with value = 2
    输入解释:相交节点的值为 2 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。


    示例 3:

    输入:intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
    输出:null
    输入解释:从各自的表头开始算起,链表 A 为 [2,6,4],链表 B 为 [1,5]。由于这两个链表不相交,所以 intersectVal 必须为 0,而 skipA 和 skipB 可以是任意值。
    解释:这两个链表不相交,因此返回 null。


    注意:

    • 如果两个链表没有交点,返回 null
    • 在返回结果后,两个链表仍须保持原有的结构。
    • 可假定整个链表结构中没有循环。
    • 程序尽量满足 O(n) 时间复杂度,且仅用 O(1) 内存。
    ## 解法 + + 先求两链表的长度差 `differ`,接着较长的链表先走 `differ` 步,之后两链表同时走,若相遇,则说明相交。 ### **Python3** + ```python @@ -46,6 +50,7 @@ class Solution: ``` ### **Java** + ```java @@ -94,8 +99,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.07.Intersection of Two Linked Lists/README_EN.md b/lcci/02.07.Intersection of Two Linked Lists/README_EN.md index ef10a33ea3d05..5ab9fbfd0b213 100644 --- a/lcci/02.07.Intersection of Two Linked Lists/README_EN.md +++ b/lcci/02.07.Intersection of Two Linked Lists/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README.md) ## Description -

    Given two (singly) linked lists, determine if the two lists intersect. Return the inter­ secting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.

    - +

    Given two (singly) linked lists, determine if the two lists intersect. Return the inter­ secting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.

    Example 1:

    - -
     
     Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
    @@ -19,12 +16,8 @@
     
     Input Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.
    - -

    Example 2:

    - -
     
     Input: intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
    @@ -33,12 +26,8 @@
     
     Input Explanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [0,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.
    - -

    Example 3:

    - -
     
     Input: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
    @@ -49,7 +38,6 @@
     
     Explanation: The two lists do not intersect, so return null.
    -

    Notes:

    - If the two linked lists have no intersection at all, return null. @@ -59,7 +47,6 @@ ## Solutions - ### **Python3** @@ -142,8 +129,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.08.Linked List Cycle/README.md b/lcci/02.08.Linked List Cycle/README.md index c029407e05d41..2e04e7dfb0ea5 100644 --- a/lcci/02.08.Linked List Cycle/README.md +++ b/lcci/02.08.Linked List Cycle/README.md @@ -3,16 +3,18 @@ [English Version](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) ## 题目描述 +

    给定一个有环链表,实现一个算法返回环路的开头节点。
    有环链表的定义:在链表中某个节点的next元素指向在它前面出现过的节点,则表明该链表存在环路。


    示例 1:

    输入:head = [3,2,0,-4], pos = 1
    输出:tail connects to node index 1
    解释:链表中有一个环,其尾部连接到第二个节点。


    示例 2:

    输入:head = [1,2], pos = 0
    输出:tail connects to node index 0
    解释:链表中有一个环,其尾部连接到第一个节点。


    示例 3:

    输入:head = [1], pos = -1
    输出:no cycle
    解释:链表中没有环。


    进阶:
    你是否可以不用额外空间解决此题?

    ## 解法 - + ### **Python3** + ```python @@ -39,6 +41,7 @@ class Solution: ``` ### **Java** + ```java @@ -73,8 +76,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/02.08.Linked List Cycle/README_EN.md b/lcci/02.08.Linked List Cycle/README_EN.md index 98e4532f9c6cb..d47d506ab5bc1 100644 --- a/lcci/02.08.Linked List Cycle/README_EN.md +++ b/lcci/02.08.Linked List Cycle/README_EN.md @@ -3,60 +3,41 @@ [中文文档](/lcci/02.08.Linked%20List%20Cycle/README.md) ## Description -

    Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop.

    - +

    Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop.

    Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node, so as to make a loop in the linked list.

    - -

    Example 1:

    - -
     
     Input: head = [3,2,0,-4], pos = 1
     
     Output: tail connects to node index 1
    - -

    Example 2:

    - -
     
     Input: head = [1,2], pos = 0
     
     Output: tail connects to node index 0
    - -

    Example 3:

    - -
     
     Input: head = [1], pos = -1
     
     Output: no cycle
    - -

    Follow Up:
    Can you solve it without using additional space?

    - - - ## Solutions - ### **Python3** @@ -118,8 +99,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.01.Three in One/README.md b/lcci/03.01.Three in One/README.md index 7e01c67d7bce1..7d70d1fd5efa8 100644 --- a/lcci/03.01.Three in One/README.md +++ b/lcci/03.01.Three in One/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.01.Three%20in%20One/README_EN.md) ## 题目描述 +

    三合一。描述如何只用一个数组来实现三个栈。

    @@ -29,14 +30,16 @@ [null, null, null, null, 2, 1, -1, -1] - ## 解法 + + 二维数组解决;也可以使用一维数组,以下标 `0,3,6,..`、`1,4,7,..`、`2,5,8,..` 区分,一维数组最后三个元素记录每个栈的元素个数。 ### **Python3** + ```python @@ -69,6 +72,7 @@ class TripleInOne: ``` ### **Java** + ```java @@ -80,14 +84,14 @@ class TripleInOne { s = new int[stackSize * 3 + 3]; capacity = stackSize; } - + public void push(int stackNum, int value) { if (s[stackNum + 3 * capacity] < capacity) { s[s[stackNum + 3 * capacity] * 3 + stackNum] = value; ++s[stackNum + 3 * capacity]; } } - + public int pop(int stackNum) { if (isEmpty(stackNum)) { return -1; @@ -95,11 +99,11 @@ class TripleInOne { --s[stackNum + 3 * capacity]; return s[s[stackNum + 3 * capacity] * 3 + stackNum]; } - + public int peek(int stackNum) { return isEmpty(stackNum) ? -1 : s[(s[stackNum + 3 * capacity] - 1) * 3 + stackNum]; } - + public boolean isEmpty(int stackNum) { return s[stackNum + 3 * capacity] == 0; } @@ -116,8 +120,9 @@ class TripleInOne { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.01.Three in One/README_EN.md b/lcci/03.01.Three in One/README_EN.md index 2d77e29430e94..40ded4afb328f 100644 --- a/lcci/03.01.Three in One/README_EN.md +++ b/lcci/03.01.Three in One/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/03.01.Three%20in%20One/README.md) ## Description -

    Describe how you could use a single array to implement three stacks.

    - +

    Describe how you could use a single array to implement three stacks.

    Yout should implement push(stackNum, value)pop(stackNum)isEmpty(stackNum)peek(stackNum) methods. stackNum is the index of the stack. value is the value that pushed to the stack.

    - -

    The constructor requires a stackSize parameter, which represents the size of each stack.

    - -

    Example1:

    - -
     
      Input: 
    @@ -35,12 +28,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: 
    @@ -55,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -105,14 +90,14 @@ class TripleInOne { s = new int[stackSize * 3 + 3]; capacity = stackSize; } - + public void push(int stackNum, int value) { if (s[stackNum + 3 * capacity] < capacity) { s[s[stackNum + 3 * capacity] * 3 + stackNum] = value; ++s[stackNum + 3 * capacity]; } } - + public int pop(int stackNum) { if (isEmpty(stackNum)) { return -1; @@ -120,11 +105,11 @@ class TripleInOne { --s[stackNum + 3 * capacity]; return s[s[stackNum + 3 * capacity] * 3 + stackNum]; } - + public int peek(int stackNum) { return isEmpty(stackNum) ? -1 : s[(s[stackNum + 3 * capacity] - 1) * 3 + stackNum]; } - + public boolean isEmpty(int stackNum) { return s[stackNum + 3 * capacity] == 0; } @@ -141,8 +126,9 @@ class TripleInOne { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.02.Min Stack/README.md b/lcci/03.02.Min Stack/README.md index 8d05969560198..aa0a010ca2972 100644 --- a/lcci/03.02.Min Stack/README.md +++ b/lcci/03.02.Min Stack/README.md @@ -3,17 +3,20 @@ [English Version](/lcci/03.02.Min%20Stack/README_EN.md) ## 题目描述 +

    请设计一个栈,除了常规栈支持的pop与push函数以外,还支持min函数,该函数返回栈元素中的最小值。执行push、pop和min操作的时间复杂度必须为O(1)。


    示例:

    MinStack minStack = new MinStack();
    minStack.push(-2);
    minStack.push(0);
    minStack.push(-3);
    minStack.getMin(); --> 返回 -3.
    minStack.pop();
    minStack.top(); --> 返回 0.
    minStack.getMin(); --> 返回 -2.

    ## 解法 + -利用辅助栈存放栈的最小元素。 +利用辅助栈存放栈的最小元素。 ### **Python3** + ```python @@ -51,6 +54,7 @@ class MinStack: ``` ### **Java** + ```java @@ -63,21 +67,21 @@ class MinStack { s1 = new Stack<>(); s2 = new Stack<>(); } - + public void push(int x) { s1.push(x); s2.push(s2.empty() || s2.peek() >= x ? x : s2.peek()); } - + public void pop() { s1.pop(); s2.pop(); } - + public int top() { return s1.peek(); } - + public int getMin() { return s2.empty() ? -1 : s2.peek(); } @@ -94,8 +98,9 @@ class MinStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.02.Min Stack/README_EN.md b/lcci/03.02.Min Stack/README_EN.md index 7bd358029b1a0..57fb34d7ede8f 100644 --- a/lcci/03.02.Min Stack/README_EN.md +++ b/lcci/03.02.Min Stack/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/03.02.Min%20Stack/README.md) ## Description -

    How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.

    - +

    How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.

    Example:

    - -
     
     MinStack minStack = new MinStack();
    @@ -29,12 +26,8 @@ minStack.top();      --> return 0.
     
     minStack.getMin();   --> return -2.
    - - - ## Solutions - ### **Python3** @@ -85,21 +78,21 @@ class MinStack { s1 = new Stack<>(); s2 = new Stack<>(); } - + public void push(int x) { s1.push(x); s2.push(s2.empty() || s2.peek() >= x ? x : s2.peek()); } - + public void pop() { s1.pop(); s2.pop(); } - + public int top() { return s1.peek(); } - + public int getMin() { return s2.empty() ? -1 : s2.peek(); } @@ -116,8 +109,9 @@ class MinStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.03.Stack of Plates/README.md b/lcci/03.03.Stack of Plates/README.md index 014c53aa032fd..11f4acacf2ce9 100644 --- a/lcci/03.03.Stack of Plates/README.md +++ b/lcci/03.03.Stack of Plates/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.03.Stack%20of%20Plates/README_EN.md) ## 题目描述 +

    堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构SetOfStacks,模拟这种行为。SetOfStacks应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,SetOfStacks.push()SetOfStacks.pop()应该与普通栈的操作方法相同(也就是说,pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个popAt(int index)方法,根据指定的子栈,执行pop操作。

    @@ -26,14 +27,14 @@ [null, null, null, null, 2, 1, 3] - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.03.Stack of Plates/README_EN.md b/lcci/03.03.Stack of Plates/README_EN.md index 13de55d75d100..729014fa88b87 100644 --- a/lcci/03.03.Stack of Plates/README_EN.md +++ b/lcci/03.03.Stack of Plates/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/03.03.Stack%20of%20Plates/README.md) ## Description -

    Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks and should create a new stack once the previous one exceeds capacity. SetOfStacks.push() and SetOfStacks.pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack). Follow Up: Implement a function popAt(int index) which performs a pop operation on a specific sub-stack.

    - +

    Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks and should create a new stack once the previous one exceeds capacity. SetOfStacks.push() and SetOfStacks.pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack). Follow Up: Implement a function popAt(int index) which performs a pop operation on a specific sub-stack.

    You should delete the sub-stack when it becomes empty. pop, popAt should return -1 when there's no element to pop.

    - -

    Example1:

    - -
     
      Input: 
    @@ -31,12 +26,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: 
    @@ -51,12 +42,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -72,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.04.Implement Queue using Stacks/README.md b/lcci/03.04.Implement Queue using Stacks/README.md index 47e331e30e931..c3ce9842b4c0d 100644 --- a/lcci/03.04.Implement Queue using Stacks/README.md +++ b/lcci/03.04.Implement Queue using Stacks/README.md @@ -3,11 +3,14 @@ [English Version](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) ## 题目描述 +

    实现一个MyQueue类,该类用两个栈来实现一个队列。


    示例:

    MyQueue queue = new MyQueue();

    queue.push(1);
    queue.push(2);
    queue.peek(); // 返回 1
    queue.pop(); // 返回 1
    queue.empty(); // 返回 false


    说明:

    • 你只能使用标准的栈操作 -- 也就是只有 push to top, peek/pop from top, sizeis empty 操作是合法的。
    • 你所使用的语言也许不支持栈。你可以使用 list 或者 deque(双端队列)来模拟一个栈,只要是标准的栈操作即可。
    • 假设所有操作都是有效的 (例如,一个空的队列不会调用 pop 或者 peek 操作)。

    ## 解法 + + - 每次压入元素时,放入第 1 个栈中; - 第 2 个栈不为空时,不能倒入元素; - 第 2 个栈为空时,必须将第 1 个栈的所有元素按顺序倒入第 2 个栈中。 @@ -15,6 +18,7 @@ ### **Python3** + ```python @@ -71,6 +75,7 @@ class MyQueue: ``` ### **Java** + ```java @@ -83,12 +88,12 @@ class MyQueue { s1 = new Stack<>(); s2 = new Stack<>(); } - + /** Push element x to the back of queue. */ public void push(int x) { s1.push(x); } - + /** Removes the element from in front of queue and returns that element. */ public int pop() { if (s2.empty()) { @@ -98,7 +103,7 @@ class MyQueue { } return s2.pop(); } - + /** Get the front element. */ public int peek() { if (s2.empty()) { @@ -108,7 +113,7 @@ class MyQueue { } return s2.peek(); } - + /** Returns whether the queue is empty. */ public boolean empty() { return s1.empty() && s2.empty(); @@ -126,8 +131,9 @@ class MyQueue { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.04.Implement Queue using Stacks/README_EN.md b/lcci/03.04.Implement Queue using Stacks/README_EN.md index aef8e17d6a65b..c9efdbd54c2f9 100644 --- a/lcci/03.04.Implement Queue using Stacks/README_EN.md +++ b/lcci/03.04.Implement Queue using Stacks/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) ## Description +

    Implement a MyQueue class which implements a queue using two stacks.

      - -

    Example:

    - -
     
     MyQueue queue = new MyQueue();
    @@ -29,32 +26,20 @@ queue.pop();   // return 1
     
     queue.empty(); // return false
    - -

     

    - -

    Notes:

    - -
    • You must use only standard operations of a stack -- which means only push to toppeek/pop from topsize, and is empty operations are valid.
    • Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.
    • You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).
    - -

     

    - - - ## Solutions - ### **Python3** @@ -124,12 +109,12 @@ class MyQueue { s1 = new Stack<>(); s2 = new Stack<>(); } - + /** Push element x to the back of queue. */ public void push(int x) { s1.push(x); } - + /** Removes the element from in front of queue and returns that element. */ public int pop() { if (s2.empty()) { @@ -139,7 +124,7 @@ class MyQueue { } return s2.pop(); } - + /** Get the front element. */ public int peek() { if (s2.empty()) { @@ -149,7 +134,7 @@ class MyQueue { } return s2.peek(); } - + /** Returns whether the queue is empty. */ public boolean empty() { return s1.empty() && s2.empty(); @@ -167,8 +152,9 @@ class MyQueue { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.05.Sort of Stacks/README.md b/lcci/03.05.Sort of Stacks/README.md index 6211150d22f7f..5fd0243eef6e5 100644 --- a/lcci/03.05.Sort of Stacks/README.md +++ b/lcci/03.05.Sort of Stacks/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) ## 题目描述 +

    栈排序。 编写程序,对栈进行排序使最小元素位于栈顶。最多只能使用一个其他的临时栈存放数据,但不得将元素复制到别的数据结构(如数组)中。该栈支持如下操作:pushpoppeekisEmpty。当栈为空时,peek 返回 -1。

    @@ -30,14 +31,16 @@
  • 栈中的元素数目在[0, 5000]范围内。
  • - ## 解法 + + 利用辅助栈实现 `push` 操作,其余操作不变。 ### **Python3** + ```python @@ -66,6 +69,7 @@ class SortedStack: ``` ### **Java** + ```java @@ -74,7 +78,7 @@ class SortedStack { public SortedStack() { s = new Stack<>(); } - + public void push(int val) { Stack t = new Stack<>(); while (!isEmpty() && s.peek() < val) { @@ -85,17 +89,17 @@ class SortedStack { s.push(t.pop()); } } - + public void pop() { if (!isEmpty()) { s.pop(); } } - + public int peek() { return isEmpty() ? -1 : s.peek(); } - + public boolean isEmpty() { return s.isEmpty(); } @@ -112,8 +116,9 @@ class SortedStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.05.Sort of Stacks/README_EN.md b/lcci/03.05.Sort of Stacks/README_EN.md index e13878b59304a..d5fb5a2be9f26 100644 --- a/lcci/03.05.Sort of Stacks/README_EN.md +++ b/lcci/03.05.Sort of Stacks/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/03.05.Sort%20of%20Stacks/README.md) ## Description -

    Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, and isEmpty. When the stack is empty, peek should return -1.

    - +

    Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, and isEmpty. When the stack is empty, peek should return -1.

    Example1:

    - -
     
      Input: 
    @@ -25,12 +22,8 @@
     
     
    - -

    Example2:

    - -
     
      Input:  
    @@ -45,22 +38,14 @@
     
     
    - -

    Note:

    - -
    1. The total number of elements in the stack is within the range [0, 5000].
    - - - ## Solutions - ### **Python3** @@ -98,7 +83,7 @@ class SortedStack { public SortedStack() { s = new Stack<>(); } - + public void push(int val) { Stack t = new Stack<>(); while (!isEmpty() && s.peek() < val) { @@ -109,17 +94,17 @@ class SortedStack { s.push(t.pop()); } } - + public void pop() { if (!isEmpty()) { s.pop(); } } - + public int peek() { return isEmpty() ? -1 : s.peek(); } - + public boolean isEmpty() { return s.isEmpty(); } @@ -136,8 +121,9 @@ class SortedStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.06.Animal Shelter/README.md b/lcci/03.06.Animal Shelter/README.md index 1653568787ac7..871e41efc56c4 100644 --- a/lcci/03.06.Animal Shelter/README.md +++ b/lcci/03.06.Animal Shelter/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.06.Animal%20Shelter/README_EN.md) ## 题目描述 +

    动物收容所。有家动物收容所只收容狗与猫,且严格遵守“先进先出”的原则。在收养该收容所的动物时,收养人只能收养所有动物中“最老”(由其进入收容所的时间长短而定)的动物,或者可以挑选猫或狗(同时必须收养此类动物中“最老”的)。换言之,收养人不能自由挑选想收养的对象。请创建适用于这个系统的数据结构,实现各种操作方法,比如enqueuedequeueAnydequeueDogdequeueCat。允许使用Java内置的LinkedList数据结构。

    @@ -34,14 +35,16 @@
  • 收纳所的最大容量为20000
  • - ## 解法 + + 双队列存储。 ### **Python3** + ```python @@ -78,6 +81,7 @@ class AnimalShelf: ``` ### **Java** + ```java @@ -88,7 +92,7 @@ class AnimalShelf { cats = new LinkedList<>(); dogs = new LinkedList<>(); } - + public void enqueue(int[] animal) { if (animal[1] == 0) { cats.offer(animal[0]); @@ -96,15 +100,15 @@ class AnimalShelf { dogs.offer(animal[0]); } } - + public int[] dequeueAny() { return dogs.isEmpty() ? dequeueCat() : (cats.isEmpty() ? dequeueDog() : (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat())); } - + public int[] dequeueDog() { return dogs.isEmpty() ? new int[]{-1, -1} : new int[]{dogs.poll(), 1}; } - + public int[] dequeueCat() { return cats.isEmpty() ? new int[]{-1, -1} : new int[]{cats.poll(), 0}; } @@ -121,8 +125,9 @@ class AnimalShelf { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.06.Animal Shelter/README_EN.md b/lcci/03.06.Animal Shelter/README_EN.md index e3154e1fcd56a..189055fe5bfca 100644 --- a/lcci/03.06.Animal Shelter/README_EN.md +++ b/lcci/03.06.Animal Shelter/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/03.06.Animal%20Shelter/README.md) ## Description -

    An animal shelter, which holds only dogs and cats, operates on a strictly"first in, first out" basis. People must adopt either the"oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog, and dequeueCat. You may use the built-in Linked list data structure.

    - +

    An animal shelter, which holds only dogs and cats, operates on a strictly"first in, first out" basis. People must adopt either the"oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog, and dequeueCat. You may use the built-in Linked list data structure.

    enqueue method has a animal parameter, animal[0] represents the number of the animal, animal[1] represents the type of the animal, 0 for cat and 1 for dog.

    - -

    dequeue* method returns [animal number, animal type], if there's no animal that can be adopted, return [-1, -1].

    - -

    Example1:

    - -
     
      Input: 
    @@ -33,12 +26,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: 
    @@ -53,22 +42,14 @@
     
     
    - -

    Note:

    - -
    1. The number of animals in the shelter will not exceed 20000.
    - - - ## Solutions - ### **Python3** @@ -116,7 +97,7 @@ class AnimalShelf { cats = new LinkedList<>(); dogs = new LinkedList<>(); } - + public void enqueue(int[] animal) { if (animal[1] == 0) { cats.offer(animal[0]); @@ -124,15 +105,15 @@ class AnimalShelf { dogs.offer(animal[0]); } } - + public int[] dequeueAny() { return dogs.isEmpty() ? dequeueCat() : (cats.isEmpty() ? dequeueDog() : (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat())); } - + public int[] dequeueDog() { return dogs.isEmpty() ? new int[]{-1, -1} : new int[]{dogs.poll(), 1}; } - + public int[] dequeueCat() { return cats.isEmpty() ? new int[]{-1, -1} : new int[]{cats.poll(), 0}; } @@ -149,8 +130,9 @@ class AnimalShelf { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.01.Route Between Nodes/README.md b/lcci/04.01.Route Between Nodes/README.md index a634023fadc01..f5356fc956684 100644 --- a/lcci/04.01.Route Between Nodes/README.md +++ b/lcci/04.01.Route Between Nodes/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) ## 题目描述 +

    节点间通路。给定有向图,设计一个算法,找出两个节点之间是否存在一条路径。

    @@ -26,14 +27,14 @@
  • 图中可能存在自环和平行边。
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.01.Route Between Nodes/README_EN.md b/lcci/04.01.Route Between Nodes/README_EN.md index 488053c6e7a56..2966fbdcc83cd 100644 --- a/lcci/04.01.Route Between Nodes/README_EN.md +++ b/lcci/04.01.Route Between Nodes/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.01.Route%20Between%20Nodes/README.md) ## Description -

    Given a directed graph, design an algorithm to find out whether there is a route between two nodes.

    - +

    Given a directed graph, design an algorithm to find out whether there is a route between two nodes.

    Example1:

    - -
     
      Input: n = 3, graph = [[0, 1], [0, 2], [1, 2], [1, 2]], start = 0, target = 2
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: n = 5, graph = [[0, 1], [0, 2], [0, 4], [0, 4], [0, 1], [1, 3], [1, 4], [1, 3], [2, 3], [3, 4]], start = 0, target = 4
    @@ -33,24 +26,16 @@
     
     
    - -

    Note:

    - -
    1. 0 <= n <= 100000
    2. All node numbers are within the range [0, n].
    3. There might be self cycles and duplicated edges.
    - - - ## Solutions - ### **Python3** @@ -66,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.02.Minimum Height Tree/README.md b/lcci/04.02.Minimum Height Tree/README.md index af5d738b023da..92c1b5b5b0420 100644 --- a/lcci/04.02.Minimum Height Tree/README.md +++ b/lcci/04.02.Minimum Height Tree/README.md @@ -3,16 +3,18 @@ [English Version](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) ## 题目描述 +

    给定一个有序整数数组,元素各不相同且按升序排列,编写一个算法,创建一棵高度最小的二叉搜索树。

    示例:
    给定有序数组: [-10,-3,0,5,9],

    一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树:

    0
    / \
    -3 9
    / /
    -10 5
    ## 解法 - + ### **Python3** + ```python @@ -20,6 +22,7 @@ ``` ### **Java** + ```java @@ -27,8 +30,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.02.Minimum Height Tree/README_EN.md b/lcci/04.02.Minimum Height Tree/README_EN.md index c8e5b5d266e5e..e37df1d4c56ef 100644 --- a/lcci/04.02.Minimum Height Tree/README_EN.md +++ b/lcci/04.02.Minimum Height Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.02.Minimum%20Height%20Tree/README.md) ## Description -

    Given a sorted (increasing order) array with unique integer elements, write an algo­rithm to create a binary search tree with minimal height.

    - +

    Given a sorted (increasing order) array with unique integer elements, write an algo­rithm to create a binary search tree with minimal height.

    Example:

    - -
     
     Given sorted array: [-10,-3,0,5,9],
    @@ -33,12 +30,8 @@ One possible answer is: [0,-3,9,-10,null,5],which represents the following tre
     
     
    - - - ## Solutions - ### **Python3** @@ -54,8 +47,9 @@ One possible answer is: [0,-3,9,-10,null,5],which represents the following tre ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.03.List of Depth/README.md b/lcci/04.03.List of Depth/README.md index 470c7277fc474..c8861174580ff 100644 --- a/lcci/04.03.List of Depth/README.md +++ b/lcci/04.03.List of Depth/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.03.List%20of%20Depth/README_EN.md) ## 题目描述 +

    给定一棵二叉树,设计一个算法,创建含有某一深度上所有节点的链表(比如,若一棵树的深度为 D,则会创建出 D 个链表)。返回一个包含所有深度的链表的数组。

    @@ -23,14 +24,14 @@ 输出:[[1],[2,3],[4,5,7],[8]] - ## 解法 - + ### **Python3** + ```python @@ -38,6 +39,7 @@ ``` ### **Java** + ```java @@ -45,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.03.List of Depth/README_EN.md b/lcci/04.03.List of Depth/README_EN.md index 7a756015d58d4..e8811cffece34 100644 --- a/lcci/04.03.List of Depth/README_EN.md +++ b/lcci/04.03.List of Depth/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/04.03.List%20of%20Depth/README.md) ## Description -

    Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array containing all the linked lists.

    - +

    Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array containing all the linked lists.

     

    - -

    Example:

    - -
     
     Input: [1,2,3,4,5,null,7,8]
    @@ -41,12 +36,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -62,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.04.Check Balance/README.md b/lcci/04.04.Check Balance/README.md index 07236b556a228..65e5f677b3a87 100644 --- a/lcci/04.04.Check Balance/README.md +++ b/lcci/04.04.Check Balance/README.md @@ -3,16 +3,20 @@ [English Version](/lcci/04.04.Check%20Balance/README_EN.md) ## 题目描述 +

    实现一个函数,检查二叉树是否平衡。在这个问题中,平衡树的定义如下:任意一个节点,其两棵子树的高度差不超过 1。


    示例 1:
    给定二叉树 [3,9,20,null,null,15,7]
    3
    / \
    9 20
    / \
    15 7
    返回 true 。
    示例 2:
    给定二叉树 [1,2,2,3,3,null,null,4,4]
    1
    / \
    2 2
    / \
    3 3
    / \
    4 4
    返回 false 。
    ## 解法 + + 递归法。 ### **Python3** + ```python @@ -37,6 +41,7 @@ class Solution: ``` ### **Java** + ```java @@ -68,8 +73,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.04.Check Balance/README_EN.md b/lcci/04.04.Check Balance/README_EN.md index a9daa3059a9d0..1db241ff3357c 100644 --- a/lcci/04.04.Check Balance/README_EN.md +++ b/lcci/04.04.Check Balance/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/04.04.Check%20Balance/README.md) ## Description -

    Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

    - +

    Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.


    Example 1:

    - -
     
     Given tree [3,9,20,null,null,15,7]
    @@ -29,12 +26,8 @@ Given tree [3,9,20,null,null,15,7]
     
     return true.
    - -

    Example 2:

    - -
     
     Given [1,2,2,3,3,null,null,4,4]
    @@ -55,16 +48,10 @@ Given [1,2,2,3,3,null,null,4,4]
     
     return false.
    - -

     

    - - - ## Solutions - ### **Python3** @@ -121,8 +108,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.05.Legal Binary Search Tree/README.md b/lcci/04.05.Legal Binary Search Tree/README.md index 21b9e8fe2e59d..afbf1e786de10 100644 --- a/lcci/04.05.Legal Binary Search Tree/README.md +++ b/lcci/04.05.Legal Binary Search Tree/README.md @@ -3,16 +3,20 @@ [English Version](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +

    实现一个函数,检查一棵二叉树是否为二叉搜索树。

    示例 1:
    输入:
    2
    / \
    1 3
    输出: true
    示例 2:
    输入:
    5
    / \
    1 4
      / \
      3 6
    输出: false
    解释: 输入为: [5,1,4,null,null,3,6]。
      根节点的值为 5 ,但是其右子节点值为 4 。
    ## 解法 + + 一棵合法的二叉搜索树,其中序遍历的结果应该升序排列。 ### **Python3** + ```python @@ -42,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -79,8 +84,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.05.Legal Binary Search Tree/README_EN.md b/lcci/04.05.Legal Binary Search Tree/README_EN.md index 96f782a02bc1b..e59cb8bab8a21 100644 --- a/lcci/04.05.Legal Binary Search Tree/README_EN.md +++ b/lcci/04.05.Legal Binary Search Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) ## Description -

    Implement a function to check if a binary tree is a binary search tree.

    - +

    Implement a function to check if a binary tree is a binary search tree.

    Example 1:

    - -
     
     Input:
    @@ -25,12 +22,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -51,12 +44,8 @@
     
          the value of root node is 5, but its right child has value 4.
    - - - ## Solutions - ### **Python3** @@ -124,8 +113,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.06.Successor/README.md b/lcci/04.06.Successor/README.md index 4a501d6d0bce5..8193be99537ed 100644 --- a/lcci/04.06.Successor/README.md +++ b/lcci/04.06.Successor/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.06.Successor/README_EN.md) ## 题目描述 +

    设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。

    @@ -32,14 +33,14 @@ 输出: null - ## 解法 - + ### **Python3** + ```python @@ -47,6 +48,7 @@ ``` ### **Java** + ```java @@ -54,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.06.Successor/README_EN.md b/lcci/04.06.Successor/README_EN.md index d2441df2f52d3..f9fd091350e40 100644 --- a/lcci/04.06.Successor/README_EN.md +++ b/lcci/04.06.Successor/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/04.06.Successor/README.md) ## Description -

    Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree.

    - +

    Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree.

    Return null if there's no "next" node for the given node.

    - -

    Example 1:

    - -
     
     Input: root = [2,1,3], p = 1
    @@ -31,12 +26,8 @@
     
     Output: 2
    - -

    Example 2:

    - -
     
     Input: root = [5,3,6,2,4,null,null,1], p = 6
    @@ -61,12 +52,8 @@
     
     Output: null
    - - - ## Solutions - ### **Python3** @@ -82,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.08.First Common Ancestor/README.md b/lcci/04.08.First Common Ancestor/README.md index 197fc8c85208b..a4f7bc1adc869 100644 --- a/lcci/04.08.First Common Ancestor/README.md +++ b/lcci/04.08.First Common Ancestor/README.md @@ -3,16 +3,18 @@ [English Version](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) ## 题目描述 +

    设计并实现一个算法,找出二叉树中某两个节点的第一个共同祖先。不得将其他的节点存储在另外的数据结构中。注意:这不一定是二叉搜索树。

    例如,给定如下二叉树: root = [3,5,1,6,2,0,8,null,null,7,4]

        3
    / \
    5 1
    / \ / \
    6 2 0 8
    / \
    7 4
    示例 1:
    输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
    输入: 3
    解释: 节点 5 和节点 1 的最近公共祖先是节点 3。
    示例 2:
    输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
    输出: 5
    解释: 节点 5 和节点 4 的最近公共祖先是节点 5。因为根据定义最近公共祖先节点可以为节点本身。
    说明:
    所有节点的值都是唯一的。
    p、q 为不同节点且均存在于给定的二叉树中。
    ## 解法 - + ### **Python3** + ```python @@ -33,6 +35,7 @@ class Solution: ``` ### **Java** + ```java @@ -58,8 +61,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.08.First Common Ancestor/README_EN.md b/lcci/04.08.First Common Ancestor/README_EN.md index c0591b2f6a27b..8dd1145bf3b71 100644 --- a/lcci/04.08.First Common Ancestor/README_EN.md +++ b/lcci/04.08.First Common Ancestor/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.08.First%20Common%20Ancestor/README.md) ## Description -

    Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.

    - +

    Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.

    For example, Given the following tree: root = [3,5,1,6,2,0,8,null,null,7,4]

    - -
     
         3
    @@ -29,12 +26,8 @@
     
     
    - -

    Example 1:

    - -
     
     Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
    @@ -43,12 +36,8 @@
     
     Explanation: The first common ancestor of node 5 and node 1 is node 3.
    - -

    Example 2:

    - -
     
     Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
    @@ -57,8 +46,6 @@
     
     Explanation: The first common ancestor of node 5 and node 4 is node 5.
    - -

    Notes:

      @@ -66,12 +53,8 @@
    • p, q are different node and both can be found in the given tree.
    - - - ## Solutions - ### **Python3** @@ -118,8 +101,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.09.BST Sequences/README.md b/lcci/04.09.BST Sequences/README.md index b4ddd66ff6da6..3f5fadb7923eb 100644 --- a/lcci/04.09.BST Sequences/README.md +++ b/lcci/04.09.BST Sequences/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.09.BST%20Sequences/README_EN.md) ## 题目描述 +

    从左向右遍历一个数组,通过不断将其中的元素插入树中可以逐步地生成一棵二叉搜索树。给定一个由不同节点组成的二叉树,输出所有可能生成此树的数组。

    @@ -22,14 +23,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -37,6 +38,7 @@ ``` ### **Java** + ```java @@ -44,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.09.BST Sequences/README_EN.md b/lcci/04.09.BST Sequences/README_EN.md index 90252671811bd..0117940590e53 100644 --- a/lcci/04.09.BST Sequences/README_EN.md +++ b/lcci/04.09.BST Sequences/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/04.09.BST%20Sequences/README.md) ## Description -

    A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.

    - +

    A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.

    Example:
    Given the following tree:

    - -
     
             2
    @@ -23,12 +20,8 @@ Given the following tree:

    - -

    Output:

    - -
     
     [
    @@ -41,12 +34,8 @@ Given the following tree:

    - - - ## Solutions - ### **Python3** @@ -62,8 +51,9 @@ Given the following tree:

    ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.10.Check SubTree/README.md b/lcci/04.10.Check SubTree/README.md index e5f692e3c02c8..4c2d42e7946da 100644 --- a/lcci/04.10.Check SubTree/README.md +++ b/lcci/04.10.Check SubTree/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.10.Check%20SubTree/README_EN.md) ## 题目描述 +

    检查子树。你有两棵非常大的二叉树:T1,有几万个节点;T2,有几万个节点。设计一个算法,判断 T2 是否为 T1 的子树。

    @@ -26,14 +27,16 @@
  • 树的节点数目范围为[0, 20000]。
  • - ## 解法 + + 先找 t1 中 t2 结点,找到后进行 DFS,确认子树和 t2 的子树完全相同,否则返回 FALSE。 ### **Python3** + ```python @@ -44,7 +47,7 @@ class Solution: if t2 == None: return True return self.dfs(t1,t2) or self.checkSubTree(t1.left,t2) or self.checkSubTree(t1.right,t2) - + def dfs(self, t1: TreeNode, t2: TreeNode) -> bool: if not t1 and t2 : return False @@ -57,6 +60,7 @@ class Solution: ``` ### **Java** + ```java @@ -82,8 +86,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.10.Check SubTree/README_EN.md b/lcci/04.10.Check SubTree/README_EN.md index 5e9cbc0cc48d1..4bf9b9a910177 100644 --- a/lcci/04.10.Check SubTree/README_EN.md +++ b/lcci/04.10.Check SubTree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/04.10.Check%20SubTree/README.md) ## Description -

    T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1.

    - +

    T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1.

    A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n is identical to T2. That is, if you cut off the tree at node n, the two trees would be identical.

    - -

    Example1:

    - -
     
      Input: t1 = [1, 2, 3], t2 = [2]
    @@ -23,12 +18,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: t1 = [1, null, 2, 4], t2 = [3, 2]
    @@ -37,20 +28,14 @@
     
     
    - -

    Note:

    - -
    1. The node numbers of both tree are in [0, 20000].
    - - - ## Solutions + Find the t2 node in t1 first, then use the depth-first search (DFS) algorithm to make sure that the subtree and the subtree of t2 are identical, otherwise return FALSE. @@ -65,7 +50,7 @@ class Solution: if t2 == None: return True return self.dfs(t1,t2) or self.checkSubTree(t1.left,t2) or self.checkSubTree(t1.right,t2) - + def dfs(self, t1: TreeNode, t2: TreeNode) -> bool: if not t1 and t2 : return False @@ -102,8 +87,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.12.Paths with Sum/README.md b/lcci/04.12.Paths with Sum/README.md index a9cb87a5d0e56..1a72ae75239da 100644 --- a/lcci/04.12.Paths with Sum/README.md +++ b/lcci/04.12.Paths with Sum/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.12.Paths%20with%20Sum/README_EN.md) ## 题目描述 +

    给定一棵二叉树,其中每个节点都含有一个整数数值(该值或正或负)。设计一个算法,打印节点数值总和等于某个给定值的所有路径的数量。注意,路径不一定非得从二叉树的根节点或叶节点开始或结束,但是其方向必须向下(只能从父节点指向子节点方向)。

    @@ -29,16 +30,20 @@
  • 节点总数 <= 10000
  • - ## 解法 + + DFS 深度优先搜索 ### **Python3** + + 采用递归的思想,每递归到某个节点时: + - 若`root.val-sum == 0`,结果加 1 - 考虑将此节点纳入或不纳入路径两种情况 @@ -58,7 +63,7 @@ class Solution: dfs(root.right, sum, 0) dfs(root.left, sum-root.val, 1) dfs(root.right, sum-root.val, 1) - + if not root: return 0 ans = 0 @@ -67,8 +72,10 @@ class Solution: ``` ### **Java** + -使用到2个递归过程: + +使用到 2 个递归过程: - BFS:(traverse)遍历每个树节点; - DFS: 从每个树节点出发,节点求和,看是否能满足 sum。 @@ -104,8 +111,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.12.Paths with Sum/README_EN.md b/lcci/04.12.Paths with Sum/README_EN.md index bd0af437441fa..664ff00437f7a 100644 --- a/lcci/04.12.Paths with Sum/README_EN.md +++ b/lcci/04.12.Paths with Sum/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/04.12.Paths%20with%20Sum/README.md) ## Description -

    You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).

    - +

    You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).

    Example:
    Given the following tree and  sum = 22,

    - -
     
                   5
    @@ -31,38 +28,30 @@ Given the following tree and  sum = 22,

    - -

    Output:

    - -
     
     3
     
     Explanation: Paths that have sum 22 are: [5,4,11,2], [5,8,4,5], [4,11,7]
    - -

    Note:

    - -
    • node number <= 10000
    - - - ## Solutions + Depth-First-Search ### **Python3** + Using the idea of recursion, at each recursion to a node. + - If root.val-sum == 0, add 1 to the result - Consider two scenarios for inclusion or exclusion of this node from the pathway @@ -82,7 +71,7 @@ class Solution: dfs(root.right, sum, 0) dfs(root.left, sum-root.val, 1) dfs(root.right, sum-root.val, 1) - + if not root: return 0 ans = 0 @@ -91,6 +80,7 @@ class Solution: ``` ### **Java** + Use to 2 recursive processes. - BFS: (traverse) traverses each tree node. @@ -127,8 +117,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.01.Insert Into Bits/README.md b/lcci/05.01.Insert Into Bits/README.md index ae5d52e723c3e..af303f172e519 100644 --- a/lcci/05.01.Insert Into Bits/README.md +++ b/lcci/05.01.Insert Into Bits/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) ## 题目描述 +

    插入。给定两个32位的整数NM,以及表示比特位置的ij。编写一种方法,将M插入N,使得M从N的第j位开始,到第i位结束。假定从j位到i位足以容纳M,也即若M = 10 011,那么j和i之间至少可容纳5个位。例如,不可能出现j = 3和i = 2的情况,因为第3位和第2位之间放不下M。

    @@ -20,14 +21,14 @@ 输出:N = 11111 - ## 解法 - + ### **Python3** + ```python @@ -35,6 +36,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.01.Insert Into Bits/README_EN.md b/lcci/05.01.Insert Into Bits/README_EN.md index b23a7139ab6bc..23ed2ae99f1c6 100644 --- a/lcci/05.01.Insert Into Bits/README_EN.md +++ b/lcci/05.01.Insert Into Bits/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.01.Insert%20Into%20Bits/README.md) ## Description -

    You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.

    - +

    You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.

    Example1:

    - -
     
      Input: N = 10000000000, M = 10011, i = 2, j = 6
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input:  N = 0, M = 11111, i = 0, j = 4
    @@ -33,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -61,8 +50,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.02.Bianry Number to String/README.md b/lcci/05.02.Bianry Number to String/README.md index 7a132ad18fd6a..5eb819260427f 100644 --- a/lcci/05.02.Bianry Number to String/README.md +++ b/lcci/05.02.Bianry Number to String/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) ## 题目描述 +

    二进制数转字符串。给定一个介于0和1之间的实数(如0.72),类型为double,打印它的二进制表达式。如果该数字不在0和1之间,或者无法精确地用32位以内的二进制表示,则打印“ERROR”。

    @@ -25,14 +26,14 @@
  • 32位包括输出中的"0."这两位。
  • - ## 解法 - + ### **Python3** + ```python @@ -40,6 +41,7 @@ ``` ### **Java** + ```java @@ -47,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.02.Bianry Number to String/README_EN.md b/lcci/05.02.Bianry Number to String/README_EN.md index aa90c28c2a3d5..e0171991b8861 100644 --- a/lcci/05.02.Bianry Number to String/README_EN.md +++ b/lcci/05.02.Bianry Number to String/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.02.Bianry%20Number%20to%20String/README.md) ## Description -

    Given a real number between O and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".

    - +

    Given a real number between O and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".

    Example1:

    - -
     
      Input: 0.625
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: 0.1
    @@ -35,22 +28,14 @@
     
     
    - -

    Note:

    - -
    1. This two charaters "0." should be counted into 32 characters.
    - - - ## Solutions - ### **Python3** @@ -66,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.03.Reverse Bits/README.md b/lcci/05.03.Reverse Bits/README.md index 9f0a1eae32b09..01733cdb27cda 100644 --- a/lcci/05.03.Reverse Bits/README.md +++ b/lcci/05.03.Reverse Bits/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.03.Reverse%20Bits/README_EN.md) ## 题目描述 +

    给定一个32位整数 num,你可以将一个数位从0变为1。请编写一个程序,找出你能够获得的最长的一串1的长度。

    @@ -18,14 +19,14 @@ 输出: 4 - ## 解法 - + ### **Python3** + ```python @@ -33,6 +34,7 @@ ``` ### **Java** + ```java @@ -40,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.03.Reverse Bits/README_EN.md b/lcci/05.03.Reverse Bits/README_EN.md index 368447208ae76..ee9407a1e2b47 100644 --- a/lcci/05.03.Reverse Bits/README_EN.md +++ b/lcci/05.03.Reverse Bits/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.03.Reverse%20Bits/README.md) ## Description -

    You have an integer and you can flip exactly one bit from a 0 to a 1. Write code to find the length of the longest sequence of 1s you could create.

    - +

    You have an integer and you can flip exactly one bit from a 0 to a 1. Write code to find the length of the longest sequence of 1s you could create.

    Example 1:

    - -
     
     Input: num = 1775(110111011112)
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: num = 7(01112)
    @@ -33,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -54,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.04.Closed Number/README.md b/lcci/05.04.Closed Number/README.md index 7b29c74803a51..f52631bf59c1a 100644 --- a/lcci/05.04.Closed Number/README.md +++ b/lcci/05.04.Closed Number/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.04.Closed%20Number/README_EN.md) ## 题目描述 +

    下一个数。给定一个正整数,找出与其二进制表达式中1的个数相同且大小最接近的那两个数(一个略大,一个略小)。

    @@ -27,14 +28,14 @@
  • 如果找不到前一个或者后一个满足条件的正数,那么输出 -1。
  • - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.04.Closed Number/README_EN.md b/lcci/05.04.Closed Number/README_EN.md index 217c89bc853b7..3f4c302b4fbe5 100644 --- a/lcci/05.04.Closed Number/README_EN.md +++ b/lcci/05.04.Closed Number/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.04.Closed%20Number/README.md) ## Description -

    Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.

    - +

    Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.

    Example1:

    - -
     
      Input: num = 2 (0b10)
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: num = 1
    @@ -33,23 +26,15 @@
     
     
    - -

    Note:

    - -
    1. 1 <= num <= 2147483647
    2. If there is no next smallest or next largest number, output -1.
    - - - ## Solutions - ### **Python3** @@ -65,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.06.Convert Integer/README.md b/lcci/05.06.Convert Integer/README.md index b72b0bbac99c8..be05e5fa6e7c7 100644 --- a/lcci/05.06.Convert Integer/README.md +++ b/lcci/05.06.Convert Integer/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.06.Convert%20Integer/README_EN.md) ## 题目描述 +

    整数转换。编写一个函数,确定需要改变几个位才能将整数A转成整数B。

    @@ -26,14 +27,14 @@
  • A,B范围在[-2147483648, 2147483647]之间
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -52,8 +54,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.06.Convert Integer/README_EN.md b/lcci/05.06.Convert Integer/README_EN.md index 62158e6404f83..5cfc8c246b5ec 100644 --- a/lcci/05.06.Convert Integer/README_EN.md +++ b/lcci/05.06.Convert Integer/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.06.Convert%20Integer/README.md) ## Description -

    Write a function to determine the number of bits you would need to flip to convert integer A to integer B.

    - +

    Write a function to determine the number of bits you would need to flip to convert integer A to integer B.

    Example1:

    - -
     
      Input: A = 29 (0b11101), B = 15 (0b01111)
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: A = 1,B = 2
    @@ -33,22 +26,14 @@
     
     
    - -

    Note:

    - -
    1. -2147483648 <= A, B <= 2147483647
    - - - ## Solutions - ### **Python3** @@ -68,8 +53,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.07.Exchange/README.md b/lcci/05.07.Exchange/README.md index 69dde0b491af2..1c2c0f00a264d 100644 --- a/lcci/05.07.Exchange/README.md +++ b/lcci/05.07.Exchange/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.07.Exchange/README_EN.md) ## 题目描述 +

    配对交换。编写程序,交换某个整数的奇数位和偶数位,尽量使用较少的指令(也就是说,位0与位1交换,位2与位3交换,以此类推)。

    @@ -26,14 +27,14 @@
  • num的范围在[0, 2^30 - 1]之间,不会发生整数溢出。
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -54,8 +56,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.07.Exchange/README_EN.md b/lcci/05.07.Exchange/README_EN.md index 62c5e1315b5a7..96df5b341db64 100644 --- a/lcci/05.07.Exchange/README_EN.md +++ b/lcci/05.07.Exchange/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/05.07.Exchange/README.md) ## Description -

    Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on).

    - +

    Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on).

    Example1:

    - -
     
      Input: num = 2(0b10)
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: num = 3
    @@ -33,23 +26,15 @@
     
     
    - -

    Note:

    - -
    1. 0 <= num <= 2^30 - 1
    2. The result integer fits into 32-bit integer.
    - - - ## Solutions - ### **Python3** @@ -71,8 +56,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.08.Draw Line/README.md b/lcci/05.08.Draw Line/README.md index 96f453dd1b011..1c79e906e921f 100644 --- a/lcci/05.08.Draw Line/README.md +++ b/lcci/05.08.Draw Line/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.08.Draw%20Line/README_EN.md) ## 题目描述 +

    绘制直线。有个单色屏幕存储在一个一维数组中,使得32个连续像素可以存放在一个 int 里。屏幕宽度为w,且w可被32整除(即一个 int 不会分布在两行上),屏幕高度可由数组长度及屏幕宽度推算得出。请实现一个函数,绘制从点(x1, y)到点(x2, y)的水平线。

    @@ -21,14 +22,14 @@ 输出:[-1, -1, -1] - ## 解法 - + ### **Python3** + ```python @@ -36,6 +37,7 @@ ``` ### **Java** + ```java @@ -43,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.08.Draw Line/README_EN.md b/lcci/05.08.Draw Line/README_EN.md index f0fe61d16432c..f27d6e278459e 100644 --- a/lcci/05.08.Draw Line/README_EN.md +++ b/lcci/05.08.Draw Line/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/05.08.Draw%20Line/README.md) ## Description -

    A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be split across rows). The height of the screen, of course, can be derived from the length of the array and the width. Implement a function that draws a horizontal line from (x1, y) to (x2, y).

    - +

    A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be split across rows). The height of the screen, of course, can be derived from the length of the array and the width. Implement a function that draws a horizontal line from (x1, y) to (x2, y).

    Given the length of the array, the width of the array (in bit), start position x1 (in bit) of the line, end position x2 (in bit) of the line and the row number y of the line, return the array after drawing.

    - -

    Example1:

    - -
     
      Input: length = 1, w = 32, x1 = 30, x2 = 31, y = 0
    @@ -25,12 +20,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: length = 3, w = 96, x1 = 0, x2 = 95, y = 0
    @@ -39,10 +30,8 @@
     
     
    - ## Solutions - ### **Python3** @@ -58,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.01.Three Steps Problem/README.md b/lcci/08.01.Three Steps Problem/README.md index 52f077cc3125c..fa172c0f5a7ee 100644 --- a/lcci/08.01.Three Steps Problem/README.md +++ b/lcci/08.01.Three Steps Problem/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) ## 题目描述 +

    三步问题。有个小孩正在上楼梯,楼梯有n阶台阶,小孩一次可以上1阶、2阶或3阶。实现一种方法,计算小孩有多少种上楼梯的方式。结果可能很大,你需要对结果模1000000007。

    @@ -27,14 +28,16 @@
  • n范围在[1, 1000000]之间
  • - ## 解法 + + 递推法。`f(n)=f(n-1)+f(n-2)+f(n-3)` ### **Python3** + ```python @@ -49,6 +52,7 @@ class Solution: ``` ### **Java** + ```java @@ -70,6 +74,7 @@ class Solution { ``` ### **C++** + ```cpp class Solution { public: @@ -89,4 +94,4 @@ public: }; ``` - \ No newline at end of file + diff --git a/lcci/08.01.Three Steps Problem/README_EN.md b/lcci/08.01.Three Steps Problem/README_EN.md index 3e84aeb5cc292..9ce39db976a8c 100644 --- a/lcci/08.01.Three Steps Problem/README_EN.md +++ b/lcci/08.01.Three Steps Problem/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.01.Three%20Steps%20Problem/README.md) ## Description -

    A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so return it modulo 1000000007.

    - +

    A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so return it modulo 1000000007.

    Example1:

    - -
     
      Input: n = 3 
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: n = 5
    @@ -33,15 +26,12 @@
     
     
    - -

    Note:

    1. `1 <= n <= 1000000` ## Solutions - ### **Python3** @@ -78,6 +68,7 @@ class Solution { ``` ### **C++** + ```cpp class Solution { public: @@ -97,4 +88,4 @@ public: }; ``` - \ No newline at end of file + diff --git a/lcci/08.02.Robot in a Grid/README.md b/lcci/08.02.Robot in a Grid/README.md index 08e036f2b5ef0..88b4e9c34f6d0 100644 --- a/lcci/08.02.Robot in a Grid/README.md +++ b/lcci/08.02.Robot in a Grid/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) ## 题目描述 +

    设想有个机器人坐在一个网格的左上角,网格 r 行 c 列。机器人只能向下或向右移动,但不能走到一些被禁止的网格(有障碍物)。设计一种算法,寻找机器人从左上角移动到右下角的路径。

    @@ -27,14 +28,14 @@

    说明:r 和 c 的值均不超过 100。

    - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.02.Robot in a Grid/README_EN.md b/lcci/08.02.Robot in a Grid/README_EN.md index f404b3f5aa0a5..6c2de546ee6e8 100644 --- a/lcci/08.02.Robot in a Grid/README_EN.md +++ b/lcci/08.02.Robot in a Grid/README_EN.md @@ -3,21 +3,17 @@ [中文文档](/lcci/08.02.Robot%20in%20a%20Grid/README.md) ## Description -

    Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such that the robot cannot step on them. Design an algorithm to find a path for the robot from the top left to the bottom right.

    +

    Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such that the robot cannot step on them. Design an algorithm to find a path for the robot from the top left to the bottom right.

    ![](./images/robot_maze.png)

    "off limits" and empty grid are represented by 1 and 0 respectively.

    -

    Return a valid path, consisting of row number and column number of grids in the path.

    -

    Example 1:

    - -
     
     Input:
    @@ -34,19 +30,14 @@
     
     Output: [[0,0],[0,1],[0,2],[1,2],[2,2]]
    - -

    Note:

    - -
    • r, c <= 100
    ## Solutions - ### **Python3** @@ -62,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.03.Magic Index/README.md b/lcci/08.03.Magic Index/README.md index 3019661b5218c..39e794aecc3cd 100644 --- a/lcci/08.03.Magic Index/README.md +++ b/lcci/08.03.Magic Index/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.03.Magic%20Index/README_EN.md) ## 题目描述 +

    魔术索引。 在数组A[0...n-1]中,有所谓的魔术索引,满足条件A[i] = i。给定一个有序整数数组,编写一种方法找出魔术索引,若有的话,在数组A中找出一个魔术索引,如果没有,则返回-1。若有多个魔术索引,返回索引值最小的一个。

    @@ -25,14 +26,14 @@
  • nums长度在[1, 1000000]之间
  • - ## 解法 - + ### **Python3** + ```python @@ -40,6 +41,7 @@ ``` ### **Java** + ```java @@ -47,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.03.Magic Index/README_EN.md b/lcci/08.03.Magic Index/README_EN.md index 2fae3e07bb425..68c9d9d2a0f97 100644 --- a/lcci/08.03.Magic Index/README_EN.md +++ b/lcci/08.03.Magic Index/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.03.Magic%20Index/README.md) ## Description -

    A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are more than one magic index, return the smallest one.

    - +

    A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are more than one magic index, return the smallest one.

    Example1:

    - -
     
      Input: nums = [0, 2, 3, 4, 5]
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: nums = [1, 1, 1]
    @@ -33,20 +26,14 @@
     
     
    - -

    Note:

    1. 1 <= nums.length <= 1000000
    - - - ## Solutions - ### **Python3** @@ -62,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.04.Power Set/README.md b/lcci/08.04.Power Set/README.md index 1eaab13add14d..41c4d08051fb4 100644 --- a/lcci/08.04.Power Set/README.md +++ b/lcci/08.04.Power Set/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.04.Power%20Set/README_EN.md) ## 题目描述 +

    幂集。编写一种方法,返回某集合的所有子集。集合中不包含重复的元素

    @@ -24,14 +25,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ ``` ### **Java** + ```java @@ -46,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.04.Power Set/README_EN.md b/lcci/08.04.Power Set/README_EN.md index 30dfe81f8e3ed..598f8e52626dc 100644 --- a/lcci/08.04.Power Set/README_EN.md +++ b/lcci/08.04.Power Set/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.04.Power%20Set/README.md) ## Description -

    Write a method to return all subsets of a set. The elements in a set are pairwise distinct.

    - +

    Write a method to return all subsets of a set. The elements in a set are pairwise distinct.

    Note: The result set should not contain duplicated subsets.

    - -

    Example:

    - -
     
      Input:  nums = [1,2,3]
    @@ -43,12 +38,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -64,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.05.Recursive Mulitply/README.md b/lcci/08.05.Recursive Mulitply/README.md index 2d99c79302cfd..db0e67ec277d9 100644 --- a/lcci/08.05.Recursive Mulitply/README.md +++ b/lcci/08.05.Recursive Mulitply/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.05.Recursive%20Mulitply/README_EN.md) ## 题目描述 +

    递归乘法。 写一个递归函数,不使用 * 运算符, 实现两个正整数的相乘。可以使用加号、减号、位移,但要吝啬一些。

    @@ -26,14 +27,14 @@
  • 保证乘法范围不会溢出
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.05.Recursive Mulitply/README_EN.md b/lcci/08.05.Recursive Mulitply/README_EN.md index 5ac5043166a0f..5bf5620201b3c 100644 --- a/lcci/08.05.Recursive Mulitply/README_EN.md +++ b/lcci/08.05.Recursive Mulitply/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.05.Recursive%20Mulitply/README.md) ## Description -

    Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations.

    - +

    Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations.

    Example 1:

    - -
     
      Input: A = 1, B = 10
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
      Input: A = 3, B = 4
    @@ -33,22 +26,14 @@
     
     
    - -

    Note:

    - -
    1. The result will not overflow.
    - - - ## Solutions - ### **Python3** @@ -64,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.06.Hanota/README.md b/lcci/08.06.Hanota/README.md index a539956405481..1c8ecbbd3e36b 100644 --- a/lcci/08.06.Hanota/README.md +++ b/lcci/08.06.Hanota/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.06.Hanota/README_EN.md) ## 题目描述 +

    在经典汉诺塔问题中,有 3 根柱子及 N 个不同大小的穿孔圆盘,盘子可以滑入任意一根柱子。一开始,所有盘子自上而下按升序依次套在第一根柱子上(即每一个盘子只能放在更大的盘子上面)。移动圆盘时受到以下限制:
    (1) 每次只能移动一个盘子;
    @@ -31,14 +32,14 @@

  • A中盘子的数目不大于14个。
  • - ## 解法 - + ### **Python3** + ```python @@ -46,6 +47,7 @@ ``` ### **Java** + ```java @@ -53,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.06.Hanota/README_EN.md b/lcci/08.06.Hanota/README_EN.md index 684ed2c635789..f66b2a5919243 100644 --- a/lcci/08.06.Hanota/README_EN.md +++ b/lcci/08.06.Hanota/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/lcci/08.06.Hanota/README.md) ## Description -

    In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:

    - +

    In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:

    (1) Only one disk can be moved at a time.
    @@ -13,16 +12,10 @@ (3) A disk cannot be placed on top of a smaller disk.

    - -

    Write a program to move the disks from the first tower to the last using stacks.

    - -

    Example1:

    - -
     
      Input: A = [2, 1, 0], B = [], C = []
    @@ -31,12 +24,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: A = [1, 0], B = [], C = []
    @@ -45,22 +34,14 @@
     
     
    - -

    Note:

    - -
    1. A.length <= 14
    - - - ## Solutions - ### **Python3** @@ -76,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.07.Permutation I/README.md b/lcci/08.07.Permutation I/README.md index 8f04bb58d3ad1..604b675e3af70 100644 --- a/lcci/08.07.Permutation I/README.md +++ b/lcci/08.07.Permutation I/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.07.Permutation%20I/README_EN.md) ## 题目描述 +

    无重复字符串的排列组合。编写一种方法,计算某字符串的所有排列组合,字符串每个字符均不相同。

    @@ -27,14 +28,14 @@
  • 字符串长度在[1, 9]之间。
  • - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.07.Permutation I/README_EN.md b/lcci/08.07.Permutation I/README_EN.md index 60f13fc841ee9..8d0be82e1aecf 100644 --- a/lcci/08.07.Permutation I/README_EN.md +++ b/lcci/08.07.Permutation I/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.07.Permutation%20I/README.md) ## Description -

    Write a method to compute all permutations of a string of unique characters.

    - +

    Write a method to compute all permutations of a string of unique characters.

    Example1:

    - -
     
      Input: S = "qwe"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: S = "ab"
    @@ -33,23 +26,15 @@
     
     
    - -

    Note:

    - -
    1. All charaters are English letters.
    2. 1 <= S.length <= 9
    - - - ## Solutions - ### **Python3** @@ -65,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.08.Permutation II/README.md b/lcci/08.08.Permutation II/README.md index b764ca1ccda27..dacfda61b913b 100644 --- a/lcci/08.08.Permutation II/README.md +++ b/lcci/08.08.Permutation II/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.08.Permutation%20II/README_EN.md) ## 题目描述 +

    有重复字符串的排列组合。编写一种方法,计算某字符串的所有排列组合。

    @@ -25,14 +26,14 @@
  • 字符串长度在[1, 9]之间。
  • - ## 解法 - + ### **Python3** + ```python @@ -40,6 +41,7 @@ ``` ### **Java** + ```java @@ -47,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.08.Permutation II/README_EN.md b/lcci/08.08.Permutation II/README_EN.md index 1d10e5673afaa..86430a473f316 100644 --- a/lcci/08.08.Permutation II/README_EN.md +++ b/lcci/08.08.Permutation II/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.08.Permutation%20II/README.md) ## Description -

    Write a method to compute all permutations of a string whose charac­ ters are not necessarily unique. The list of permutations should not have duplicates.

    - +

    Write a method to compute all permutations of a string whose charac­ ters are not necessarily unique. The list of permutations should not have duplicates.

    Example1:

    - -
     
      Input: S = "qqe"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: S = "ab"
    @@ -33,23 +26,15 @@
     
     
    - -

    Note:

    - -
    1. All characters are English letters.
    2. 1 <= S.length <= 9
    - - - ## Solutions - ### **Python3** @@ -65,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.09.Bracket/README.md b/lcci/08.09.Bracket/README.md index caf1921e32572..a291d4b1a4f02 100644 --- a/lcci/08.09.Bracket/README.md +++ b/lcci/08.09.Bracket/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.09.Bracket/README_EN.md) ## 题目描述 +

    括号。设计一种算法,打印n对括号的所有合法的(例如,开闭一一对应)组合。

    @@ -20,15 +21,16 @@ ] - ## 解法 - + ### **Python3** + + 递归求解。其中,`left` 表示剩余的 `(`,`right` 表示剩余的 `)`。 - 当 `left` > `right` 时,说明 state 中 `(` 少于 `)`,不是合法组合,直接剪枝; @@ -36,7 +38,6 @@ - 当 `left` > 0 时,此时可往 state 添加一个 `(`; - 当 `right` > 0 时,此时可往 state 添加一个 `)`。 - ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -57,6 +58,7 @@ class Solution: ``` ### **Java** + ```java @@ -88,8 +90,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.09.Bracket/README_EN.md b/lcci/08.09.Bracket/README_EN.md index c135bd340eabb..5caf97cc420c7 100644 --- a/lcci/08.09.Bracket/README_EN.md +++ b/lcci/08.09.Bracket/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.09.Bracket/README.md) ## Description -

    Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses.

    - +

    Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses.

    Note: The result set should not contain duplicated subsets.

    - -

    For example, given n = 3, the result should be:

    - -
     
     [
    @@ -33,12 +28,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -92,8 +83,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.10.Color Fill/README.md b/lcci/08.10.Color Fill/README.md index 5bad11db6057b..6973a51f58a59 100644 --- a/lcci/08.10.Color Fill/README.md +++ b/lcci/08.10.Color Fill/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.10.Color%20Fill/README_EN.md) ## 题目描述 +

    颜色填充。编写函数,实现许多图片编辑软件都支持的“颜色填充”功能。给定一个屏幕(以二维数组表示,元素为颜色值)、一个点和一个新的颜色值,将新颜色值填入这个点的周围区域,直到原来的颜色值全都改变。

    @@ -28,14 +29,14 @@ sr = 1, sc = 1, newColor = 2
  • image[i][j] 和 newColor 表示的颜色值在范围 [0, 65535]内。
  • - ## 解法 - + ### **Python3** + ```python @@ -43,6 +44,7 @@ sr = 1, sc = 1, newColor = 2 ``` ### **Java** + ```java @@ -72,8 +74,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.10.Color Fill/README_EN.md b/lcci/08.10.Color Fill/README_EN.md index e2c329216e21f..743b458aab9d8 100644 --- a/lcci/08.10.Color Fill/README_EN.md +++ b/lcci/08.10.Color Fill/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.10.Color%20Fill/README.md) ## Description -

    Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.

    - +

    Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.

    Example1:

    - -
     
     Input: 
    @@ -31,24 +28,16 @@ Note the bottom corner is not colored 2, because it is not 4-directionally conne
     
     to the starting pixel.
    - -

    Note:

    - -
    • The length of image and image[0] will be in the range [1, 50].
    • The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
    • The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
    - - - ## Solutions - ### **Python3** @@ -86,8 +75,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.11.Coin/README.md b/lcci/08.11.Coin/README.md index fad7304907bef..d4a70055defe0 100644 --- a/lcci/08.11.Coin/README.md +++ b/lcci/08.11.Coin/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.11.Coin/README_EN.md) ## 题目描述 +

    硬币。给定数量不限的硬币,币值为25分、10分、5分和1分,编写代码计算n分有几种表示法。(结果可能会很大,你需要将结果模上1000000007)

    @@ -38,14 +39,14 @@
  • 0 <= n (总金额) <= 1000000
  • - ## 解法 - + ### **Python3** + ```python @@ -53,6 +54,7 @@ ``` ### **Java** + ```java @@ -60,8 +62,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.11.Coin/README_EN.md b/lcci/08.11.Coin/README_EN.md index 6ef807c6df871..884007d203754 100644 --- a/lcci/08.11.Coin/README_EN.md +++ b/lcci/08.11.Coin/README_EN.md @@ -3,13 +3,11 @@ [中文文档](/lcci/08.11.Coin/README.md) ## Description -

    Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should return it modulo 1000000007)

    - +

    Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should return it modulo 1000000007)

    Example1:

    -
     
      Input: n = 5
    @@ -24,12 +22,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: n = 10
    @@ -48,26 +42,16 @@
     
     
    - -

    Notes:

    - -

    You can assume:

    - -
    • 0 <= n <= 1000000
    - - - ## Solutions - ### **Python3** @@ -83,8 +67,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.12.Eight Queens/README.md b/lcci/08.12.Eight Queens/README.md index ab5318c89c2bc..8fc5a09085d5b 100644 --- a/lcci/08.12.Eight Queens/README.md +++ b/lcci/08.12.Eight Queens/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.12.Eight%20Queens/README_EN.md) ## 题目描述 +

    设计一种算法,打印 N 皇后在 N × N 棋盘上的各种摆法,其中每个皇后都不同行、不同列,也不在对角线上。这里的“对角线”指的是所有的对角线,不只是平分整个棋盘的那两条对角线。

    @@ -26,14 +27,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.12.Eight Queens/README_EN.md b/lcci/08.12.Eight Queens/README_EN.md index c8e9f021fe427..b3d13b07cb99a 100644 --- a/lcci/08.12.Eight Queens/README_EN.md +++ b/lcci/08.12.Eight Queens/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.12.Eight%20Queens/README.md) ## Description -

    Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.

    - +

    Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.

    Notes: This problem is a generalization of the original one in the book.

    - -

    Example:

    - -
     
      Input: 4
    @@ -47,12 +42,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -68,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.13.Pile Box/README.md b/lcci/08.13.Pile Box/README.md index 413d38ba51eed..ee3c3b0ff6c2b 100644 --- a/lcci/08.13.Pile Box/README.md +++ b/lcci/08.13.Pile Box/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.13.Pile%20Box/README_EN.md) ## 题目描述 +

    堆箱子。给你一堆n个箱子,箱子宽 wi、高hi、深di。箱子不能翻转,将箱子堆起来时,下面箱子的宽度、高度和深度必须大于上面的箱子。实现一种方法,搭出最高的一堆箱子。箱堆的高度为每个箱子高度的总和。

    @@ -26,14 +27,14 @@
  • 箱子的数目不大于3000个。
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.13.Pile Box/README_EN.md b/lcci/08.13.Pile Box/README_EN.md index 310e454e32dfa..b1e8173415ece 100644 --- a/lcci/08.13.Pile Box/README_EN.md +++ b/lcci/08.13.Pile Box/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/lcci/08.13.Pile%20Box/README.md) ## Description +

    You have a stack of n boxes, with widths wi, heights hi, and depths di. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implement a method to compute the height of the tallest possible stack. The height of a stack is the sum of the heights of each box.

    The input use [wi, di, hi] to represents each box.

    @@ -19,8 +20,6 @@

    Example2:

    - -
     
      Input: box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]
    @@ -35,12 +34,8 @@
     	
  • box.length <= 3000
  • - - - ## Solutions - ### **Python3** @@ -56,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.14.Boolean Evaluation/README.md b/lcci/08.14.Boolean Evaluation/README.md index 4cdcdbdb1747f..9dd62a490b43a 100644 --- a/lcci/08.14.Boolean Evaluation/README.md +++ b/lcci/08.14.Boolean Evaluation/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.14.Boolean%20Evaluation/README_EN.md) ## 题目描述 +

    给定一个布尔表达式和一个期望的布尔结果 result,布尔表达式由 0 (false)、1 (true)、& (AND)、 | (OR) 和 ^ (XOR) 符号组成。实现一个函数,算出有几种可使该表达式得出 result 值的括号方法。

    @@ -28,14 +29,14 @@
  • 运算符的数量不超过 19 个
  • - ## 解法 - + ### **Python3** + ```python @@ -43,6 +44,7 @@ ``` ### **Java** + ```java @@ -50,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.14.Boolean Evaluation/README_EN.md b/lcci/08.14.Boolean Evaluation/README_EN.md index e755599241788..dd1f135935044 100644 --- a/lcci/08.14.Boolean Evaluation/README_EN.md +++ b/lcci/08.14.Boolean Evaluation/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/08.14.Boolean%20Evaluation/README.md) ## Description -

    Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.

    - +

    Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.

    Example 1:

    - -
     
     Input: s = "1^0|0|1", result = 0
    @@ -27,12 +24,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: s = "0&0&0&1^1|0", result = 1
    @@ -41,20 +34,14 @@
     
     Output: 10
    - -

    Note:

    • There are no more than 19 operators in s.
    - - - ## Solutions - ### **Python3** @@ -70,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.01.Sorted Merge/README.md b/lcci/10.01.Sorted Merge/README.md index b7644f9187e23..dad7ace51f10c 100644 --- a/lcci/10.01.Sorted Merge/README.md +++ b/lcci/10.01.Sorted Merge/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.01.Sorted%20Merge/README_EN.md) ## 题目描述 +

    给定两个排序后的数组 A 和 B,其中 A 的末端有足够的缓冲空间容纳 B。 编写一个方法,将 B 合并入 A 并排序。

    @@ -22,14 +23,14 @@ B = [2,5,6], n = 3
  • A.length == n + m
  • - ## 解法 - + ### **Python3** + ```python @@ -37,6 +38,7 @@ B = [2,5,6], n = 3 ``` ### **Java** + ```java @@ -44,8 +46,9 @@ B = [2,5,6], n = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.01.Sorted Merge/README_EN.md b/lcci/10.01.Sorted Merge/README_EN.md index 52baae15e39b2..303a026e1c5ab 100644 --- a/lcci/10.01.Sorted Merge/README_EN.md +++ b/lcci/10.01.Sorted Merge/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/10.01.Sorted%20Merge/README.md) ## Description -

    You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.

    - +

    You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.

    Initially the number of elements in A and B are m and n respectively.

    - -

    Example:

    - -
     
     Input:
    @@ -27,12 +22,8 @@ B = [2,5,6],       n = 3
     
     Output: [1,2,2,3,5,6]
    - - - ## Solutions - ### **Python3** @@ -48,8 +39,9 @@ B = [2,5,6], n = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.02.Group Anagrams/README.md b/lcci/10.02.Group Anagrams/README.md index f9b57de870bc2..23c2edaa735a2 100644 --- a/lcci/10.02.Group Anagrams/README.md +++ b/lcci/10.02.Group Anagrams/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.02.Group%20Anagrams/README_EN.md) ## 题目描述 +

    编写一种方法,对字符串数组进行排序,将所有变位词组合在一起。变位词是指字母相同,但排列不同的字符串。

    @@ -25,14 +26,14 @@
  • 不考虑答案输出的顺序。
  • - ## 解法 - + ### **Python3** + ```python @@ -40,6 +41,7 @@ ``` ### **Java** + ```java @@ -47,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.02.Group Anagrams/README_EN.md b/lcci/10.02.Group Anagrams/README_EN.md index 60aa58293089c..55e9e777f342a 100644 --- a/lcci/10.02.Group Anagrams/README_EN.md +++ b/lcci/10.02.Group Anagrams/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/10.02.Group%20Anagrams/README.md) ## Description -

    Write a method to sort an array of strings so that all the anagrams are in the same group.

    - +

    Write a method to sort an array of strings so that all the anagrams are in the same group.

    Note: This problem is slightly different from the original one the book.

    - -

    Example:

    - -
     
     Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
    @@ -31,23 +26,15 @@
     
     ]
    - -

    Notes:

    - -
    • All inputs will be in lowercase.
    • The order of your output does not matter.
    - - - ## Solutions - ### **Python3** @@ -63,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.03.Search Rotate Array/README.md b/lcci/10.03.Search Rotate Array/README.md index 0c03ac514457d..766fa95dcd4e4 100644 --- a/lcci/10.03.Search Rotate Array/README.md +++ b/lcci/10.03.Search Rotate Array/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) ## 题目描述 +

    搜索旋转数组。给定一个排序后的数组,包含n个整数,但这个数组已被旋转过很多次了,次数不详。请编写代码找出数组中的某个元素,假设数组元素原先是按升序排列的。若有多个相同元素,返回索引值最小的一个。

    @@ -24,14 +25,14 @@
  • arr 长度范围在[1, 1000000]之间
  • - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ ``` ### **Java** + ```java @@ -46,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.03.Search Rotate Array/README_EN.md b/lcci/10.03.Search Rotate Array/README_EN.md index cfb060c1d05e3..dc8df32c120dd 100644 --- a/lcci/10.03.Search Rotate Array/README_EN.md +++ b/lcci/10.03.Search Rotate Array/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/10.03.Search%20Rotate%20Array/README.md) ## Description -

    Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. If there are more than one target elements in the array, return the smallest index.

    - +

    Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. If there are more than one target elements in the array, return the smallest index.

    Example1:

    - -
     
      Input: arr = [15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14], target = 5
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: arr = [15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14], target = 11
    @@ -33,20 +26,14 @@
     
     
    - -

    Note:

    1. 1 <= arr.length <= 1000000
    - - - ## Solutions - ### **Python3** @@ -62,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.05.Sparse Array Search/README.md b/lcci/10.05.Sparse Array Search/README.md index 8165f006f27fa..aee4b30ac03a7 100644 --- a/lcci/10.05.Sparse Array Search/README.md +++ b/lcci/10.05.Sparse Array Search/README.md @@ -3,6 +3,7 @@ [中文文档](/lcci/10.05.Sparse%20Array%20Search/README.md) ## 题目描述 +

    稀疏数组搜索。有个排好序的字符串数组,其中散布着一些空字符串,编写一种方法,找出给定字符串的位置。

    @@ -25,14 +26,14 @@
  • words的长度在[1, 1000000]之间
  • - ## 解法 - + ### **Python3** + ```python @@ -40,6 +41,7 @@ ``` ### **Java** + ```java @@ -47,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.05.Sparse Array Search/README_EN.md b/lcci/10.05.Sparse Array Search/README_EN.md index 8b125cd29a812..30e2bf21294c2 100644 --- a/lcci/10.05.Sparse Array Search/README_EN.md +++ b/lcci/10.05.Sparse Array Search/README_EN.md @@ -1,14 +1,11 @@ # [10.05. Sparse Array Search](https://leetcode-cn.com/problems/sparse-array-search-lcci) ## Description -

    Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string.

    - +

    Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string.

    Example1:

    - -
     
      Input: words = ["at", "", "", "", "ball", "", "", "car", "", "","dad", "", ""], s = "ta"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example2:

    - -
     
      Input: words = ["at", "", "", "", "ball", "", "", "car", "", "","dad", "", ""], s = "ball"
    @@ -33,21 +26,14 @@
     
     
    - -

    Note:

    -
    1. 1 <= words.length <= 1000000
    - - - ## Solutions - ### **Python3** @@ -63,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.09.Sorted Matrix Search/README.md b/lcci/10.09.Sorted Matrix Search/README.md index 9281363b6668e..6bc86851d3768 100644 --- a/lcci/10.09.Sorted Matrix Search/README.md +++ b/lcci/10.09.Sorted Matrix Search/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) ## 题目描述 +

    给定M×N矩阵,每一行、每一列都按升序排列,请编写代码找出某元素。

    @@ -23,14 +24,16 @@

    给定 target = 20,返回 false

    - ## 解法 + + 从左下角(或右上角)开始查找即可。 ### **Python3** + ```python @@ -52,6 +55,7 @@ class Solution: ``` ### **Java** + ```java @@ -78,8 +82,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.09.Sorted Matrix Search/README_EN.md b/lcci/10.09.Sorted Matrix Search/README_EN.md index 1aa0606c88d9f..5f7eb85e7315d 100644 --- a/lcci/10.09.Sorted Matrix Search/README_EN.md +++ b/lcci/10.09.Sorted Matrix Search/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/10.09.Sorted%20Matrix%20Search/README.md) ## Description -

    Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element.

    - +

    Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element.

    Example:

    - -

    Given matrix:

    - -
     
     [
    @@ -33,20 +28,12 @@
     
     
    - -

    Given target = 5, return true.

    - -

    Given target = 20, return false.

    - - - ## Solutions - ### **Python3** @@ -95,8 +82,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.10.Rank from Stream/README.md b/lcci/10.10.Rank from Stream/README.md index ef26be4d69b9a..02e6c0b55675b 100644 --- a/lcci/10.10.Rank from Stream/README.md +++ b/lcci/10.10.Rank from Stream/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.10.Rank%20from%20Stream/README_EN.md) ## 题目描述 +

    假设你正在读取一串整数。每隔一段时间,你希望能找出数字 x 的秩(小于或等于 x 的值的个数)。请实现数据结构和算法来支持这些操作,也就是说:

    @@ -28,14 +29,14 @@
  • track 和 getRankOfNumber 方法的调用次数均不超过 2000 次
  • - ## 解法 - + ### **Python3** + ```python @@ -43,6 +44,7 @@ ``` ### **Java** + ```java @@ -50,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.10.Rank from Stream/README_EN.md b/lcci/10.10.Rank from Stream/README_EN.md index 48f8b7b9b3e9e..c77a89e787b62 100644 --- a/lcci/10.10.Rank from Stream/README_EN.md +++ b/lcci/10.10.Rank from Stream/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/10.10.Rank%20from%20Stream/README.md) ## Description -

    Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to x). lmplement the data structures and algorithms to support these operations. That is, implement the method track (int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x.

    - +

    Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to x). lmplement the data structures and algorithms to support these operations. That is, implement the method track (int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x.

    Note: This problem is slightly different from the original one in the book.

    - -

    Example:

    - -
     
     Input:
    @@ -29,21 +24,15 @@
     
     
    - -

    Note:

    - -
    • x <= 50000
    • The number of calls of both track and getRankOfNumber methods are less than or equal to 2000.
    - ## Solutions - ### **Python3** @@ -59,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.11.Peaks and Valleys/README.md b/lcci/10.11.Peaks and Valleys/README.md index 4524631cb45b0..527283e2e5f86 100644 --- a/lcci/10.11.Peaks and Valleys/README.md +++ b/lcci/10.11.Peaks and Valleys/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) ## 题目描述 +

    在一个整数数组中,“峰”是大于或等于相邻整数的元素,相应地,“谷”是小于或等于相邻整数的元素。例如,在数组{5, 8, 6, 2, 3, 4, 6}中,{8, 6}是峰, {5, 2}是谷。现在给定一个整数数组,将该数组按峰与谷的交替顺序排序。

    @@ -18,14 +19,14 @@
  • nums.length <= 10000
  • - ## 解法 - + ### **Python3** + ```python @@ -33,6 +34,7 @@ ``` ### **Java** + ```java @@ -40,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.11.Peaks and Valleys/README_EN.md b/lcci/10.11.Peaks and Valleys/README_EN.md index 72c7f4a5519f1..f0e2745667e62 100644 --- a/lcci/10.11.Peaks and Valleys/README_EN.md +++ b/lcci/10.11.Peaks and Valleys/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/10.11.Peaks%20and%20Valleys/README.md) ## Description -

    In an array of integers, a "peak" is an element which is greater than or equal to the adjacent integers and a "valley" is an element which is less than or equal to the adjacent inte­gers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.

    - +

    In an array of integers, a "peak" is an element which is greater than or equal to the adjacent integers and a "valley" is an element which is less than or equal to the adjacent inte­gers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.

    Example:

    - -
     
     Input: [5, 3, 1, 2, 3]
    @@ -19,20 +16,14 @@
     
     
    - -

    Note:

    • nums.length <= 10000
    - - - ## Solutions - ### **Python3** @@ -48,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.01.Swap Numbers/README.md b/lcci/16.01.Swap Numbers/README.md index d5dc27202e8aa..63b33ff7f1ea1 100644 --- a/lcci/16.01.Swap Numbers/README.md +++ b/lcci/16.01.Swap Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.01.Swap%20Numbers/README_EN.md) ## 题目描述 +

    编写一个函数,不用临时变量,直接交换numbers = [a, b]ab的值。

    示例:

    @@ -14,14 +15,16 @@
  • numbers.length == 2
  • - ## 解法 + + 异或运算。 ### **Python3** + ```python @@ -32,6 +35,7 @@ class Solution: ``` ### **Java** + ```java @@ -46,8 +50,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.01.Swap Numbers/README_EN.md b/lcci/16.01.Swap Numbers/README_EN.md index 128704ed127eb..46af646fee594 100644 --- a/lcci/16.01.Swap Numbers/README_EN.md +++ b/lcci/16.01.Swap Numbers/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.01.Swap%20Numbers/README.md) ## Description -

    Write a function to swap a number in place (that is, without temporary vari­ ables).

    - +

    Write a function to swap a number in place (that is, without temporary vari­ ables).

    Example:

    - -
     
     Input: numbers = [1,2]
    @@ -19,22 +16,14 @@
     
     
    - -

    Note:

    - -
    • numbers.length == 2
    - - - ## Solutions - ### **Python3** @@ -60,8 +49,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.02.Words Frequency/README.md b/lcci/16.02.Words Frequency/README.md index f00612d2fc75c..6321ea6faeb8b 100644 --- a/lcci/16.02.Words Frequency/README.md +++ b/lcci/16.02.Words Frequency/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.02.Words%20Frequency/README_EN.md) ## 题目描述 +

    设计一个方法,找出任意指定单词在一本书中的出现频率。

    你的实现应该支持如下操作:

    @@ -26,14 +27,14 @@ wordsFrequency.get("pen"); //返回1
  • get函数的调用次数不会超过100000
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ wordsFrequency.get("pen"); //返回1 ``` ### **Java** + ```java @@ -48,8 +50,9 @@ wordsFrequency.get("pen"); //返回1 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.02.Words Frequency/README_EN.md b/lcci/16.02.Words Frequency/README_EN.md index 9a3599fe47f9f..1c858bc13c2b0 100644 --- a/lcci/16.02.Words Frequency/README_EN.md +++ b/lcci/16.02.Words Frequency/README_EN.md @@ -3,25 +3,18 @@ [中文文档](/lcci/16.02.Words%20Frequency/README.md) ## Description -

    Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?

    - +

    Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?

    You should implement following methods:

    - -
    • WordsFrequency(book) constructor, parameter is a array of strings, representing the book.
    • get(word) get the frequency of word in the book. 
    - -

    Example:

    - -
     
     WordsFrequency wordsFrequency = new WordsFrequency({"i", "have", "an", "apple", "he", "have", "a", "pen"});
    @@ -38,30 +31,22 @@ wordsFrequency.get("pen"); //returns 1
     
     
    - -

    Note:

    - -
      -
    • There are only lowercase letters in book[i].
    • +
    • There are only lowercase letters in book[i].
    • -
    • 1 <= book.length <= 100000
    • +
    • 1 <= book.length <= 100000
    • -
    • 1 <= book[i].length <= 10
    • +
    • 1 <= book[i].length <= 10
    • -
    • get function will not be called more than 100000 times.
    • +
    • get function will not be called more than 100000 times.
    - - - ## Solutions - ### **Python3** @@ -77,8 +62,9 @@ wordsFrequency.get("pen"); //returns 1 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.03.Intersection/README.md b/lcci/16.03.Intersection/README.md index 8b2860da2f6a9..58fbd0e7bc216 100644 --- a/lcci/16.03.Intersection/README.md +++ b/lcci/16.03.Intersection/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.03.Intersection/README_EN.md) ## 题目描述 +

    给定两条线段(表示为起点start = {X1, Y1}和终点end = {X2, Y2}),如果它们有交点,请计算其交点,没有交点则返回空值。

    要求浮点型误差不超过10^-6。若有多个交点(线段重叠)则返回X值最小的点,X坐标相同则返回Y值最小的点。

    @@ -30,14 +31,14 @@ line2 = {1, 0}, {2, 1}
  • 输入的坐标均是有效的二维坐标
  • - ## 解法 - + ### **Python3** + ```python @@ -45,6 +46,7 @@ line2 = {1, 0}, {2, 1} ``` ### **Java** + ```java @@ -52,8 +54,9 @@ line2 = {1, 0}, {2, 1} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.03.Intersection/README_EN.md b/lcci/16.03.Intersection/README_EN.md index 84a50cf35a9af..7919de4b09aab 100644 --- a/lcci/16.03.Intersection/README_EN.md +++ b/lcci/16.03.Intersection/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/16.03.Intersection/README.md) ## Description +

    Given two straight line segments (represented as a start point and an end point), compute the point of intersection, if any. If there's no intersection, return an empty array.

    The absolute error should not exceed 10^-6. If there are more than one intersections, return the one with smallest X axis value. If there are more than one intersections that have same X axis value, return the one with smallest Y axis value. - -

    Example 1:

    - -
     
     Input: 
    @@ -25,12 +22,8 @@ line2 = {1, 1}, {0, -1}
     
     
    - -

    Example 2:

    - -
     
     Input: 
    @@ -43,12 +36,8 @@ line2 = {1, 1}, {2, 2}
     
     
    - -

    Example 3:

    - -
     
     Input: 
    @@ -61,23 +50,15 @@ line2 = {1, 0}, {2, 1}
     
     
    - -

    Note:

    - -
    • The absolute value of coordinate value will not exceed 2^7.
    • All coordinates are valid 2D coordinates.
    - - - ## Solutions - ### **Python3** @@ -93,8 +74,9 @@ line2 = {1, 0}, {2, 1} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.04.Tic-Tac-Toe/README.md b/lcci/16.04.Tic-Tac-Toe/README.md index a8a613bcf00d5..5c31e75bde6e6 100644 --- a/lcci/16.04.Tic-Tac-Toe/README.md +++ b/lcci/16.04.Tic-Tac-Toe/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.04.Tic-Tac-Toe/README_EN.md) ## 题目描述 +

    设计一个算法,判断玩家是否赢了井字游戏。输入是一个 N x N 的数组棋盘,由字符" ","X"和"O"组成,其中字符" "代表一个空位。

    @@ -46,14 +47,14 @@
  • 输入一定遵循井字棋规则
  • - ## 解法 - + ### **Python3** + ```python @@ -61,6 +62,7 @@ ``` ### **Java** + ```java @@ -68,8 +70,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.04.Tic-Tac-Toe/README_EN.md b/lcci/16.04.Tic-Tac-Toe/README_EN.md index d8e26046efc1d..088361dee4586 100644 --- a/lcci/16.04.Tic-Tac-Toe/README_EN.md +++ b/lcci/16.04.Tic-Tac-Toe/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.04.Tic-Tac-Toe/README.md) ## Description -

    Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.

    - +

    Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.

    The rules of tic-tac-toe are as follows:

    - -
    • Players place characters into an empty grid(" ") in turn.
    • The first player always place character "O", and the second one place "X".
    • @@ -20,16 +17,10 @@
    • If the game ends, players cannot place any character further.
    - -

    If there is any winner, return the character that the winner used. If there's a draw, return "Draw". If the game doesn't end and there is no winner, return "Pending".

    - -

    Example 1:

    - -
     
     Input:  board = ["O X"," XO","X O"]
    @@ -38,12 +29,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:  board = ["OOX","XXO","OXO"]
    @@ -54,12 +41,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input:  board = ["OOX","XXO","OX "]
    @@ -70,23 +53,15 @@
     
     
    - -

    Note:

    - -
    • 1 <= board.length == board[i].length <= 100
    • Input follows the rules.
    - - - ## Solutions - ### **Python3** @@ -102,8 +77,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.05.Factorial Zeros/README.md b/lcci/16.05.Factorial Zeros/README.md index e21904fd42ab1..38d7daef21659 100644 --- a/lcci/16.05.Factorial Zeros/README.md +++ b/lcci/16.05.Factorial Zeros/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.05.Factorial%20Zeros/README_EN.md) ## 题目描述 +

    设计一个算法,算出 n 阶乘有多少个尾随零。

    @@ -20,14 +21,14 @@

    说明: 你算法的时间复杂度应为 O(log n) 

    - ## 解法 - + ### **Python3** + ```python @@ -35,6 +36,7 @@ ``` ### **Java** + ```java @@ -42,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.05.Factorial Zeros/README_EN.md b/lcci/16.05.Factorial Zeros/README_EN.md index 8bae56b4ac752..5321bee114b68 100644 --- a/lcci/16.05.Factorial Zeros/README_EN.md +++ b/lcci/16.05.Factorial Zeros/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.05.Factorial%20Zeros/README.md) ## Description -

    Write an algorithm which computes the number of trailing zeros in n factorial.

    - +

    Write an algorithm which computes the number of trailing zeros in n factorial.

    Example 1:

    - -
     
     Input: 3
    @@ -19,12 +16,8 @@
     
     Explanation: 3! = 6, no trailing zero.
    - -

    Example 2:

    - -
     
     Input: 5
    @@ -33,16 +26,10 @@
     
     Explanation: 5! = 120, one trailing zero.
    - -

    Note: Your solution should be in logarithmic time complexity.

    - - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.06.Smallest Difference/README.md b/lcci/16.06.Smallest Difference/README.md index dcdd323961aef..095a40953c318 100644 --- a/lcci/16.06.Smallest Difference/README.md +++ b/lcci/16.06.Smallest Difference/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.06.Smallest%20Difference/README_EN.md) ## 题目描述 +

    给定两个整数数组ab,计算具有最小差绝对值的一对数值(每个数组中取一个值),并返回该对数值的差

    示例:

    @@ -16,14 +17,14 @@
  • 正确结果在区间[-2147483648, 2147483647]内
  • - ## 解法 - + ### **Python3** + ```python @@ -39,10 +40,11 @@ class Solution: if a[i] > b[j]: j += 1 else: i += 1 return res - + ``` ### **Java** + ```java @@ -65,8 +67,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.06.Smallest Difference/README_EN.md b/lcci/16.06.Smallest Difference/README_EN.md index f974dd1b6a736..fb2b2b84994d5 100644 --- a/lcci/16.06.Smallest Difference/README_EN.md +++ b/lcci/16.06.Smallest Difference/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.06.Smallest%20Difference/README.md) ## Description -

    Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference.

    - +

    Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference.

    Example:

    - -
     
     Input: {1, 3, 15, 11, 2}, {23, 127, 235, 19, 8}
    @@ -19,24 +16,16 @@
     
     
    - -

    Note:

    - -
    • 1 <= a.length, b.length <= 100000
    • -2147483648 <= a[i], b[i] <= 2147483647
    • The result is in the range [-2147483648, 2147483647]
    - - - ## Solutions - ### **Python3** @@ -54,7 +43,7 @@ class Solution: if a[i] > b[j]: j += 1 else: i += 1 return res - + ``` ### **Java** @@ -79,8 +68,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.07.Maximum/README.md b/lcci/16.07.Maximum/README.md index 3d0ff2315fc6b..382b9e47e718c 100644 --- a/lcci/16.07.Maximum/README.md +++ b/lcci/16.07.Maximum/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.07.Maximum/README_EN.md) ## 题目描述 +

    编写一个方法,找出两个数字ab中最大的那一个。不得使用if-else或其他比较运算符。

    示例:

    @@ -10,14 +11,14 @@ 输出: 2
    - ## 解法 - + ### **Python3** + ```python @@ -25,6 +26,7 @@ ``` ### **Java** + ```java @@ -32,8 +34,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.07.Maximum/README_EN.md b/lcci/16.07.Maximum/README_EN.md index 12d35005e26a9..383dccaa3619e 100644 --- a/lcci/16.07.Maximum/README_EN.md +++ b/lcci/16.07.Maximum/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.07.Maximum/README.md) ## Description -

    Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.

    - +

    Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.

    Example:

    - -
     
     Input:  a = 1, b = 2
    @@ -19,12 +16,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.08.English Int/README.md b/lcci/16.08.English Int/README.md index 3ee7b199a0ce0..190d0c85176ac 100644 --- a/lcci/16.08.English Int/README.md +++ b/lcci/16.08.English Int/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.08.English%20Int/README_EN.md) ## 题目描述 +

    给定一个整数,打印该整数的英文描述。

    @@ -27,14 +28,14 @@
    输入: 1234567891
     输出: "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"
    - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.08.English Int/README_EN.md b/lcci/16.08.English Int/README_EN.md index 9b31609ed807b..36cbf4a929af1 100644 --- a/lcci/16.08.English Int/README_EN.md +++ b/lcci/16.08.English Int/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.08.English%20Int/README.md) ## Description -

    Given any integer, print an English phrase that describes the integer (e.g., "One Thousand Two Hundred Thirty Four").

    - +

    Given any integer, print an English phrase that describes the integer (e.g., "One Thousand Two Hundred Thirty Four").

    Example 1:

    - -
     
     Input: 123
    @@ -19,48 +16,32 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 12345
     
     Output: "Twelve Thousand Three Hundred Forty Five"
    - -

    Example 3:

    - -
     
     Input: 1234567
     
     Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
    - -

    Example 4:

    - -
     
     Input: 1234567891
     
     Output: "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"
    - - - ## Solutions - ### **Python3** @@ -76,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.09.Operations/README.md b/lcci/16.09.Operations/README.md index 8152f83e63451..26e90abdf3666 100644 --- a/lcci/16.09.Operations/README.md +++ b/lcci/16.09.Operations/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.09.Operations/README_EN.md) ## 题目描述 +

    请实现整数数字的乘法、减法和除法运算,运算结果均为整数数字,程序中只允许使用加法运算符和逻辑运算符,允许程序中出现正负常数,不允许使用位运算。

    你的实现应该支持如下操作:

    @@ -24,14 +25,14 @@ operations.divide(5, -2); //返回-2
  • 单个用例的函数调用次数不会超过1000次
  • - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ operations.divide(5, -2); //返回-2 ``` ### **Java** + ```java @@ -46,8 +48,9 @@ operations.divide(5, -2); //返回-2 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.09.Operations/README_EN.md b/lcci/16.09.Operations/README_EN.md index b1db6f31b1e07..43b4c78a75d55 100644 --- a/lcci/16.09.Operations/README_EN.md +++ b/lcci/16.09.Operations/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.09.Operations/README.md) ## Description -

    rite methods to implement the multiply, subtract, and divide operations for integers. The results of all of these are integers. Use only the add operator.

    - +

    rite methods to implement the multiply, subtract, and divide operations for integers. The results of all of these are integers. Use only the add operator.

    You should implement following methods:

    - -
    • Operations()  constructor
    • minus(a, b)  Subtraction, returns a - b
    • @@ -18,12 +15,8 @@
    • divide(a, b)  Division, returns a / b
    - -

    Example:

    - -
     
     Operations operations = new Operations();
    @@ -36,26 +29,18 @@ operations.divide(5, -2); //returns -2
     
     
    - -

    Note:

    - -
      -
    • You can assume inputs are always valid, that is, e.g., denominator will not be 0 in division.
    • +
    • You can assume inputs are always valid, that is, e.g., denominator will not be 0 in division.
    • -
    • The number of calls will not exceed 1000.
    • +
    • The number of calls will not exceed 1000.
    - - - ## Solutions - ### **Python3** @@ -71,8 +56,9 @@ operations.divide(5, -2); //returns -2 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.10.Living People/README.md b/lcci/16.10.Living People/README.md index 6e4a18db125f5..48d5d20a5d4a5 100644 --- a/lcci/16.10.Living People/README.md +++ b/lcci/16.10.Living People/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.10.Living%20People/README_EN.md) ## 题目描述 +

    给定N个人的出生年份和死亡年份,第i个人的出生年份为birth[i],死亡年份为death[i],实现一个方法以计算生存人数最多的年份。

    你可以假设所有人都出生于1900年至2000年(含1900和2000)之间。如果一个人在某一年的任意时期都处于生存状态,那么他们应该被纳入那一年的统计中。例如,生于1908年、死于1909年的人应当被列入1908年和1909年的计数。

    @@ -19,14 +20,14 @@ death = {1948, 1951, 2000}
  • birth[i] <= death[i]
  • - ## 解法 - + ### **Python3** + ```python @@ -34,6 +35,7 @@ death = {1948, 1951, 2000} ``` ### **Java** + ```java @@ -41,8 +43,9 @@ death = {1948, 1951, 2000} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.10.Living People/README_EN.md b/lcci/16.10.Living People/README_EN.md index 19ec583a508b2..bd62cdfc338ca 100644 --- a/lcci/16.10.Living People/README_EN.md +++ b/lcci/16.10.Living People/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.10.Living%20People/README.md) ## Description -

    Given a list of people with their birth and death years, implement a method to compute the year with the most number of people alive. You may assume that all people were born between 1900 and 2000 (inclusive). If a person was alive during any portion of that year, they should be included in that year's count. For example, Person (birth= 1908, death= 1909) is included in the counts for both 1908 and 1909.

    - +

    Given a list of people with their birth and death years, implement a method to compute the year with the most number of people alive. You may assume that all people were born between 1900 and 2000 (inclusive). If a person was alive during any portion of that year, they should be included in that year's count. For example, Person (birth= 1908, death= 1909) is included in the counts for both 1908 and 1909.

    If there are more than one years that have the most number of people alive, return the smallest one.

    - -

    Example:

    - -
     
     Input: 
    @@ -27,23 +22,15 @@ death = {1948, 1951, 2000}
     
     
    - -

    Note:

    - -
    • 0 < birth.length == death.length <= 10000
    • birth[i] <= death[i]
    - - - ## Solutions - ### **Python3** @@ -59,8 +46,9 @@ death = {1948, 1951, 2000} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.11.Diving Board/README.md b/lcci/16.11.Diving Board/README.md index d3d27ab6bef4d..fad96b8717d65 100644 --- a/lcci/16.11.Diving Board/README.md +++ b/lcci/16.11.Diving Board/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.11.Diving%20Board/README_EN.md) ## 题目描述 +

    你正在使用一堆木板建造跳水板。有两种类型的木板,其中长度较短的木板长度为shorter,长度较长的木板长度为longer。你必须正好使用k块木板。编写一个方法,生成跳水板所有可能的长度。

    返回的长度需要从小到大排列。

    @@ -19,14 +20,14 @@ k = 3
  • 0 <= k <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -34,6 +35,7 @@ k = 3 ``` ### **Java** + ```java @@ -41,8 +43,9 @@ k = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.11.Diving Board/README_EN.md b/lcci/16.11.Diving Board/README_EN.md index 8aa9d31ea7d9e..0ef65fac05142 100644 --- a/lcci/16.11.Diving Board/README_EN.md +++ b/lcci/16.11.Diving Board/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.11.Diving%20Board/README.md) ## Description -

    You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks of wood. Write a method to generate all possible lengths for the diving board.

    - +

    You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks of wood. Write a method to generate all possible lengths for the diving board.

    return all lengths in non-decreasing order.

    - -

    Example:

    - -
     
     Input: 
    @@ -29,23 +24,15 @@ k = 3
     
     
    - -

    Note:

    - -
    • 0 < shorter <= longer
    • 0 <= k <= 100000
    - - - ## Solutions - ### **Python3** @@ -61,8 +48,9 @@ k = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.13.Bisect Squares/README.md b/lcci/16.13.Bisect Squares/README.md index 3bb1d5e5ea72f..a805b78adb467 100644 --- a/lcci/16.13.Bisect Squares/README.md +++ b/lcci/16.13.Bisect Squares/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.13.Bisect%20Squares/README_EN.md) ## 题目描述 +

    给定两个正方形及一个二维平面。请找出将这两个正方形分割成两半的一条直线。假设正方形顶边和底边与 x 轴平行。

    @@ -26,14 +27,14 @@ square2 = {0, -1, 2}
  • square[2] > 0
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ square2 = {0, -1, 2} ``` ### **Java** + ```java @@ -48,8 +50,9 @@ square2 = {0, -1, 2} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.13.Bisect Squares/README_EN.md b/lcci/16.13.Bisect Squares/README_EN.md index e6444ddfc7eb9..67d5587bd89c8 100644 --- a/lcci/16.13.Bisect Squares/README_EN.md +++ b/lcci/16.13.Bisect Squares/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/16.13.Bisect%20Squares/README.md) ## Description -

    Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis.

    - +

    Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis.

    Each square consists of three values, the coordinate of bottom left corner [X,Y] = [square[0],square[1]], and the side length of the square square[2]. The line will intersect to the two squares in four points. Return the coordinates of two intersection points [X1,Y1] and [X2,Y2] that the forming segment covers the other two intersection points in format of {X1,Y1,X2,Y2}. If X1 != X2, there should be X1 < X2, otherwise there should be Y1 <= Y2.

    - -

    If there are more than one line that can cut these two squares in half, return the one that has biggest slope (slope of a line parallel to the y-axis is considered as infinity).

    - -

    Example:

    - -
     
     Input: 
    @@ -33,23 +26,15 @@ square2 = {0, -1, 2}
     
     
    - -

    Note:

    - -
    • square.length == 3
    • square[2] > 0
    - - - ## Solutions - ### **Python3** @@ -65,8 +50,9 @@ square2 = {0, -1, 2} ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.14.Best Line/README.md b/lcci/16.14.Best Line/README.md index f0e5b0ab20920..167b4849dda7c 100644 --- a/lcci/16.14.Best Line/README.md +++ b/lcci/16.14.Best Line/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.14.Best%20Line/README_EN.md) ## 题目描述 +

    给定一个二维平面及平面上的 N 个点列表Points,其中第i个点的坐标为Points[i]=[Xi,Yi]。请找出一条直线,其通过的点的数目最多。

    设穿过最多点的直线所穿过的全部点编号从小到大排序的列表为S,你仅需返回[S[0],S[1]]作为答案,若有多条直线穿过了相同数量的点,则选择S[0]值较小的直线返回,S[0]相同则选择S[1]值较小的直线返回。

    @@ -17,14 +18,14 @@
  • len(Points[i]) = 2
  • - ## 解法 - + ### **Python3** + ```python @@ -32,6 +33,7 @@ ``` ### **Java** + ```java @@ -39,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.14.Best Line/README_EN.md b/lcci/16.14.Best Line/README_EN.md index 123ba4f88d821..13ff1e2e63f22 100644 --- a/lcci/16.14.Best Line/README_EN.md +++ b/lcci/16.14.Best Line/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.14.Best%20Line/README.md) ## Description -

    Given a two-dimensional graph with points on it, find a line which passes the most number of points.

    - +

    Given a two-dimensional graph with points on it, find a line which passes the most number of points.

    Assume all the points that passed by the line are stored in list S sorted by their number. You need to return [S[0], S[1]], that is , two points that have smallest number. If there are more than one line that passes the most number of points, choose the one that has the smallest S[0]. If there are more that one line that has the same S[0], choose the one that has smallest S[1].

    - -

    Example:

    - -
     
     Input:  [[0,0],[1,1],[1,0],[2,0]]
    @@ -25,23 +20,15 @@
     
     
    - -

    Note:

    - -
    • 2 <= len(Points) <= 300
    • len(Points[i]) = 2
    - - - ## Solutions - ### **Python3** @@ -57,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.15.Master Mind/README.md b/lcci/16.15.Master Mind/README.md index 8b9f82cf59a3b..98ebff24bf967 100644 --- a/lcci/16.15.Master Mind/README.md +++ b/lcci/16.15.Master Mind/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.15.Master%20Mind/README_EN.md) ## 题目描述 +

    珠玑妙算游戏(the game of master mind)的玩法如下。

    计算机有4个槽,每个槽放一个球,颜色可能是红色(R)、黄色(Y)、绿色(G)或蓝色(B)。例如,计算机可能有RGGB 4种(槽1为红色,槽2、3为绿色,槽4为蓝色)。作为用户,你试图猜出颜色组合。打个比方,你可能会猜YRGB。要是猜对某个槽的颜色,则算一次“猜中”;要是只猜对颜色但槽位猜错了,则算一次“伪猜中”。注意,“猜中”不能算入“伪猜中”。

    @@ -18,14 +19,14 @@
  • solutionguess仅包含"R","G","B","Y"这4种字符
  • - ## 解法 - + ### **Python3** + ```python @@ -33,6 +34,7 @@ ``` ### **Java** + ```java @@ -40,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.15.Master Mind/README_EN.md b/lcci/16.15.Master Mind/README_EN.md index 8656e1092f3bd..1b561e24d8421 100644 --- a/lcci/16.15.Master Mind/README_EN.md +++ b/lcci/16.15.Master Mind/README_EN.md @@ -3,34 +3,21 @@ [中文文档](/lcci/16.15.Master%20Mind/README.md) ## Description -

    The Game of Master Mind is played as follows:

    - +

    The Game of Master Mind is played as follows:

    The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is red, Slots #2 and #3 are green, Slot #4 is blue).

    - -

    You, the user, are trying to guess the solution. You might, for example, guess YRGB.

    - -

    When you guess the correct color for the correct slot, you get a "hit:' If you guess a color that exists but is in the wrong slot, you get a "pseudo-hit:' Note that a slot that is a hit can never count as a pseudo-hit.

    - -

    For example, if the actual solution is RGBY and you guess GGRR, you have one hit and one pseudo-hit. Write a method that, given a guess and a solution, returns the number of hits and pseudo-hits.

    - -

    Given a sequence of colors solution, and a guess, write a method that return the number of hits and pseudo-hit answer, where answer[0] is the number of hits and answer[1] is the number of pseudo-hit.

    - -

    Example:

    - -
     
     Input:  solution="RGBY",guess="GGRR"
    @@ -41,23 +28,15 @@
     
     
    - -

    Note:

    - -
    • len(solution) = len(guess) = 4
    • There are only "R","G","B","Y" in solution and guess.
    - - - ## Solutions - ### **Python3** @@ -73,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.16.Sub Sort/README.md b/lcci/16.16.Sub Sort/README.md index 41fab028d7183..ccfc8c36152e7 100644 --- a/lcci/16.16.Sub Sort/README.md +++ b/lcci/16.16.Sub Sort/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.15.Master%20Mind/README_EN.md) ## 题目描述 +

    给定一个整数数组,编写一个函数,找出索引mn,只要将索引区间[m,n]的元素排好序,整个数组就是有序的。注意:n-m尽量最小,也就是说,找出符合条件的最短序列。函数返回值为[m,n],若不存在这样的mn(例如整个数组是有序的),请返回[-1,-1]

    示例:

    @@ -14,14 +15,14 @@
  • 0 <= len(array) <= 1000000
  • - ## 解法 - + ### **Python3** + ```python @@ -29,6 +30,7 @@ ``` ### **Java** + ```java @@ -36,8 +38,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.16.Sub Sort/README_EN.md b/lcci/16.16.Sub Sort/README_EN.md index bc67d4f1f9ad9..4539a2d771c39 100644 --- a/lcci/16.16.Sub Sort/README_EN.md +++ b/lcci/16.16.Sub Sort/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.15.Master%20Mind/README.md) ## Description -

    Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence).

    - +

    Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence).

    Return [m,n]. If there are no such m and n (e.g. the array is already sorted), return [-1, -1].

    - -

    Example:

    - -
     
     Input:  [1,2,4,7,10,11,7,12,6,7,16,18,19]
    @@ -23,22 +18,14 @@
     
     
    - -

    Note:

    - -
    • 0 <= len(array) <= 1000000
    - - - ## Solutions - ### **Python3** @@ -54,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.17.Contiguous Sequence/README.md b/lcci/16.17.Contiguous Sequence/README.md index 5a921dc3bef2c..41de82208330c 100644 --- a/lcci/16.17.Contiguous Sequence/README.md +++ b/lcci/16.17.Contiguous Sequence/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.17.Contiguous%20Sequence/README_EN.md) ## 题目描述 +

    给定一个整数数组(有正数有负数),找出总和最大的连续数列,并返回总和。

    @@ -17,14 +18,14 @@

    如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。

    - ## 解法 - + ### **Python3** + ```python @@ -32,6 +33,7 @@ ``` ### **Java** + ```java @@ -39,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.17.Contiguous Sequence/README_EN.md b/lcci/16.17.Contiguous Sequence/README_EN.md index d9a17e1758f43..403565fbeceb0 100644 --- a/lcci/16.17.Contiguous Sequence/README_EN.md +++ b/lcci/16.17.Contiguous Sequence/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.17.Contiguous%20Sequence/README.md) ## Description -

    You are given an array of integers (both positive and negative). Find the contiguous sequence with the largest sum. Return the sum.

    - +

    You are given an array of integers (both positive and negative). Find the contiguous sequence with the largest sum. Return the sum.

    Example:

    - -
     
     Input:  [-2,1,-3,4,-1,2,1,-5,4]
    @@ -21,20 +18,12 @@
     
     
    - -

    Follow Up:

    - -

    If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

    - - - ## Solutions - ### **Python3** @@ -50,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.18.Pattern Matching/README.md b/lcci/16.18.Pattern Matching/README.md index fecbbabe319e4..7785db6d2b738 100644 --- a/lcci/16.18.Pattern Matching/README.md +++ b/lcci/16.18.Pattern Matching/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.18.Pattern%20Matching/README_EN.md) ## 题目描述 +

    你有两个字符串,即patternvaluepattern字符串由字母"a""b"组成,用于描述字符串中的模式。例如,字符串"catcatgocatgo"匹配模式"aabab"(其中"cat""a""go""b"),该字符串也匹配像"a""ab""b"这样的模式。但需注意"a""b"不能同时表示相同的字符串。编写一个方法判断value字符串是否匹配pattern字符串。

    示例 1:

    @@ -29,14 +30,14 @@
  • 你可以假设pattern只包含字母"a""b"value仅包含小写字母。
  • - ## 解法 - + ### **Python3** + ```python @@ -44,6 +45,7 @@ ``` ### **Java** + ```java @@ -51,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.18.Pattern Matching/README_EN.md b/lcci/16.18.Pattern Matching/README_EN.md index 6aec048bed18a..f9610de6b3962 100644 --- a/lcci/16.18.Pattern Matching/README_EN.md +++ b/lcci/16.18.Pattern Matching/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.18.Pattern%20Matching/README.md) ## Description -

    You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also matches patterns like a, ab, and b. Write a method to determine if value matches pattern. a and b cannot be the same string.

    - +

    You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also matches patterns like a, ab, and b. Write a method to determine if value matches pattern. a and b cannot be the same string.

    Example 1:

    - -
     
     Input:  pattern = "abba", value = "dogcatcatdog"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:  pattern = "abba", value = "dogcatcatfish"
    @@ -33,12 +26,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input:  pattern = "aaaa", value = "dogcatcatdog"
    @@ -47,12 +36,8 @@
     
     
    - -

    Example 4:

    - -
     
     Input:  pattern = "abba", value = "dogdogdogdog"
    @@ -63,24 +48,16 @@
     
     
    - -

    Note:

    - -
    • 0 <= len(pattern) <= 1000
    • 0 <= len(value) <= 1000
    • pattern only contains "a" and "b"value only contains lowercase letters.
    - - - ## Solutions - ### **Python3** @@ -96,8 +73,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.19.Pond Sizes/README.md b/lcci/16.19.Pond Sizes/README.md index fa15a416fb5bb..6ecbefb881741 100644 --- a/lcci/16.19.Pond Sizes/README.md +++ b/lcci/16.19.Pond Sizes/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.19.Pond%20Sizes/README_EN.md) ## 题目描述 +

    你有一个用于表示一片土地的整数矩阵land,该矩阵中每个点的值代表对应地点的海拔高度。若值为0则表示水域。由垂直、水平或对角连接的水域为池塘。池塘的大小是指相连接的水域的个数。编写一个方法来计算矩阵中所有池塘的大小,返回值需要从小到大排序。

    示例:

    @@ -21,14 +22,14 @@
  • 0 < len(land[i]) <= 1000
  • - ## 解法 - + ### **Python3** + ```python @@ -36,6 +37,7 @@ ``` ### **Java** + ```java @@ -43,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.19.Pond Sizes/README_EN.md b/lcci/16.19.Pond Sizes/README_EN.md index 97f5166edf06b..bc51db0a7ce3c 100644 --- a/lcci/16.19.Pond Sizes/README_EN.md +++ b/lcci/16.19.Pond Sizes/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.19.Pond%20Sizes/README.md) ## Description -

    You have an integer matrix representing a plot of land, where the value at that loca­tion represents the height above sea level. A value of zero indicates water. A pond is a region of water connected vertically, horizontally, or diagonally. The size of the pond is the total number of connected water cells. Write a method to compute the sizes of all ponds in the matrix.

    - +

    You have an integer matrix representing a plot of land, where the value at that loca­tion represents the height above sea level. A value of zero indicates water. A pond is a region of water connected vertically, horizontally, or diagonally. The size of the pond is the total number of connected water cells. Write a method to compute the sizes of all ponds in the matrix.

    Example:

    - -
     
     Input: 
    @@ -31,23 +28,15 @@
     
     
    - -

    Note:

    - -
    • 0 < len(land) <= 1000
    • 0 < len(land[i]) <= 1000
    - - - ## Solutions - ### **Python3** @@ -63,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.20.T9/README.md b/lcci/16.20.T9/README.md index c9614d6fa9d53..5665b16e8d790 100644 --- a/lcci/16.20.T9/README.md +++ b/lcci/16.20.T9/README.md @@ -1,8 +1,9 @@ -# [面试题 16.20. T9键盘](https://leetcode-cn.com/problems/t9-lcci) +# [面试题 16.20. T9 键盘](https://leetcode-cn.com/problems/t9-lcci) [English Version](/lcci/16.20.T9/README_EN.md) ## 题目描述 +

    在老式手机上,用户通过数字键盘输入,手机将提供与这些数字相匹配的单词列表。每个数字映射到0至4个字母。给定一个数字序列,实现一个算法来返回匹配单词的列表。你会得到一张含有有效单词的列表。映射如下图所示:

    @@ -28,14 +29,14 @@
  • num中不会出现 0, 1 这两个数字
  • - ## 解法 - + ### **Python3** + ```python @@ -43,6 +44,7 @@ ``` ### **Java** + ```java @@ -50,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.20.T9/README_EN.md b/lcci/16.20.T9/README_EN.md index 6096f4ea2ad70..24719c6a3c77f 100644 --- a/lcci/16.20.T9/README_EN.md +++ b/lcci/16.20.T9/README_EN.md @@ -3,15 +3,13 @@ [中文文档](/lcci/16.20.T9/README.md) ## Description +

    On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0 - 4 letters. Implement an algo­rithm to return a list of matching words, given a sequence of digits. You are provided a list of valid words. The mapping is shown in the diagram below:

    ![](./images/17_telephone_keypad.png) -

    Example 1:

    - -
     
     Input: num = "8733", words = ["tree", "used"]
    @@ -20,24 +18,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: num = "2", words = ["a", "b", "c", "d"]
     
     Output: ["a", "b", "c"]
    - -

    Note:

    - -
    • num.length <= 1000
    • words.length <= 500
    • @@ -45,12 +35,8 @@
    • There are no number 0 and 1 in num.
    - - - ## Solutions - ### **Python3** @@ -66,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.21.Sum Swap/README.md b/lcci/16.21.Sum Swap/README.md index e868f1e71ed19..365f1cb336962 100644 --- a/lcci/16.21.Sum Swap/README.md +++ b/lcci/16.21.Sum Swap/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.21.Sum%20Swap/README_EN.md) ## 题目描述 +

    给定两个整数数组,请交换一对数值(每个数组中取一个数值),使得两个数组所有元素的和相等。

    @@ -25,14 +26,16 @@
  • 1 <= array1.length, array2.length <= 100000
  • - ## 解法 + + 先计算两个数组的差值 `diff`,若 `diff` 为奇数,则说明无满足条件的数值,返回空数组。否则,将 `array2` 转为 `set`。然后遍历 `array1` 中的每个数 `e`,若值 `e - diff` 在 `set` 中,则说明找到满足条件的数值对。 ### **Python3** + ```python @@ -48,6 +51,7 @@ class Solution: ``` ### **Java** + ```java @@ -78,8 +82,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.21.Sum Swap/README_EN.md b/lcci/16.21.Sum Swap/README_EN.md index c68e5559bf1a7..4f34d930676e2 100644 --- a/lcci/16.21.Sum Swap/README_EN.md +++ b/lcci/16.21.Sum Swap/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.21.Sum%20Swap/README.md) ## Description -

    Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.

    - +

    Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.

    Return an array, where the first element is the element in the first array that will be swapped, and the second element is another one in the second array. If there are more than one answers, return any one of them. If there is no answer, return an empty array.

    - -

    Example:

    - -
     
     Input: array1 = [4, 1, 2, 1, 1, 2], array2 = [3, 6, 3, 3]
    @@ -23,34 +18,22 @@
     
     
    - -

    Example:

    - -
     
     Input: array1 = [1, 2, 3], array2 = [4, 5, 6]
     
     Output: []
    - -

    Note:

    - -
    • 1 <= array1.length, array2.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -97,8 +80,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.22.Langtons Ant/README.md b/lcci/16.22.Langtons Ant/README.md index 20c3f277a8154..b666c90369f71 100644 --- a/lcci/16.22.Langtons Ant/README.md +++ b/lcci/16.22.Langtons Ant/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.22.Langtons%20Ant/README_EN.md) ## 题目描述 +

    一只蚂蚁坐在由白色和黑色方格构成的无限网格上。开始时,网格全白,蚂蚁面向右侧。每行走一步,蚂蚁执行以下操作。

    @@ -46,14 +47,14 @@
  • K <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -61,6 +62,7 @@ ``` ### **Java** + ```java @@ -68,8 +70,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.22.Langtons Ant/README_EN.md b/lcci/16.22.Langtons Ant/README_EN.md index b2e336662e43b..df2582994d42f 100644 --- a/lcci/16.22.Langtons Ant/README_EN.md +++ b/lcci/16.22.Langtons Ant/README_EN.md @@ -3,34 +3,21 @@ [中文文档](/lcci/16.22.Langtons%20Ant/README.md) ## Description -

    An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.

    - +

    An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.

    At each step, it does the following:

    - -

    (1) At a white square, flip the color of the square, turn 90 degrees right (clockwise), and move forward one unit.

    - -

    (2) At a black square, flip the color of the square, turn 90 degrees left (counter-clockwise), and move forward one unit.

    - -

    Write a program to simulate the first K moves that the ant makes and print the final board as a grid.

    - -

    The grid should be represented as an array of strings, where each element represents one row in the grid. The black square is represented as 'X', and the white square is represented as '_', the square which is occupied by the ant is represented as 'L', 'U', 'R', 'D', which means the left, up, right and down orientations respectively. You only need to return the minimum matrix that is able to contain all squares that are passed through by the ant.

    - -

    Example 1:

    - -
     
     Input: 0
    @@ -39,12 +26,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 2
    @@ -61,12 +44,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: 5
    @@ -85,22 +64,14 @@
     
     
    - -

    Note:

    - -
    • K <= 100000
    - - - ## Solutions - ### **Python3** @@ -116,8 +87,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.24.Pairs With Sum/README.md b/lcci/16.24.Pairs With Sum/README.md index 8c6cfa0e2a350..2079c65849acd 100644 --- a/lcci/16.24.Pairs With Sum/README.md +++ b/lcci/16.24.Pairs With Sum/README.md @@ -3,6 +3,7 @@ [中文文档](/lcci/16.24.Pairs%20With%20Sum/README.md) ## 题目描述 +

    设计一个算法,找出数组中两数之和为指定值的所有整数对。一个数只能属于一个数对。

    @@ -22,14 +23,14 @@
  • nums.length <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -37,6 +38,7 @@ ``` ### **Java** + ```java @@ -44,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.24.Pairs With Sum/README_EN.md b/lcci/16.24.Pairs With Sum/README_EN.md index c4a0bc302fcf5..331d9aa4e2e04 100644 --- a/lcci/16.24.Pairs With Sum/README_EN.md +++ b/lcci/16.24.Pairs With Sum/README_EN.md @@ -1,48 +1,33 @@ # [16.24. Pairs With Sum](https://leetcode-cn.com/problems/pairs-with-sum-lcci) ## Description -

    Design an algorithm to find all pairs of integers within an array which sum to a specified value.

    - +

    Design an algorithm to find all pairs of integers within an array which sum to a specified value.

    Example 1:

    - -
     
     Input: nums = [5,6,5], target = 11
     
     Output: [[5,6]]
    - -

    Example 2:

    - -
     
     Input: nums = [5,6,5,6], target = 11
     
     Output: [[5,6],[5,6]]
    - -

    Note:

    - -
    • nums.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.25.LRU Cache/README.md b/lcci/16.25.LRU Cache/README.md index 211af4fe23153..61b0ca557f072 100644 --- a/lcci/16.25.LRU Cache/README.md +++ b/lcci/16.25.LRU Cache/README.md @@ -1,8 +1,9 @@ -# [面试题 16.25. LRU缓存](https://leetcode-cn.com/problems/lru-cache-lcci) +# [面试题 16.25. LRU 缓存](https://leetcode-cn.com/problems/lru-cache-lcci) [English Version](/lcci/16.25.LRU%20Cache/README_EN.md) ## 题目描述 +

    设计和构建一个“最近最少使用”缓存,该缓存会删除最近最少使用的项目。缓存应该从键映射到值(允许你插入和检索特定键对应的值),并在初始化时指定最大容量。当缓存被填满时,它应该删除最近最少使用的项目。

    @@ -26,14 +27,14 @@ cache.get(3); // 返回 3 cache.get(4); // 返回 4 - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ cache.get(4); // 返回 4 ``` ### **Java** + ```java @@ -48,8 +50,9 @@ cache.get(4); // 返回 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.25.LRU Cache/README_EN.md b/lcci/16.25.LRU Cache/README_EN.md index 461043d6331d3..f48cae9f301b6 100644 --- a/lcci/16.25.LRU Cache/README_EN.md +++ b/lcci/16.25.LRU Cache/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/lcci/16.25.LRU%20Cache/README.md) ## Description -

    Design and build a "least recently used" cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associ­ated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.

    - +

    Design and build a "least recently used" cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associ­ated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.

    You should implement following operations:  get and put.

    - -

    Get a value by key: get(key) - If key is in the cache, return the value, otherwise return -1.
    Write a key-value pair to the cache: put(key, value) - If the key is not in the cache, then write its value to the cache. Evict the least recently used item before writing if necessary.

    - -

    Example:

    - -
     
     LRUCache cache = new LRUCache( 2 /* capacity */ );
    @@ -47,12 +40,8 @@ cache.get(4);       // returns 4
     
     
    - - - ## Solutions - ### **Python3** @@ -68,8 +57,9 @@ cache.get(4); // returns 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.26.Calculator/README.md b/lcci/16.26.Calculator/README.md index 5b0c6162675d2..ee6e9bd9e921c 100644 --- a/lcci/16.26.Calculator/README.md +++ b/lcci/16.26.Calculator/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.26.Calculator/README_EN.md) ## 题目描述 +

    给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。

    @@ -32,14 +33,14 @@
  • 不要使用内置的库函数 eval
  • - ## 解法 - + ### **Python3** + ```python @@ -47,6 +48,7 @@ ``` ### **Java** + ```java @@ -54,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.26.Calculator/README_EN.md b/lcci/16.26.Calculator/README_EN.md index b2b98ae355cdb..acfb115e55399 100644 --- a/lcci/16.26.Calculator/README_EN.md +++ b/lcci/16.26.Calculator/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/16.26.Calculator/README.md) ## Description -

    Given an arithmetic equation consisting of positive integers, +, -, * and / (no paren­theses), compute the result.

    - +

    Given an arithmetic equation consisting of positive integers, +, -, * and / (no paren­theses), compute the result.

    The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.

    - -

    Example 1:

    - -
     
     Input: "3+2*2"
    @@ -23,24 +18,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: " 3/2 "
     
     Output: 1
    - -

    Example 3:

    - -
     
     Input: " 3+5 / 2 "
    @@ -49,23 +36,15 @@
     
     
    - -

    Note:

    - -
    • You may assume that the given expression is always valid.
    • Do not use the eval built-in library function.
    - - - ## Solutions - ### **Python3** @@ -81,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.01.Add Without Plus/README.md b/lcci/17.01.Add Without Plus/README.md index cad364f384058..9f5b89906f555 100644 --- a/lcci/17.01.Add Without Plus/README.md +++ b/lcci/17.01.Add Without Plus/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.01.Add%20Without%20Plus/README_EN.md) ## 题目描述 +

    设计一个函数把两个数字相加。不得使用 + 或者其他算术运算符。

    @@ -20,14 +21,14 @@
  • 结果不会溢出 32 位整数
  • - ## 解法 - + ### **Python3** + ```python @@ -35,6 +36,7 @@ ``` ### **Java** + ```java @@ -53,8 +55,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.01.Add Without Plus/README_EN.md b/lcci/17.01.Add Without Plus/README_EN.md index 7a4945d8f05c5..1dee2f839973a 100644 --- a/lcci/17.01.Add Without Plus/README_EN.md +++ b/lcci/17.01.Add Without Plus/README_EN.md @@ -3,41 +3,28 @@ [中文文档](/lcci/17.01.Add%20Without%20Plus/README.md) ## Description -

    Write a function that adds two numbers. You should not use + or any arithmetic operators.

    - +

    Write a function that adds two numbers. You should not use + or any arithmetic operators.

    Example:

    - -
     
     Input: a = 1, b = 1
     
     Output: 2
    - -

     

    - -

    Note:

    - -
    • a and b may be 0 or negative.
    • The result fits in 32-bit integer.
    - - - ## Solutions - ### **Python3** @@ -64,8 +51,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.04.Missing Number/README.md b/lcci/17.04.Missing Number/README.md index e1bd5538e5046..bb254afa7d962 100644 --- a/lcci/17.04.Missing Number/README.md +++ b/lcci/17.04.Missing Number/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.04.Missing%20Number/README_EN.md) ## 题目描述 +

    数组nums包含从0n的所有整数,但其中缺了一个。请编写代码找出那个缺失的整数。你有办法在O(n)时间内完成吗?

    @@ -21,14 +22,16 @@ 输出:8 - ## 解法 + + 利用异或的特性,`res = res ^ x ^ x`。对同一个值异或两次,结果等于它本身。最后异或的结果,就是只出现一次的数字,即数组中缺失的整数。 ### **Python3** + ```python @@ -43,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -60,8 +64,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.04.Missing Number/README_EN.md b/lcci/17.04.Missing Number/README_EN.md index a6ac286bfe577..8d38e6e64b912 100644 --- a/lcci/17.04.Missing Number/README_EN.md +++ b/lcci/17.04.Missing Number/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/lcci/17.04.Missing%20Number/README.md) ## Description -

    An array contains all the integers from 0 to n, except for one number which is missing.  Write code to find the missing integer. Can you do it in O(n) time?

    - +

    An array contains all the integers from 0 to n, except for one number which is missing.  Write code to find the missing integer. Can you do it in O(n) time?

    Note: This problem is slightly different from the original one the book.

    - -

    Example 1:

    - -
     
     Input: [3,0,1]
     
     Output: 2
    - -

     

    - -

    Example 2:

    - -
     
     Input: [9,6,4,2,3,5,7,0,1]
    @@ -39,12 +28,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -77,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.05.Find Longest Subarray/README.md b/lcci/17.05.Find Longest Subarray/README.md index bc990ea123761..ccc1c9bbd1a89 100644 --- a/lcci/17.05.Find Longest Subarray/README.md +++ b/lcci/17.05.Find Longest Subarray/README.md @@ -1,8 +1,9 @@ -# [面试题 17.05. 字母与数字](https://leetcode-cn.com/problems/find-longest-subarray-lcci) +# [面试题 17.05. 字母与数字](https://leetcode-cn.com/problems/find-longest-subarray-lcci) [English Version](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) ## 题目描述 +

    给定一个放有字符和数字的数组,找到最长的子数组,且包含的字符和数字的个数相同。

    @@ -28,14 +29,14 @@
  • array.length <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -43,6 +44,7 @@ ``` ### **Java** + ```java @@ -50,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.05.Find Longest Subarray/README_EN.md b/lcci/17.05.Find Longest Subarray/README_EN.md index d0e3712d3da96..726a733ab1c24 100644 --- a/lcci/17.05.Find Longest Subarray/README_EN.md +++ b/lcci/17.05.Find Longest Subarray/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.05.Find%20Longest%20Subarray/README.md) ## Description -

    Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.

    - +

    Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.

    Return the subarray. If there are more than one answer, return the one which has the smallest index of its left endpoint. If there is no answer, return an empty arrary.

    - -

    Example 1:

    - -
     
     Input: ["A","1","B","C","D","2","3","4","E","5","F","G","6","7","H","I","J","K","L","M"]
    @@ -25,12 +20,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: ["A","A"]
    @@ -41,22 +32,14 @@
     
     
    - -

    Note:

    - -
    • array.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -72,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.06.Number Of 2s In Range/README.md b/lcci/17.06.Number Of 2s In Range/README.md index 55ea251065289..64f99a47983a8 100644 --- a/lcci/17.06.Number Of 2s In Range/README.md +++ b/lcci/17.06.Number Of 2s In Range/README.md @@ -1,8 +1,9 @@ -# [面试题 17.06. 2出现的次数](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) +# [面试题 17.06. 2 出现的次数](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) [English Version](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) ## 题目描述 +

    编写一个方法,计算从 0 到 n (含 n) 中数字 2 出现的次数。

    @@ -18,14 +19,14 @@
  • n <= 10^9
  • - ## 解法 - + ### **Python3** + ```python @@ -33,6 +34,7 @@ ``` ### **Java** + ```java @@ -40,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.06.Number Of 2s In Range/README_EN.md b/lcci/17.06.Number Of 2s In Range/README_EN.md index fd19d74554f59..23ae9446cbde4 100644 --- a/lcci/17.06.Number Of 2s In Range/README_EN.md +++ b/lcci/17.06.Number Of 2s In Range/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/17.06.Number%20Of%202s%20In%20Range/README.md) ## Description -

    Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive).

    - +

    Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive).

    Example:

    - -
     
     Input: 25
    @@ -19,22 +16,14 @@
     
     Explanation: (2, 12, 20, 21, 22, 23, 24, 25)(Note that 22 counts for two 2s.)
    - -

    Note:

    - -
    • n <= 10^9
    - - - ## Solutions - ### **Python3** @@ -50,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.07.Baby Names/README.md b/lcci/17.07.Baby Names/README.md index 4e511fa78c006..94769c0e72044 100644 --- a/lcci/17.07.Baby Names/README.md +++ b/lcci/17.07.Baby Names/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.07.Baby%20Names/README_EN.md) ## 题目描述 +

    每年,政府都会公布一万个最常见的婴儿名字和它们出现的频率,也就是同名婴儿的数量。有些名字有多种拼法,例如,John 和 Jon 本质上是相同的名字,但被当成了两个名字公布出来。给定两个列表,一个是名字及对应的频率,另一个是本质相同的名字对。设计一个算法打印出每个真实名字的实际频率。注意,如果 John 和 Jon 是相同的,并且 Jon 和 Johnny 相同,则 John 与 Johnny 也相同,即它们有传递和对称性。

    @@ -19,14 +20,14 @@
  • names.length <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -34,6 +35,7 @@ ``` ### **Java** + ```java @@ -41,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.07.Baby Names/README_EN.md b/lcci/17.07.Baby Names/README_EN.md index 27e3f87865509..079878c41d17c 100644 --- a/lcci/17.07.Baby Names/README_EN.md +++ b/lcci/17.07.Baby Names/README_EN.md @@ -3,36 +3,25 @@ [中文文档](/lcci/17.07.Baby%20Names/README.md) ## Description -

    Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,"John" and ''Jon" are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are lexicographically smallest as the "real" name.

    - +

    Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,"John" and ''Jon" are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are lexicographically smallest as the "real" name.

    Example:

    - -
     
     Input: names = ["John(15)","Jon(12)","Chris(13)","Kris(4)","Christopher(19)"], synonyms = ["(Jon,John)","(John,Johnny)","(Chris,Kris)","(Chris,Christopher)"]
     
     Output: ["John(27)","Chris(36)"]
    - -

    Note:

    - -
    • names.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -48,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.08.Circus Tower/README.md b/lcci/17.08.Circus Tower/README.md index 19f2a006ccc2c..cd3ba1d3004b9 100644 --- a/lcci/17.08.Circus Tower/README.md +++ b/lcci/17.08.Circus Tower/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.08.Circus%20Tower/README_EN.md) ## 题目描述 +

    有个马戏团正在设计叠罗汉的表演节目,一个人要站在另一人的肩膀上。出于实际和美观的考虑,在上面的人要比下面的人矮一点且轻一点。已知马戏团每个人的身高和体重,请编写代码计算叠罗汉最多能叠几个人。

    @@ -18,14 +19,14 @@
  • height.length == weight.length <= 10000
  • - ## 解法 - + ### **Python3** + ```python @@ -33,6 +34,7 @@ ``` ### **Java** + ```java @@ -40,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.08.Circus Tower/README_EN.md b/lcci/17.08.Circus Tower/README_EN.md index 9f846d8ffbcf6..1be82f098d32b 100644 --- a/lcci/17.08.Circus Tower/README_EN.md +++ b/lcci/17.08.Circus Tower/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/17.08.Circus%20Tower/README.md) ## Description -

    A circus is designing a tower routine consisting of people standing atop one anoth­er's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.

    - +

    A circus is designing a tower routine consisting of people standing atop one anoth­er's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.

    Example:

    - -
     
     Input: height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]
    @@ -19,22 +16,14 @@
     
     Explanation: The longest tower is length 6 and includes from top to bottom: (56,90), (60,95), (65,100), (68,110), (70,150), (75,190)
    - -

    Note:

    - -
    • height.length == weight.length <= 10000
    - - - ## Solutions - ### **Python3** @@ -50,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.09.Get Kth Magic Number/README.md b/lcci/17.09.Get Kth Magic Number/README.md index 38dd4a120a329..d78527ca9ab45 100644 --- a/lcci/17.09.Get Kth Magic Number/README.md +++ b/lcci/17.09.Get Kth Magic Number/README.md @@ -3,6 +3,7 @@ [中文文档](/lcci/17.09.Get%20Kth%20Magic%20Number/README.md) ## 题目描述 +

    有些数的素因子只有 3,5,7,请设计一个算法找出第 k 个数。注意,不是必须有这些素因子,而是必须不包含其他的素因子。例如,前几个数按顺序应该是 1,3,5,7,9,15,21。

    @@ -13,14 +14,14 @@ 输出: 9 - ## 解法 - + ### **Python3** + ```python @@ -28,6 +29,7 @@ ``` ### **Java** + ```java @@ -35,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.09.Get Kth Magic Number/README_EN.md b/lcci/17.09.Get Kth Magic Number/README_EN.md index de2115da6bbd3..320a1b81aec3e 100644 --- a/lcci/17.09.Get Kth Magic Number/README_EN.md +++ b/lcci/17.09.Get Kth Magic Number/README_EN.md @@ -1,14 +1,11 @@ # [17.09. Get Kth Magic Number](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) ## Description -

    Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime factors. For example, the first several multiples would be (in order) 1, 3, 5, 7, 9, 15, 21.

    - +

    Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime factors. For example, the first several multiples would be (in order) 1, 3, 5, 7, 9, 15, 21.

    Example 1:

    - -
     
     Input: k = 5
    @@ -19,12 +16,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.10.Find Majority Element/README.md b/lcci/17.10.Find Majority Element/README.md index 3b8f16f5ca16a..ad1805f1708ba 100644 --- a/lcci/17.10.Find Majority Element/README.md +++ b/lcci/17.10.Find Majority Element/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.10.Find%20Majority%20Element/README_EN.md) ## 题目描述 +

    如果数组中多一半的数都是同一个,则称之为主要元素。给定一个整数数组,找到它的主要元素。若没有,返回-1。

    @@ -30,14 +31,14 @@

    说明:
    你有办法在时间复杂度为 O(N),空间复杂度为 O(1) 内完成吗?

    - ## 解法 - + ### **Python3** + ```python @@ -45,6 +46,7 @@ ``` ### **Java** + ```java @@ -52,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.10.Find Majority Element/README_EN.md b/lcci/17.10.Find Majority Element/README_EN.md index 43378c3d724c1..d5bcac1be8f67 100644 --- a/lcci/17.10.Find Majority Element/README_EN.md +++ b/lcci/17.10.Find Majority Element/README_EN.md @@ -3,46 +3,31 @@ [中文文档](/lcci/17.10.Find%20Majority%20Element/README.md) ## Description -

    A majority element is an element that makes up more than half of the items in an array. Given a positive integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.

    - +

    A majority element is an element that makes up more than half of the items in an array. Given a positive integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.

    Example 1:

    - -
     
     Input: [1,2,5,9,5,9,5,5,5]
     
     Output: 5
    - -

     

    - -

    Example 2:

    - -
     
     Input: [3,2]
     
     Output: -1
    - -

     

    - -

    Example 3:

    - -
     
     Input: [2,2,1,1,1,2,2]
    @@ -51,12 +36,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -72,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.11.Find Closest/README.md b/lcci/17.11.Find Closest/README.md index 6146366881fa5..c71e3acdf86b1 100644 --- a/lcci/17.11.Find Closest/README.md +++ b/lcci/17.11.Find Closest/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.11.Find%20Closest/README_EN.md) ## 题目描述 +

    有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?

    @@ -17,14 +18,14 @@
  • words.length <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -32,6 +33,7 @@ ``` ### **Java** + ```java @@ -39,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.11.Find Closest/README_EN.md b/lcci/17.11.Find Closest/README_EN.md index 30c0e47de0b35..686c78925f386 100644 --- a/lcci/17.11.Find Closest/README_EN.md +++ b/lcci/17.11.Find Closest/README_EN.md @@ -3,35 +3,25 @@ [中文文档](/lcci/17.11.Find%20Closest/README.md) ## Description -

    You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?

    - +

    You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?

    Example:

    - -
     
     Input: words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student"
     
     Output: 1
    - -

    Note:

    -
    • words.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -47,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.12.BiNode/README.md b/lcci/17.12.BiNode/README.md index a4119bda0875b..e058334104870 100644 --- a/lcci/17.12.BiNode/README.md +++ b/lcci/17.12.BiNode/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.12.BiNode/README_EN.md) ## 题目描述 +

    二叉树数据结构TreeNode可用来表示单向链表(其中left置空,right为下一个链表节点)。实现一个方法,把二叉搜索树转换为单向链表,要求值的顺序保持不变,转换操作应是原址的,也就是在原始的二叉搜索树上直接修改。

    @@ -24,14 +25,14 @@
  • 节点数量不会超过 100000。
  • - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ ``` ### **Java** + ```java @@ -46,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.12.BiNode/README_EN.md b/lcci/17.12.BiNode/README_EN.md index ea027981c8461..8a2372f4c7a78 100644 --- a/lcci/17.12.BiNode/README_EN.md +++ b/lcci/17.12.BiNode/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/lcci/17.12.BiNode/README.md) ## Description -

    The data structure TreeNode is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with TreeNode) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).

    - +

    The data structure TreeNode is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with TreeNode) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).

    Return the head node of the linked list after converting.

    - -

    Note: This problem is slightly different from the original one in the book.

    - -

     

    - -

    Example:

    - -
     
     Input:  [4,2,5,1,3,null,6,0]
    @@ -31,22 +22,14 @@
     
     
    - -

    Note:

    - -
    • The number of nodes will not exceed 100000.
    - - - ## Solutions - ### **Python3** @@ -62,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.13.Re-Space/README.md b/lcci/17.13.Re-Space/README.md index b93049907de8f..220ecc383bca1 100644 --- a/lcci/17.13.Re-Space/README.md +++ b/lcci/17.13.Re-Space/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.13.Re-Space/README_EN.md) ## 题目描述 +

    哦,不!你不小心把一个长篇文章中的空格、标点都删掉了,并且大写也弄成了小写。像句子"I reset the computer. It still didn’t boot!"已经变成了"iresetthecomputeritstilldidntboot"。在处理标点符号和大小写之前,你得先把它断成词语。当然了,你有一本厚厚的词典dictionary,不过,有些词没在词典里。假设文章用sentence表示,设计一个算法,把文章断开,要求未识别的字符最少,返回未识别的字符数。

    @@ -27,14 +28,14 @@ sentence = "jesslookedjustliketimherbrother"
  • 你可以认为dictionarysentence中只包含小写字母。
  • - ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ sentence = "jesslookedjustliketimherbrother" ``` ### **Java** + ```java @@ -49,8 +51,9 @@ sentence = "jesslookedjustliketimherbrother" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.13.Re-Space/README_EN.md b/lcci/17.13.Re-Space/README_EN.md index ab4dcdfa1d94b..7f0ddb6148f5b 100644 --- a/lcci/17.13.Re-Space/README_EN.md +++ b/lcci/17.13.Re-Space/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/17.13.Re-Space/README.md) ## Description -

    Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeritstilldidntboot''. You'll deal with the punctuation and capi­talization later; right now you need to re-insert the spaces. Most of the words are in a dictionary but a few are not. Given a dictionary (a list of strings) and the document (a string), design an algorithm to unconcatenate the document in a way that minimizes the number of unrecognized characters. Return the number of unrecognized characters.

    - +

    Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeritstilldidntboot''. You'll deal with the punctuation and capi­talization later; right now you need to re-insert the spaces. Most of the words are in a dictionary but a few are not. Given a dictionary (a list of strings) and the document (a string), design an algorithm to unconcatenate the document in a way that minimizes the number of unrecognized characters. Return the number of unrecognized characters.

    Note: This problem is slightly different from the original one in the book.

    - -

     

    - -

    Example:

    - -
     
     Input: 
    @@ -33,24 +26,16 @@ sentence = "jesslookedjustliketimherbrother"
     
     
    - -

    Note:

    - -
    • 0 <= len(sentence) <= 1000
    • The total number of characters in dictionary is less than or equal to 150000.
    • There are only lowercase letters in dictionary and sentence.
    - - - ## Solutions - ### **Python3** @@ -66,8 +51,9 @@ sentence = "jesslookedjustliketimherbrother" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.14.Smallest K/README.md b/lcci/17.14.Smallest K/README.md index b58e93a7826d2..71dd5e5c1e042 100644 --- a/lcci/17.14.Smallest K/README.md +++ b/lcci/17.14.Smallest K/README.md @@ -1,8 +1,9 @@ -# [面试题 17.14. 最小K个数](https://leetcode-cn.com/problems/smallest-k-lcci) +# [面试题 17.14. 最小 K 个数](https://leetcode-cn.com/problems/smallest-k-lcci) [English Version](/lcci/17.14.Smallest%20K/README_EN.md) ## 题目描述 +

    设计一个算法,找出数组中最小的k个数。以任意顺序返回这k个数均可。

    @@ -19,14 +20,14 @@
  • 0 <= k <= min(100000, len(arr))
  • - ## 解法 - + ### **Python3** + ```python @@ -34,6 +35,7 @@ ``` ### **Java** + ```java @@ -41,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.14.Smallest K/README_EN.md b/lcci/17.14.Smallest K/README_EN.md index 0a075130ff6ab..7dd220125b5d4 100644 --- a/lcci/17.14.Smallest K/README_EN.md +++ b/lcci/17.14.Smallest K/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/17.14.Smallest%20K/README.md) ## Description -

    Design an algorithm to find the smallest K numbers in an array.

    - +

    Design an algorithm to find the smallest K numbers in an array.

    Example:

    - -
     
     Input:  arr = [1,3,5,7,2,4,6,8], k = 4
    @@ -19,23 +16,15 @@
     
     
    - -

    Note:

    - -
    • 0 <= len(arr) <= 100000
    • 0 <= k <= min(100000, len(arr))
    - - - ## Solutions - ### **Python3** @@ -51,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.15.Longest Word/README.md b/lcci/17.15.Longest Word/README.md index 7559350da3901..5f564411e4c79 100644 --- a/lcci/17.15.Longest Word/README.md +++ b/lcci/17.15.Longest Word/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.15.Longest%20Word/README_EN.md) ## 题目描述 +

    给定一组单词words,编写一个程序,找出其中的最长单词,且该单词由这组单词中的其他单词组合而成。若有多个长度相同的结果,返回其中字典序最小的一项,若没有符合要求的单词则返回空字符串。

    示例:

    @@ -16,14 +17,14 @@
  • 1 <= len(words[i]) <= 100
  • - ## 解法 - + ### **Python3** + ```python @@ -31,6 +32,7 @@ ``` ### **Java** + ```java @@ -38,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.15.Longest Word/README_EN.md b/lcci/17.15.Longest Word/README_EN.md index a11044cefe7a9..860681268aeea 100644 --- a/lcci/17.15.Longest Word/README_EN.md +++ b/lcci/17.15.Longest Word/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/17.15.Longest%20Word/README.md) ## Description -

    Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If no answer, return an empty string.

    - +

    Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If no answer, return an empty string.

    Example:

    - -
     
     Input:  ["cat","banana","dog","nana","walk","walker","dogwalker"]
    @@ -21,23 +18,15 @@
     
     
    - -

    Note:

    - -
    • 0 <= len(words) <= 100
    • 1 <= len(words[i]) <= 100
    - - - ## Solutions - ### **Python3** @@ -53,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.16.The Masseuse/README.md b/lcci/17.16.The Masseuse/README.md index d105e98ff737c..65265d5dc2dde 100644 --- a/lcci/17.16.The Masseuse/README.md +++ b/lcci/17.16.The Masseuse/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.16.The%20Masseuse/README_EN.md) ## 题目描述 +

    一个有名的按摩师会收到源源不断的预约请求,每个预约都可以选择接或不接。在每次预约服务之间要有休息时间,因此她不能接受相邻的预约。给定一个预约请求序列,替按摩师找到最优的预约集合(总预约时间最长),返回总的分钟数。

    @@ -31,15 +32,16 @@ 解释: 选择 1 号预约、 3 号预约、 5 号预约和 8 号预约,总时长 = 2 + 4 + 3 + 3 = 12。 - ## 解法 + -递推求解。 +递推求解。 ### **Python3** + ```python @@ -59,6 +61,7 @@ class Solution: ``` ### **Java** + ```java @@ -84,8 +87,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.16.The Masseuse/README_EN.md b/lcci/17.16.The Masseuse/README_EN.md index 99bc5617ae7f8..b296f4fc5f46f 100644 --- a/lcci/17.16.The Masseuse/README_EN.md +++ b/lcci/17.16.The Masseuse/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/17.16.The%20Masseuse/README.md) ## Description -

    A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adjacent requests. Given a sequence of back-to-back appoint­ ment requests, find the optimal (highest total booked minutes) set the masseuse can honor. Return the number of minutes.

    - +

    A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adjacent requests. Given a sequence of back-to-back appoint­ ment requests, find the optimal (highest total booked minutes) set the masseuse can honor. Return the number of minutes.

    Note: This problem is slightly different from the original one in the book.

    - -

     

    - -

    Example 1:

    - -
     
     Input:  [1,2,3,1]
    @@ -29,12 +22,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:  [2,7,9,3,1]
    @@ -45,12 +34,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input:  [2,1,4,5,3,1,1,3]
    @@ -61,12 +46,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -112,8 +93,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.17.Multi Search/README.md b/lcci/17.17.Multi Search/README.md index da47994efa2b6..0b0b2dd563fce 100644 --- a/lcci/17.17.Multi Search/README.md +++ b/lcci/17.17.Multi Search/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.17.Multi%20Search/README_EN.md) ## 题目描述 +

    给定一个较长字符串big和一个包含较短字符串的数组smalls,设计一个方法,根据smalls中的每一个较短字符串,对big进行搜索。输出smalls中的字符串在big里出现的所有位置positions,其中positions[i]smalls[i]出现的所有位置。

    @@ -24,14 +25,14 @@ smalls = ["is","ppi","hi","sis","i&
  • 所有出现的字符均为英文小写字母。
  • - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ smalls = ["is","ppi","hi","sis","i& ``` ### **Java** + ```java @@ -46,8 +48,9 @@ smalls = ["is","ppi","hi","sis","i& ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.17.Multi Search/README_EN.md b/lcci/17.17.Multi Search/README_EN.md index 8bbe2e1cdebd3..c1d7f818a4057 100644 --- a/lcci/17.17.Multi Search/README_EN.md +++ b/lcci/17.17.Multi Search/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/17.17.Multi%20Search/README.md) ## Description -

    Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions of all strings in smalls that appear in big, where positions[i] is all positions of smalls[i].

    - +

    Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions of all strings in smalls that appear in big, where positions[i] is all positions of smalls[i].

    Example:

    - -
     
     Input: 
    @@ -23,12 +20,8 @@ smalls = ["is","ppi","hi","sis","i&
     
     
    - -

    Note:

    - -
    • 0 <= len(big) <= 1000
    • 0 <= len(smalls[i]) <= 1000
    • @@ -37,12 +30,8 @@ smalls = ["is","ppi","hi","sis","i&
    • All characters are lowercase letters.
    - - - ## Solutions - ### **Python3** @@ -58,8 +47,9 @@ smalls = ["is","ppi","hi","sis","i& ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.18.Shortest Supersequence/README.md b/lcci/17.18.Shortest Supersequence/README.md index cb18109093668..897541aa88359 100644 --- a/lcci/17.18.Shortest Supersequence/README.md +++ b/lcci/17.18.Shortest Supersequence/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.18.Shortest%20Supersequence/README_EN.md) ## 题目描述 +

    假设你有两个数组,一个长一个短,短的元素均不相同。找到长数组中包含短数组所有的元素的最短子数组,其出现顺序无关紧要。

    @@ -29,14 +30,14 @@ small = [4]
  • 1 <= small.length <= 100000
  • - ## 解法 - + ### **Python3** + ```python @@ -44,6 +45,7 @@ small = [4]
    ``` ### **Java** + ```java @@ -51,8 +53,9 @@ small = [4] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.18.Shortest Supersequence/README_EN.md b/lcci/17.18.Shortest Supersequence/README_EN.md index 288003d2fb303..989437bf99e44 100644 --- a/lcci/17.18.Shortest Supersequence/README_EN.md +++ b/lcci/17.18.Shortest Supersequence/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.18.Shortest%20Supersequence/README.md) ## Description -

    You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter array. The items can appear in any order.

    - +

    You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter array. The items can appear in any order.

    Return the indexes of the leftmost and the rightmost elements of the array. If there are more than one answer, return the one that has the smallest left index. If there is no answer, return an empty array.

    - -

    Example 1:

    - -
     
     Input:
    @@ -25,12 +20,8 @@ small = [1,5,9]
     
     Output: [7,10]
    - -

    Example 2:

    - -
     
     Input:
    @@ -41,23 +32,15 @@ small = [4]
     
     Output: []
    - -

    Note:

    - -
    • big.length <= 100000
    • 1 <= small.length <= 100000
    - - - ## Solutions - ### **Python3** @@ -73,8 +56,9 @@ small = [4] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.19.Missing Two/README.md b/lcci/17.19.Missing Two/README.md index d5ac4f7d99d90..bb888b345337a 100644 --- a/lcci/17.19.Missing Two/README.md +++ b/lcci/17.19.Missing Two/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.19.Missing%20Two/README_EN.md) ## 题目描述 +

    给定一个数组,包含从 1 到 N 所有的整数,但其中缺了两个数字。你能在 O(N) 时间内只用 O(1) 的空间找到它们吗?

    @@ -24,14 +25,16 @@
  • nums.length <= 30000
  • - ## 解法 + -异或运算。与[面试题56 - I. 数组中数字出现的次数](/lcof/面试题56%20-%20I.%20数组中数字出现的次数/README.md) 类似。 + +异或运算。与[面试题 56 - I. 数组中数字出现的次数](/lcof/面试题56%20-%20I.%20数组中数字出现的次数/README.md) 类似。 ### **Python3** + ```python @@ -47,7 +50,7 @@ class Solution: while (res & 1) == 0: pos += 1 res >>= 1 - + a = b = 0 for num in nums: t = num >> pos @@ -55,7 +58,7 @@ class Solution: a ^= num else: b ^= num - + for i in range(1, n + 3): t = i >> pos if (t & 1) == 0: @@ -66,6 +69,7 @@ class Solution: ``` ### **Java** + ```java @@ -108,8 +112,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.19.Missing Two/README_EN.md b/lcci/17.19.Missing Two/README_EN.md index 78388013e015b..b30dbe04525fa 100644 --- a/lcci/17.19.Missing Two/README_EN.md +++ b/lcci/17.19.Missing Two/README_EN.md @@ -3,52 +3,35 @@ [中文文档](/lcci/17.19.Missing%20Two/README.md) ## Description -

    You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space?

    - +

    You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space?

    You can return the missing numbers in any order.

    - -

    Example 1:

    - -
     
     Input: [1]
     
     Output: [2,3]
    - -

    Example 2:

    - -
     
     Input: [2,3]
     
     Output: [1,4]
    - -

    Note:

    - -
    • nums.length <= 30000
    - - - ## Solutions - ### **Python3** @@ -66,7 +49,7 @@ class Solution: while (res & 1) == 0: pos += 1 res >>= 1 - + a = b = 0 for num in nums: t = num >> pos @@ -74,7 +57,7 @@ class Solution: a ^= num else: b ^= num - + for i in range(1, n + 3): t = i >> pos if (t & 1) == 0: @@ -126,8 +109,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.20.Continuous Median/README.md b/lcci/17.20.Continuous Median/README.md index 0ee4ecd385a0e..006e714778592 100644 --- a/lcci/17.20.Continuous Median/README.md +++ b/lcci/17.20.Continuous Median/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.20.Continuous%20Median/README_EN.md) ## 题目描述 +

    随机产生数字并传递给一个方法。你能否完成这个方法,在每次产生新值时,寻找当前所有值的中间值(中位数)并保存。

    @@ -30,16 +31,18 @@ addNum(3) findMedian() -> 2 - ## 解法 + + - 创建大根堆、小根堆,其中:大根堆存放较小的一半元素,小根堆存放较大的一半元素。 -- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多1);若不等,放入大根堆(使得大小根堆元素个数相等) +- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多 1);若不等,放入大根堆(使得大小根堆元素个数相等) - 取中位数时,若两堆元素个数相等,取两堆顶求平均值;若不等,取小根堆堆顶。 ### **Python3** + ```python @@ -70,6 +73,7 @@ class MedianFinder: ``` ### **Java** + ```java @@ -82,7 +86,7 @@ class MedianFinder { minHeap = new PriorityQueue<>(); maxHeap = new PriorityQueue<>((a, b) -> b - a); } - + public void addNum(int num) { if (minHeap.size() == maxHeap.size()) { maxHeap.offer(num); @@ -92,7 +96,7 @@ class MedianFinder { maxHeap.offer(minHeap.poll()); } } - + public double findMedian() { return minHeap.size() == maxHeap.size() ? (minHeap.peek() + maxHeap.peek()) / 2.0 : minHeap.peek(); } @@ -107,8 +111,9 @@ class MedianFinder { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.20.Continuous Median/README_EN.md b/lcci/17.20.Continuous Median/README_EN.md index 5afb8a27575f2..5d7b85c5bac53 100644 --- a/lcci/17.20.Continuous Median/README_EN.md +++ b/lcci/17.20.Continuous Median/README_EN.md @@ -3,41 +3,26 @@ [中文文档](/lcci/17.20.Continuous%20Median/README.md) ## Description -

    Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.

    - +

    Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.

    - -

    For example,

    - -

    [2,3,4], the median is 3

    - -

    [2,3], the median is (2 + 3) / 2 = 2.5

    - -

    Design a data structure that supports the following two operations:

    - -
    • void addNum(int num) - Add a integer number from the data stream to the data structure.
    • double findMedian() - Return the median of all elements so far.
    - -

    Example:

    - -
     
     addNum(1)
    @@ -52,12 +37,8 @@ findMedian() -> 2
     
     
    - - - ## Solutions - ### **Python3** @@ -101,7 +82,7 @@ class MedianFinder { minHeap = new PriorityQueue<>(); maxHeap = new PriorityQueue<>((a, b) -> b - a); } - + public void addNum(int num) { if (minHeap.size() == maxHeap.size()) { maxHeap.offer(num); @@ -111,7 +92,7 @@ class MedianFinder { maxHeap.offer(minHeap.poll()); } } - + public double findMedian() { return minHeap.size() == maxHeap.size() ? (minHeap.peek() + maxHeap.peek()) / 2.0 : minHeap.peek(); } @@ -126,8 +107,9 @@ class MedianFinder { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.21.Volume of Histogram/README.md b/lcci/17.21.Volume of Histogram/README.md index e014090bc8125..a54c1fba58720 100644 --- a/lcci/17.21.Volume of Histogram/README.md +++ b/lcci/17.21.Volume of Histogram/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) ## 题目描述 +

    给定一个直方图(也称柱状图),假设有人从上面源源不断地倒水,最后直方图能存多少水量?直方图的宽度为 1。

    @@ -15,14 +16,14 @@
    输入: [0,1,0,2,1,0,1,3,2,1,2,1]
     输出: 6
    - ## 解法 - + ### **Python3** + ```python @@ -30,6 +31,7 @@ ``` ### **Java** + ```java @@ -37,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.21.Volume of Histogram/README_EN.md b/lcci/17.21.Volume of Histogram/README_EN.md index 5cdaf874145fd..1e1bc93fe1862 100644 --- a/lcci/17.21.Volume of Histogram/README_EN.md +++ b/lcci/17.21.Volume of Histogram/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/lcci/17.21.Volume%20of%20Histogram/README.md) ## Description -

    Imagine a histogram (bar graph). Design an algorithm to compute the volume of water it could hold if someone poured water across the top. You can assume that each histogram bar has width 1.

    - +

    Imagine a histogram (bar graph). Design an algorithm to compute the volume of water it could hold if someone poured water across the top. You can assume that each histogram bar has width 1.

    ![](./images/rainwatertrap.png) - -

    The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of water (blue section) are being trapped. Thanks Marcos for contributing this image!

    - -

    Example:

    - -
     
     Input: [0,1,0,2,1,0,1,3,2,1,2,1]
     
     Output: 6
    - - - ## Solutions - ### **Python3** @@ -46,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.22.Word Transformer/README.md b/lcci/17.22.Word Transformer/README.md index a265bd153eabc..d721b88f08cfc 100644 --- a/lcci/17.22.Word Transformer/README.md +++ b/lcci/17.22.Word Transformer/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.22.Word%20Transformer/README_EN.md) ## 题目描述 +

    给定字典中的两个词,长度相等。写一个方法,把一个词转换成另一个词, 但是一次只能改变一个字符。每一步得到的新词都必须能在字典中找到。

    @@ -30,14 +31,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以不存在符合要求的转换序列。 - ## 解法 - + ### **Python3** + ```python @@ -45,6 +46,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -52,8 +54,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.22.Word Transformer/README_EN.md b/lcci/17.22.Word Transformer/README_EN.md index 6a0abb6f73cf0..77f9ead091abe 100644 --- a/lcci/17.22.Word Transformer/README_EN.md +++ b/lcci/17.22.Word Transformer/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.22.Word%20Transformer/README.md) ## Description -

    Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.

    - +

    Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.

    Write code to return a possible transforming sequence. If there are more that one sequence, any one is ok.

    - -

    Example 1:

    - -
     
     Input:
    @@ -33,12 +28,8 @@ wordList = ["hot","dot","dog","lot",&quo
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -57,12 +48,8 @@ wordList = ["hot","dot","dog","lot",&quo
     
     Explanation: endWord "cog" is not in the dictionary, so there's no possible transforming sequence.
    - - - ## Solutions - ### **Python3** @@ -78,8 +65,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.23.Max Black Square/README.md b/lcci/17.23.Max Black Square/README.md index 094a675ee954b..a3e26a3ebf265 100644 --- a/lcci/17.23.Max Black Square/README.md +++ b/lcci/17.23.Max Black Square/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.23.Max%20Black%20Square/README_EN.md) ## 题目描述 +

    给定一个方阵,其中每个单元(像素)非黑即白。设计一个算法,找出 4 条边皆为黑色像素的最大子方阵。

    @@ -37,14 +38,14 @@
  • matrix.length == matrix[0].length <= 200
  • - ## 解法 - + ### **Python3** + ```python @@ -52,6 +53,7 @@ ``` ### **Java** + ```java @@ -59,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.23.Max Black Square/README_EN.md b/lcci/17.23.Max Black Square/README_EN.md index 55aca83d1133e..a73d70fa4c6a8 100644 --- a/lcci/17.23.Max Black Square/README_EN.md +++ b/lcci/17.23.Max Black Square/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.23.Max%20Black%20Square/README.md) ## Description -

    Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.

    - +

    Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.

    Return an array [r, c, size], where rc are the row number and the column number of the subsquare's upper left corner respectively, and size is the side length of the subsquare. If there are more than one answers, return the one that has smallest r. If there are more than one answers that have the same r, return the one that has smallest c. If there's no answer, return an empty array.

    - -

    Example 1:

    - -
     
     Input:
    @@ -35,12 +30,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -59,22 +50,14 @@
     
     
    - -

    Note:

    - -
    • matrix.length == matrix[0].length <= 200
    - - - ## Solutions - ### **Python3** @@ -90,8 +73,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.24.Max Submatrix/README.md b/lcci/17.24.Max Submatrix/README.md index e235c5e29f17c..4617dc1d4bc99 100644 --- a/lcci/17.24.Max Submatrix/README.md +++ b/lcci/17.24.Max Submatrix/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.24.Max%20Submatrix/README_EN.md) ## 题目描述 +

    给定一个正整数和负整数组成的 N × M 矩阵,编写代码找出元素总和最大的子矩阵。

    @@ -26,14 +27,14 @@
  • 1 <= matrix.length, matrix[0].length <= 200
  • - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.24.Max Submatrix/README_EN.md b/lcci/17.24.Max Submatrix/README_EN.md index 4ed817816fc29..6369616b68f7d 100644 --- a/lcci/17.24.Max Submatrix/README_EN.md +++ b/lcci/17.24.Max Submatrix/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/17.24.Max%20Submatrix/README.md) ## Description -

    Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum.

    - +

    Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum.

    Return an array [r1, c1, r2, c2], where r1, c1 are the row number and the column number of the submatrix's upper left corner respectively, and r2, c2 are the row number of and the column number of lower right corner. If there are more than one answers, return any one of them.

    - -

    Note: This problem is slightly different from the original one in the book.

    - -

    Example:

    - -
     
     Input:
    @@ -33,22 +26,14 @@
     
     Output: [0,1,0,1]
    - -

    Note:

    - -
    • 1 <= matrix.length, matrix[0].length <= 200
    - - - ## Solutions - ### **Python3** @@ -64,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.25.Word Rectangle/README.md b/lcci/17.25.Word Rectangle/README.md index 3df13b0486216..de9aff428e800 100644 --- a/lcci/17.25.Word Rectangle/README.md +++ b/lcci/17.25.Word Rectangle/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.25.Word%20Rectangle/README_EN.md) ## 题目描述 +

    给定一份单词的清单,设计一个算法,创建由字母组成的面积最大的矩形,其中每一行组成一个单词(自左向右),每一列也组成一个单词(自上而下)。不要求这些单词在清单里连续出现,但要求所有行等长,所有列等高。

    @@ -31,14 +32,14 @@
  • 数据保证单词足够随机
  • - ## 解法 - + ### **Python3** + ```python @@ -46,6 +47,7 @@ ``` ### **Java** + ```java @@ -53,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.25.Word Rectangle/README_EN.md b/lcci/17.25.Word Rectangle/README_EN.md index 0f2a4c7b1e98e..c3925bac93ac4 100644 --- a/lcci/17.25.Word Rectangle/README_EN.md +++ b/lcci/17.25.Word Rectangle/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.25.Word%20Rectangle/README.md) ## Description -

    Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.

    - +

    Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.

    If there are more than one answer, return any one of them. A word can be used more than once.

    - -

    Example 1:

    - -
     
     Input: ["this", "real", "hard", "trh", "hea", "iar", "sld"]
    @@ -31,36 +26,24 @@
     
     ]
    - -

    Example 2:

    - -
     
     Input: ["aa"]
     
     Output: ["aa","aa"]
    - -

    Notes:

    - -
    • words.length <= 1000
    • words[i].length <= 100
    • It's guaranteed that all the words are randomly generated.
    - - - ## Solutions - ### **Python3** @@ -76,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.26.Sparse Similarity/README.md b/lcci/17.26.Sparse Similarity/README.md index 5371dccb026ee..28aa83346bc4d 100644 --- a/lcci/17.26.Sparse Similarity/README.md +++ b/lcci/17.26.Sparse Similarity/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.26.Sparse%20Similarity/README_EN.md) ## 题目描述 +

    两个(具有不同单词的)文档的交集(intersection)中元素的个数除以并集(union)中元素的个数,就是这两个文档的相似度。例如,{1, 5, 3} 和 {1, 7, 2, 3} 的相似度是 0.4,其中,交集的元素有 2 个,并集的元素有 5 个。给定一系列的长篇文档,每个文档元素各不相同,并与一个 ID 相关联。它们的相似度非常“稀疏”,也就是说任选 2 个文档,相似度都很接近 0。请设计一个算法返回每对文档的 ID 及其相似度。只需输出相似度大于 0 的组合。请忽略空文档。为简单起见,可以假定每个文档由一个含有不同整数的数组表示。

    @@ -32,14 +33,14 @@
  • 相似度大于 0 的文档对数不会超过 1000
  • - ## 解法 - + ### **Python3** + ```python @@ -47,6 +48,7 @@ ``` ### **Java** + ```java @@ -54,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.26.Sparse Similarity/README_EN.md b/lcci/17.26.Sparse Similarity/README_EN.md index 10a2e35a755ac..0e64f3e5629cb 100644 --- a/lcci/17.26.Sparse Similarity/README_EN.md +++ b/lcci/17.26.Sparse Similarity/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.26.Sparse%20Similarity/README.md) ## Description -

    The similarity of two documents (each with distinct words) is defined to be the size of the intersection divided by the size of the union. For example, if the documents consist of integers, the similarity of {1, 5, 3} and {1, 7, 2, 3} is 0.4, because the intersection has size 2 and the union has size 5. We have a long list of documents (with distinct values and each with an associated ID) where the similarity is believed to be "sparse". That is, any two arbitrarily selected documents are very likely to have similarity 0. Design an algorithm that returns a list of pairs of document IDs and the associated similarity.

    - +

    The similarity of two documents (each with distinct words) is defined to be the size of the intersection divided by the size of the union. For example, if the documents consist of integers, the similarity of {1, 5, 3} and {1, 7, 2, 3} is 0.4, because the intersection has size 2 and the union has size 5. We have a long list of documents (with distinct values and each with an associated ID) where the similarity is believed to be "sparse". That is, any two arbitrarily selected documents are very likely to have similarity 0. Design an algorithm that returns a list of pairs of document IDs and the associated similarity.

    Input is a 2D array docs, where docs[i] is the document with id i. Return an array of strings, where each string represents a pair of documents with similarity greater than 0. The string should be formatted as  {id1},{id2}: {similarity}, where id1 is the smaller id in the two documents, and similarity is the similarity rounded to four decimal places. You can return the array in any order.

    - -

    Example:

    - -
     
     Input: 
    @@ -43,24 +38,16 @@
     
     ]
    - -

    Note:

    - -
    • docs.length <= 500
    • docs[i].length <= 500
    • The number of document pairs with similarity greater than 0 will not exceed 1000.
    - - - ## Solutions - ### **Python3** @@ -76,8 +63,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/README.md b/lcci/README.md index 84a1cddb29bc5..a79046617cc0e 100644 --- a/lcci/README.md +++ b/lcci/README.md @@ -1,124 +1,127 @@ # [《程序员面试金典(第 6 版)》系列](https://leetcode-cn.com/problemset/lcci/) + 本书是原谷歌资深面试官的经验之作,帮助了许多想要加入脸书、苹果、谷歌等 IT 名企的求职者拿到 Dream offer。本专题的 100+ 编程面试题是在原书基础上精心挑选出来的,帮助你轻松应战 IT 名企技术面试。 [English Version](/lcci/README_EN.md) ## 题解 + 以下所有题目均来源 [LeetCode 中国官网](https://leetcode-cn.com/problemset/lcci/),题解由 [doocs/leetcode 贡献者](https://github.com/doocs/leetcode/graphs/contributors) 提供,正在完善中,欢迎贡献你的题解! 快速搜索题号、题解、标签等,请善用 Control+F(或者 Command+F)。 -| 题号 | 题解 | 标签 | 难度 | -| --- | --- | --- | --- | -| [01.01](https://leetcode-cn.com/problems/is-unique-lcci) | [判定字符是否唯一](/lcci/01.01.Is%20Unique/README.md) | `数组` | 简单 | -| [01.02](https://leetcode-cn.com/problems/check-permutation-lcci) | [判定是否互为字符重排](/lcci/01.02.Check%20Permutation/README.md) | `数组`,`字符串` | 简单 | -| [01.03](https://leetcode-cn.com/problems/string-to-url-lcci) | [URL化](/lcci/01.03.String%20to%20URL/README.md) | `字符串` | 简单 | -| [01.04](https://leetcode-cn.com/problems/palindrome-permutation-lcci) | [回文排列](/lcci/01.04.Palindrome%20Permutation/README.md) | `哈希表`,`字符串` | 简单 | -| [01.05](https://leetcode-cn.com/problems/one-away-lcci) | [一次编辑](/lcci/01.05.One%20Away/README.md) | `字符串`,`动态规划` | 中等 | -| [01.06](https://leetcode-cn.com/problems/compress-string-lcci) | [字符串压缩](/lcci/01.06.Compress%20String/README.md) | `字符串` | 简单 | -| [01.07](https://leetcode-cn.com/problems/rotate-matrix-lcci) | [旋转矩阵](/lcci/01.07.Rotate%20Matrix/README.md) | `数组` | 中等 | -| [01.08](https://leetcode-cn.com/problems/zero-matrix-lcci) | [零矩阵](/lcci/01.08.Zero%20Matrix/README.md) | `数组` | 中等 | -| [01.09](https://leetcode-cn.com/problems/string-rotation-lcci) | [字符串轮转](/lcci/01.09.String%20Rotation/README.md) | `字符串` | 简单 | -| [02.01](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) | [移除重复节点](/lcci/02.01.Remove%20Duplicate%20Node/README.md) | `链表` | 简单 | -| [02.02](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) | [返回倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) | `链表`,`双指针` | 简单 | -| [02.03](https://leetcode-cn.com/problems/delete-middle-node-lcci) | [删除中间节点](/lcci/02.03.Delete%20Middle%20Node/README.md) | `链表` | 简单 | -| [02.04](https://leetcode-cn.com/problems/partition-list-lcci) | [分割链表](/lcci/02.04.Partition%20List/README.md) | `链表`,`双指针` | 中等 | -| [02.05](https://leetcode-cn.com/problems/sum-lists-lcci) | [链表求和](/lcci/02.05.Sum%20Lists/README.md) | `链表`,`数学` | 中等 | -| [02.06](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) | [回文链表](/lcci/02.06.Palindrome%20Linked%20List/README.md) | `链表` | 简单 | -| [02.07](https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci) | [链表相交](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README.md) | `链表` | 简单 | -| [02.08](https://leetcode-cn.com/problems/linked-list-cycle-lcci) | [环路检测](/lcci/02.08.Linked%20List%20Cycle/README.md) | `链表` | 中等 | -| [03.01](https://leetcode-cn.com/problems/three-in-one-lcci) | [三合一](/lcci/03.01.Three%20in%20One/README.md) | `设计` | 简单 | -| [03.02](https://leetcode-cn.com/problems/min-stack-lcci) | [栈的最小值](/lcci/03.02.Min%20Stack/README.md) | `栈` | 简单 | -| [03.03](https://leetcode-cn.com/problems/stack-of-plates-lcci) | [堆盘子](/lcci/03.03.Stack%20of%20Plates/README.md) | `设计` | 中等 | -| [03.04](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) | [化栈为队](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) | `栈` | 简单 | -| [03.05](https://leetcode-cn.com/problems/sort-of-stacks-lcci) | [栈排序](/lcci/03.05.Sort%20of%20Stacks/README.md) | `设计` | 中等 | -| [03.06](https://leetcode-cn.com/problems/animal-shelter-lcci) | [动物收容所](/lcci/03.06.Animal%20Shelter/README.md) | `设计` | 简单 | -| [04.01](https://leetcode-cn.com/problems/route-between-nodes-lcci) | [节点间通路](/lcci/04.01.Route%20Between%20Nodes/README.md) | `图` | 中等 | -| [04.02](https://leetcode-cn.com/problems/minimum-height-tree-lcci) | [最小高度树](/lcci/04.02.Minimum%20Height%20Tree/README.md) | `树`,`深度优先搜索` | 简单 | -| [04.03](https://leetcode-cn.com/problems/list-of-depth-lcci) | [特定深度节点链表](/lcci/04.03.List%20of%20Depth/README.md) | `树`,`广度优先搜索` | 中等 | -| [04.04](https://leetcode-cn.com/problems/check-balance-lcci) | [检查平衡性](/lcci/04.04.Check%20Balance/README.md) | `树`,`深度优先搜索` | 简单 | -| [04.05](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) | [合法二叉搜索树](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) | `树`,`深度优先搜索` | 中等 | -| [04.06](https://leetcode-cn.com/problems/successor-lcci) | [后继者](/lcci/04.06.Successor/README.md) | `树`,`深度优先搜索` | 中等 | -| [04.08](https://leetcode-cn.com/problems/first-common-ancestor-lcci) | [首个共同祖先](/lcci/04.08.First%20Common%20Ancestor/README.md) | `树` | 中等 | -| [04.09](https://leetcode-cn.com/problems/bst-sequences-lcci) | [二叉搜索树序列](/lcci/04.09.BST%20Sequences/README.md) | `树`,`动态规划` | 困难 | -| [04.10](https://leetcode-cn.com/problems/check-subtree-lcci) | [检查子树](/lcci/04.10.Check%20SubTree/README.md) | `树` | 中等 | -| [04.12](https://leetcode-cn.com/problems/paths-with-sum-lcci) | [求和路径](/lcci/04.12.Paths%20with%20Sum/README.md) | `树`,`深度优先搜索` | 中等 | -| [05.01](https://leetcode-cn.com/problems/insert-into-bits-lcci) | [插入](/lcci/05.01.Insert%20Into%20Bits/README.md) | `位运算` | 简单 | -| [05.02](https://leetcode-cn.com/problems/bianry-number-to-string-lcci) | [二进制数转字符串](/lcci/05.02.Bianry%20Number%20to%20String/README.md) | `字符串` | 中等 | -| [05.03](https://leetcode-cn.com/problems/reverse-bits-lcci) | [翻转数位](/lcci/05.03.Reverse%20Bits/README.md) | `位运算` | 简单 | -| [05.04](https://leetcode-cn.com/problems/closed-number-lcci) | [下一个数](/lcci/05.04.Closed%20Number/README.md) | `位运算` | 中等 | -| [05.06](https://leetcode-cn.com/problems/convert-integer-lcci) | [整数转换](/lcci/05.06.Convert%20Integer/README.md) | `位运算` | 简单 | -| [05.07](https://leetcode-cn.com/problems/exchange-lcci) | [配对交换](/lcci/05.07.Exchange/README.md) | `位运算` | 简单 | -| [05.08](https://leetcode-cn.com/problems/draw-line-lcci) | [绘制直线](/lcci/05.08.Draw%20Line/README.md) | `数组` | 中等 | -| [08.01](https://leetcode-cn.com/problems/three-steps-problem-lcci) | [三步问题](/lcci/08.01.Three%20Steps%20Problem/README.md) | `动态规划` | 简单 | -| [08.02](https://leetcode-cn.com/problems/robot-in-a-grid-lcci) | [迷路的机器人](/lcci/08.02.Robot%20in%20a%20Grid/README.md) | `动态规划` | 中等 | -| [08.03](https://leetcode-cn.com/problems/magic-index-lcci) | [魔术索引](/lcci/08.03.Magic%20Index/README.md) | `数组`,`二分查找` | 简单 | -| [08.04](https://leetcode-cn.com/problems/power-set-lcci) | [幂集](/lcci/08.04.Power%20Set/README.md) | `位运算`,`数组`,`回溯算法` | 中等 | -| [08.05](https://leetcode-cn.com/problems/recursive-mulitply-lcci) | [递归乘法](/lcci/08.05.Recursive%20Mulitply/README.md) | `递归` | 中等 | -| [08.06](https://leetcode-cn.com/problems/hanota-lcci) | [汉诺塔问题](/lcci/08.06.Hanota/README.md) | `递归` | 简单 | -| [08.07](https://leetcode-cn.com/problems/permutation-i-lcci) | [无重复字符串的排列组合](/lcci/08.07.Permutation%20I/README.md) | `回溯算法` | 中等 | -| [08.08](https://leetcode-cn.com/problems/permutation-ii-lcci) | [有重复字符串的排列组合](/lcci/08.08.Permutation%20II/README.md) | `回溯算法` | 中等 | -| [08.09](https://leetcode-cn.com/problems/bracket-lcci) | [括号](/lcci/08.09.Bracket/README.md) | `字符串`,`回溯算法` | 中等 | -| [08.10](https://leetcode-cn.com/problems/color-fill-lcci) | [颜色填充](/lcci/08.10.Color%20Fill/README.md) | `深度优先搜索` | 简单 | -| [08.11](https://leetcode-cn.com/problems/coin-lcci) | [硬币](/lcci/08.11.Coin/README.md) | `动态规划` | 中等 | -| [08.12](https://leetcode-cn.com/problems/eight-queens-lcci) | [八皇后](/lcci/08.12.Eight%20Queens/README.md) | `回溯算法` | 困难 | -| [08.13](https://leetcode-cn.com/problems/pile-box-lcci) | [堆箱子](/lcci/08.13.Pile%20Box/README.md) | `动态规划`,`回溯算法` | 困难 | -| [08.14](https://leetcode-cn.com/problems/boolean-evaluation-lcci) | [布尔运算](/lcci/08.14.Boolean%20Evaluation/README.md) | `栈`,`字符串` | 中等 | -| [10.01](https://leetcode-cn.com/problems/sorted-merge-lcci) | [合并排序的数组](/lcci/10.01.Sorted%20Merge/README.md) | `数组`,`双指针` | 简单 | -| [10.02](https://leetcode-cn.com/problems/group-anagrams-lcci) | [变位词组](/lcci/10.02.Group%20Anagrams/README.md) | `哈希表`,`字符串` | 中等 | -| [10.03](https://leetcode-cn.com/problems/search-rotate-array-lcci) | [搜索旋转数组](/lcci/10.03.Search%20Rotate%20Array/README.md) | `数组`,`二分查找` | 中等 | -| [10.05](https://leetcode-cn.com/problems/sparse-array-search-lcci) | [稀疏数组搜索](/lcci/10.05.Sparse%20Array%20Search/README.md) | `二分查找` | 简单 | -| [10.09](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) | [排序矩阵查找](/lcci/10.09.Sorted%20Matrix%20Search/README.md) | `双指针`,`二分查找`,`分治算法` | 中等 | -| [10.10](https://leetcode-cn.com/problems/rank-from-stream-lcci) | [数字流的秩](/lcci/10.10.Rank%20from%20Stream/README.md) | | 中等 | -| [10.11](https://leetcode-cn.com/problems/peaks-and-valleys-lcci) | [峰与谷](/lcci/10.11.Peaks%20and%20Valleys/README.md) | | 中等 | -| [16.01](https://leetcode-cn.com/problems/swap-numbers-lcci) | [交换数字](/lcci/16.01.Swap%20Numbers/README.md) | `位运算`,`数学` | 中等 | -| [16.02](https://leetcode-cn.com/problems/words-frequency-lcci) | [单词频率](/lcci/16.02.Words%20Frequency/README.md) | `设计`,`哈希表` | 中等 | -| [16.03](https://leetcode-cn.com/problems/intersection-lcci) | [交点](/lcci/16.03.Intersection/README.md) | `几何`,`数学` | 困难 | -| [16.04](https://leetcode-cn.com/problems/tic-tac-toe-lcci) | [井字游戏](/lcci/16.04.Tic-Tac-Toe/README.md) | `数组` | 中等 | -| [16.05](https://leetcode-cn.com/problems/factorial-zeros-lcci) | [阶乘尾数](/lcci/16.05.Factorial%20Zeros/README.md) | `数学` | 简单 | -| [16.06](https://leetcode-cn.com/problems/smallest-difference-lcci) | [最小差](/lcci/16.06.Smallest%20Difference/README.md) | `数组`,`双指针` | 中等 | -| [16.07](https://leetcode-cn.com/problems/maximum-lcci) | [最大数值](/lcci/16.07.Maximum/README.md) | `位运算`,`数学` | 简单 | -| [16.08](https://leetcode-cn.com/problems/english-int-lcci) | [整数的英语表示](/lcci/16.08.English%20Int/README.md) | `数学`,`字符串` | 困难 | -| [16.09](https://leetcode-cn.com/problems/operations-lcci) | [运算](/lcci/16.09.Operations/README.md) | `设计` | 中等 | -| [16.10](https://leetcode-cn.com/problems/living-people-lcci) | [生存人数](/lcci/16.10.Living%20People/README.md) | `数组` | 中等 | -| [16.11](https://leetcode-cn.com/problems/diving-board-lcci) | [跳水板](/lcci/16.11.Diving%20Board/README.md) | `递归`,`记忆化` | 简单 | -| [16.13](https://leetcode-cn.com/problems/bisect-squares-lcci) | [平分正方形](/lcci/16.13.Bisect%20Squares/README.md) | `几何` | 中等 | -| [16.14](https://leetcode-cn.com/problems/best-line-lcci) | [最佳直线](/lcci/16.14.Best%20Line/README.md) | `几何`,`哈希表` | 中等 | -| [16.15](https://leetcode-cn.com/problems/master-mind-lcci) | [珠玑妙算](/lcci/16.15.Master%20Mind/README.md) | `数组` | 简单 | -| [16.16](https://leetcode-cn.com/problems/sub-sort-lcci) | [部分排序](/lcci/16.16.Sub%20Sort/README.md) | `排序`,`数组` | 中等 | -| [16.17](https://leetcode-cn.com/problems/contiguous-sequence-lcci) | [连续数列](/lcci/16.17.Contiguous%20Sequence/README.md) | `数组`,`分治算法`,`动态规划` | 简单 | -| [16.18](https://leetcode-cn.com/problems/pattern-matching-lcci) | [模式匹配](/lcci/16.18.Pattern%20Matching/README.md) | `字符串` | 中等 | -| [16.19](https://leetcode-cn.com/problems/pond-sizes-lcci) | [水域大小](/lcci/16.19.Pond%20Sizes/README.md) | `深度优先搜索`,`广度优先搜索` | 中等 | -| [16.20](https://leetcode-cn.com/problems/t9-lcci) | [T9键盘](/lcci/16.20.T9/README.md) | `数组` | 中等 | -| [16.21](https://leetcode-cn.com/problems/sum-swap-lcci) | [交换和](/lcci/16.21.Sum%20Swap/README.md) | `排序`,`数组` | 中等 | -| [16.22](https://leetcode-cn.com/problems/langtons-ant-lcci) | [兰顿蚂蚁](/lcci/16.22.Langtons%20Ant/README.md) | `数组` | 中等 | -| [16.24](https://leetcode-cn.com/problems/pairs-with-sum-lcci) | [数对和](/lcci/16.24.Pairs%20With%20Sum/README.md) | `数组`,`哈希表` | 中等 | -| [16.25](https://leetcode-cn.com/problems/lru-cache-lcci) | [LRU缓存](/lcci/16.25.LRU%20Cache/README.md) | `设计` | 中等 | -| [16.26](https://leetcode-cn.com/problems/calculator-lcci) | [计算器](/lcci/16.26.Calculator/README.md) | `字符串` | 中等 | -| [17.01](https://leetcode-cn.com/problems/add-without-plus-lcci) | [不用加号的加法](/lcci/17.01.Add%20Without%20Plus/README.md) | `位运算` | 简单 | -| [17.04](https://leetcode-cn.com/problems/missing-number-lcci) | [消失的数字](/lcci/17.04.Missing%20Number/README.md) | `位运算`,`数组`,`数学` | 简单 | -| [17.05](https://leetcode-cn.com/problems/find-longest-subarray-lcci) | [ 字母与数字](/lcci/17.05.Find%20Longest%20Subarray/README.md) | `数组` | 中等 | -| [17.06](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) | [2出现的次数](/lcci/17.06.Number%20Of%202s%20In%20Range/README.md) | `数学`,`动态规划` | 中等 | -| [17.07](https://leetcode-cn.com/problems/baby-names-lcci) | [婴儿名字](/lcci/17.07.Baby%20Names/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集` | 中等 | -| [17.08](https://leetcode-cn.com/problems/circus-tower-lcci) | [马戏团人塔](/lcci/17.08.Circus%20Tower/README.md) | `排序`,`二分查找`,`动态规划` | 中等 | -| [17.09](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) | [第 k 个数](/lcci/17.09.Get%20Kth%20Magic%20Number/README.md) | `堆`,`队列`,`数学` | 中等 | -| [17.10](https://leetcode-cn.com/problems/find-majority-element-lcci) | [主要元素](/lcci/17.10.Find%20Majority%20Element/README.md) | `位运算`,`数组`,`分治算法` | 简单 | -| [17.11](https://leetcode-cn.com/problems/find-closest-lcci) | [单词距离](/lcci/17.11.Find%20Closest/README.md) | `双指针`,`字符串` | 中等 | -| [17.12](https://leetcode-cn.com/problems/binode-lcci) | [BiNode](/lcci/17.12.BiNode/README.md) | `树`,`二叉搜索树`,`递归` | 简单 | -| [17.13](https://leetcode-cn.com/problems/re-space-lcci) | [恢复空格](/lcci/17.13.Re-Space/README.md) | `记忆化`,`字符串` | 中等 | -| [17.14](https://leetcode-cn.com/problems/smallest-k-lcci) | [最小K个数](/lcci/17.14.Smallest%20K/README.md) | `堆`,`排序`,`分治算法` | 中等 | -| [17.15](https://leetcode-cn.com/problems/longest-word-lcci) | [最长单词](/lcci/17.15.Longest%20Word/README.md) | `字符串` | 中等 | -| [17.16](https://leetcode-cn.com/problems/the-masseuse-lcci) | [按摩师](/lcci/17.16.The%20Masseuse/README.md) | `动态规划` | 简单 | -| [17.17](https://leetcode-cn.com/problems/multi-search-lcci) | [多次搜索](/lcci/17.17.Multi%20Search/README.md) | `字典树`,`字符串` | 中等 | -| [17.18](https://leetcode-cn.com/problems/shortest-supersequence-lcci) | [最短超串](/lcci/17.18.Shortest%20Supersequence/README.md) | `None` | 中等 | -| [17.19](https://leetcode-cn.com/problems/missing-two-lcci) | [消失的两个数字](/lcci/17.19.Missing%20Two/README.md) | `数组`,`数学` | 困难 | -| [17.20](https://leetcode-cn.com/problems/continuous-median-lcci) | [连续中值](/lcci/17.20.Continuous%20Median/README.md) | `堆` | 困难 | -| [17.21](https://leetcode-cn.com/problems/volume-of-histogram-lcci) | [直方图的水量](/lcci/17.21.Volume%20of%20Histogram/README.md) | `栈`,`数组`,`双指针` | 困难 | -| [17.22](https://leetcode-cn.com/problems/word-transformer-lcci) | [单词转换](/lcci/17.22.Word%20Transformer/README.md) | `深度优先搜索`,`广度优先搜索`,`数组`,`字符串` | 中等 | -| [17.23](https://leetcode-cn.com/problems/max-black-square-lcci) | [最大黑方阵](/lcci/17.23.Max%20Black%20Square/README.md) | `动态规划` | 中等 | -| [17.24](https://leetcode-cn.com/problems/max-submatrix-lcci) | [最大子矩阵](/lcci/17.24.Max%20Submatrix/README.md) | `动态规划` | 困难 | -| [17.25](https://leetcode-cn.com/problems/word-rectangle-lcci) | [单词矩阵](/lcci/17.25.Word%20Rectangle/README.md) | | 困难 | -| [17.26](https://leetcode-cn.com/problems/sparse-similarity-lcci) | [稀疏相似度](/lcci/17.26.Sparse%20Similarity/README.md) | `哈希表` | 困难 | +| 题号 | 题解 | 标签 | 难度 | +| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | --------------------------------------------- | ---- | +| [01.01](https://leetcode-cn.com/problems/is-unique-lcci) | [判定字符是否唯一](/lcci/01.01.Is%20Unique/README.md) | `数组` | 简单 | +| [01.02](https://leetcode-cn.com/problems/check-permutation-lcci) | [判定是否互为字符重排](/lcci/01.02.Check%20Permutation/README.md) | `数组`,`字符串` | 简单 | +| [01.03](https://leetcode-cn.com/problems/string-to-url-lcci) | [URL 化](/lcci/01.03.String%20to%20URL/README.md) | `字符串` | 简单 | +| [01.04](https://leetcode-cn.com/problems/palindrome-permutation-lcci) | [回文排列](/lcci/01.04.Palindrome%20Permutation/README.md) | `哈希表`,`字符串` | 简单 | +| [01.05](https://leetcode-cn.com/problems/one-away-lcci) | [一次编辑](/lcci/01.05.One%20Away/README.md) | `字符串`,`动态规划` | 中等 | +| [01.06](https://leetcode-cn.com/problems/compress-string-lcci) | [字符串压缩](/lcci/01.06.Compress%20String/README.md) | `字符串` | 简单 | +| [01.07](https://leetcode-cn.com/problems/rotate-matrix-lcci) | [旋转矩阵](/lcci/01.07.Rotate%20Matrix/README.md) | `数组` | 中等 | +| [01.08](https://leetcode-cn.com/problems/zero-matrix-lcci) | [零矩阵](/lcci/01.08.Zero%20Matrix/README.md) | `数组` | 中等 | +| [01.09](https://leetcode-cn.com/problems/string-rotation-lcci) | [字符串轮转](/lcci/01.09.String%20Rotation/README.md) | `字符串` | 简单 | +| [02.01](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) | [移除重复节点](/lcci/02.01.Remove%20Duplicate%20Node/README.md) | `链表` | 简单 | +| [02.02](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) | [返回倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) | `链表`,`双指针` | 简单 | +| [02.03](https://leetcode-cn.com/problems/delete-middle-node-lcci) | [删除中间节点](/lcci/02.03.Delete%20Middle%20Node/README.md) | `链表` | 简单 | +| [02.04](https://leetcode-cn.com/problems/partition-list-lcci) | [分割链表](/lcci/02.04.Partition%20List/README.md) | `链表`,`双指针` | 中等 | +| [02.05](https://leetcode-cn.com/problems/sum-lists-lcci) | [链表求和](/lcci/02.05.Sum%20Lists/README.md) | `链表`,`数学` | 中等 | +| [02.06](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) | [回文链表](/lcci/02.06.Palindrome%20Linked%20List/README.md) | `链表` | 简单 | +| [02.07](https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci) | [链表相交](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README.md) | `链表` | 简单 | +| [02.08](https://leetcode-cn.com/problems/linked-list-cycle-lcci) | [环路检测](/lcci/02.08.Linked%20List%20Cycle/README.md) | `链表` | 中等 | +| [03.01](https://leetcode-cn.com/problems/three-in-one-lcci) | [三合一](/lcci/03.01.Three%20in%20One/README.md) | `设计` | 简单 | +| [03.02](https://leetcode-cn.com/problems/min-stack-lcci) | [栈的最小值](/lcci/03.02.Min%20Stack/README.md) | `栈` | 简单 | +| [03.03](https://leetcode-cn.com/problems/stack-of-plates-lcci) | [堆盘子](/lcci/03.03.Stack%20of%20Plates/README.md) | `设计` | 中等 | +| [03.04](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) | [化栈为队](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) | `栈` | 简单 | +| [03.05](https://leetcode-cn.com/problems/sort-of-stacks-lcci) | [栈排序](/lcci/03.05.Sort%20of%20Stacks/README.md) | `设计` | 中等 | +| [03.06](https://leetcode-cn.com/problems/animal-shelter-lcci) | [动物收容所](/lcci/03.06.Animal%20Shelter/README.md) | `设计` | 简单 | +| [04.01](https://leetcode-cn.com/problems/route-between-nodes-lcci) | [节点间通路](/lcci/04.01.Route%20Between%20Nodes/README.md) | `图` | 中等 | +| [04.02](https://leetcode-cn.com/problems/minimum-height-tree-lcci) | [最小高度树](/lcci/04.02.Minimum%20Height%20Tree/README.md) | `树`,`深度优先搜索` | 简单 | +| [04.03](https://leetcode-cn.com/problems/list-of-depth-lcci) | [特定深度节点链表](/lcci/04.03.List%20of%20Depth/README.md) | `树`,`广度优先搜索` | 中等 | +| [04.04](https://leetcode-cn.com/problems/check-balance-lcci) | [检查平衡性](/lcci/04.04.Check%20Balance/README.md) | `树`,`深度优先搜索` | 简单 | +| [04.05](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) | [合法二叉搜索树](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) | `树`,`深度优先搜索` | 中等 | +| [04.06](https://leetcode-cn.com/problems/successor-lcci) | [后继者](/lcci/04.06.Successor/README.md) | `树`,`深度优先搜索` | 中等 | +| [04.08](https://leetcode-cn.com/problems/first-common-ancestor-lcci) | [首个共同祖先](/lcci/04.08.First%20Common%20Ancestor/README.md) | `树` | 中等 | +| [04.09](https://leetcode-cn.com/problems/bst-sequences-lcci) | [二叉搜索树序列](/lcci/04.09.BST%20Sequences/README.md) | `树`,`动态规划` | 困难 | +| [04.10](https://leetcode-cn.com/problems/check-subtree-lcci) | [检查子树](/lcci/04.10.Check%20SubTree/README.md) | `树` | 中等 | +| [04.12](https://leetcode-cn.com/problems/paths-with-sum-lcci) | [求和路径](/lcci/04.12.Paths%20with%20Sum/README.md) | `树`,`深度优先搜索` | 中等 | +| [05.01](https://leetcode-cn.com/problems/insert-into-bits-lcci) | [插入](/lcci/05.01.Insert%20Into%20Bits/README.md) | `位运算` | 简单 | +| [05.02](https://leetcode-cn.com/problems/bianry-number-to-string-lcci) | [二进制数转字符串](/lcci/05.02.Bianry%20Number%20to%20String/README.md) | `字符串` | 中等 | +| [05.03](https://leetcode-cn.com/problems/reverse-bits-lcci) | [翻转数位](/lcci/05.03.Reverse%20Bits/README.md) | `位运算` | 简单 | +| [05.04](https://leetcode-cn.com/problems/closed-number-lcci) | [下一个数](/lcci/05.04.Closed%20Number/README.md) | `位运算` | 中等 | +| [05.06](https://leetcode-cn.com/problems/convert-integer-lcci) | [整数转换](/lcci/05.06.Convert%20Integer/README.md) | `位运算` | 简单 | +| [05.07](https://leetcode-cn.com/problems/exchange-lcci) | [配对交换](/lcci/05.07.Exchange/README.md) | `位运算` | 简单 | +| [05.08](https://leetcode-cn.com/problems/draw-line-lcci) | [绘制直线](/lcci/05.08.Draw%20Line/README.md) | `数组` | 中等 | +| [08.01](https://leetcode-cn.com/problems/three-steps-problem-lcci) | [三步问题](/lcci/08.01.Three%20Steps%20Problem/README.md) | `动态规划` | 简单 | +| [08.02](https://leetcode-cn.com/problems/robot-in-a-grid-lcci) | [迷路的机器人](/lcci/08.02.Robot%20in%20a%20Grid/README.md) | `动态规划` | 中等 | +| [08.03](https://leetcode-cn.com/problems/magic-index-lcci) | [魔术索引](/lcci/08.03.Magic%20Index/README.md) | `数组`,`二分查找` | 简单 | +| [08.04](https://leetcode-cn.com/problems/power-set-lcci) | [幂集](/lcci/08.04.Power%20Set/README.md) | `位运算`,`数组`,`回溯算法` | 中等 | +| [08.05](https://leetcode-cn.com/problems/recursive-mulitply-lcci) | [递归乘法](/lcci/08.05.Recursive%20Mulitply/README.md) | `递归` | 中等 | +| [08.06](https://leetcode-cn.com/problems/hanota-lcci) | [汉诺塔问题](/lcci/08.06.Hanota/README.md) | `递归` | 简单 | +| [08.07](https://leetcode-cn.com/problems/permutation-i-lcci) | [无重复字符串的排列组合](/lcci/08.07.Permutation%20I/README.md) | `回溯算法` | 中等 | +| [08.08](https://leetcode-cn.com/problems/permutation-ii-lcci) | [有重复字符串的排列组合](/lcci/08.08.Permutation%20II/README.md) | `回溯算法` | 中等 | +| [08.09](https://leetcode-cn.com/problems/bracket-lcci) | [括号](/lcci/08.09.Bracket/README.md) | `字符串`,`回溯算法` | 中等 | +| [08.10](https://leetcode-cn.com/problems/color-fill-lcci) | [颜色填充](/lcci/08.10.Color%20Fill/README.md) | `深度优先搜索` | 简单 | +| [08.11](https://leetcode-cn.com/problems/coin-lcci) | [硬币](/lcci/08.11.Coin/README.md) | `动态规划` | 中等 | +| [08.12](https://leetcode-cn.com/problems/eight-queens-lcci) | [八皇后](/lcci/08.12.Eight%20Queens/README.md) | `回溯算法` | 困难 | +| [08.13](https://leetcode-cn.com/problems/pile-box-lcci) | [堆箱子](/lcci/08.13.Pile%20Box/README.md) | `动态规划`,`回溯算法` | 困难 | +| [08.14](https://leetcode-cn.com/problems/boolean-evaluation-lcci) | [布尔运算](/lcci/08.14.Boolean%20Evaluation/README.md) | `栈`,`字符串` | 中等 | +| [10.01](https://leetcode-cn.com/problems/sorted-merge-lcci) | [合并排序的数组](/lcci/10.01.Sorted%20Merge/README.md) | `数组`,`双指针` | 简单 | +| [10.02](https://leetcode-cn.com/problems/group-anagrams-lcci) | [变位词组](/lcci/10.02.Group%20Anagrams/README.md) | `哈希表`,`字符串` | 中等 | +| [10.03](https://leetcode-cn.com/problems/search-rotate-array-lcci) | [搜索旋转数组](/lcci/10.03.Search%20Rotate%20Array/README.md) | `数组`,`二分查找` | 中等 | +| [10.05](https://leetcode-cn.com/problems/sparse-array-search-lcci) | [稀疏数组搜索](/lcci/10.05.Sparse%20Array%20Search/README.md) | `二分查找` | 简单 | +| [10.09](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) | [排序矩阵查找](/lcci/10.09.Sorted%20Matrix%20Search/README.md) | `双指针`,`二分查找`,`分治算法` | 中等 | +| [10.10](https://leetcode-cn.com/problems/rank-from-stream-lcci) | [数字流的秩](/lcci/10.10.Rank%20from%20Stream/README.md) | | 中等 | +| [10.11](https://leetcode-cn.com/problems/peaks-and-valleys-lcci) | [峰与谷](/lcci/10.11.Peaks%20and%20Valleys/README.md) | | 中等 | +| [16.01](https://leetcode-cn.com/problems/swap-numbers-lcci) | [交换数字](/lcci/16.01.Swap%20Numbers/README.md) | `位运算`,`数学` | 中等 | +| [16.02](https://leetcode-cn.com/problems/words-frequency-lcci) | [单词频率](/lcci/16.02.Words%20Frequency/README.md) | `设计`,`哈希表` | 中等 | +| [16.03](https://leetcode-cn.com/problems/intersection-lcci) | [交点](/lcci/16.03.Intersection/README.md) | `几何`,`数学` | 困难 | +| [16.04](https://leetcode-cn.com/problems/tic-tac-toe-lcci) | [井字游戏](/lcci/16.04.Tic-Tac-Toe/README.md) | `数组` | 中等 | +| [16.05](https://leetcode-cn.com/problems/factorial-zeros-lcci) | [阶乘尾数](/lcci/16.05.Factorial%20Zeros/README.md) | `数学` | 简单 | +| [16.06](https://leetcode-cn.com/problems/smallest-difference-lcci) | [最小差](/lcci/16.06.Smallest%20Difference/README.md) | `数组`,`双指针` | 中等 | +| [16.07](https://leetcode-cn.com/problems/maximum-lcci) | [最大数值](/lcci/16.07.Maximum/README.md) | `位运算`,`数学` | 简单 | +| [16.08](https://leetcode-cn.com/problems/english-int-lcci) | [整数的英语表示](/lcci/16.08.English%20Int/README.md) | `数学`,`字符串` | 困难 | +| [16.09](https://leetcode-cn.com/problems/operations-lcci) | [运算](/lcci/16.09.Operations/README.md) | `设计` | 中等 | +| [16.10](https://leetcode-cn.com/problems/living-people-lcci) | [生存人数](/lcci/16.10.Living%20People/README.md) | `数组` | 中等 | +| [16.11](https://leetcode-cn.com/problems/diving-board-lcci) | [跳水板](/lcci/16.11.Diving%20Board/README.md) | `递归`,`记忆化` | 简单 | +| [16.13](https://leetcode-cn.com/problems/bisect-squares-lcci) | [平分正方形](/lcci/16.13.Bisect%20Squares/README.md) | `几何` | 中等 | +| [16.14](https://leetcode-cn.com/problems/best-line-lcci) | [最佳直线](/lcci/16.14.Best%20Line/README.md) | `几何`,`哈希表` | 中等 | +| [16.15](https://leetcode-cn.com/problems/master-mind-lcci) | [珠玑妙算](/lcci/16.15.Master%20Mind/README.md) | `数组` | 简单 | +| [16.16](https://leetcode-cn.com/problems/sub-sort-lcci) | [部分排序](/lcci/16.16.Sub%20Sort/README.md) | `排序`,`数组` | 中等 | +| [16.17](https://leetcode-cn.com/problems/contiguous-sequence-lcci) | [连续数列](/lcci/16.17.Contiguous%20Sequence/README.md) | `数组`,`分治算法`,`动态规划` | 简单 | +| [16.18](https://leetcode-cn.com/problems/pattern-matching-lcci) | [模式匹配](/lcci/16.18.Pattern%20Matching/README.md) | `字符串` | 中等 | +| [16.19](https://leetcode-cn.com/problems/pond-sizes-lcci) | [水域大小](/lcci/16.19.Pond%20Sizes/README.md) | `深度优先搜索`,`广度优先搜索` | 中等 | +| [16.20](https://leetcode-cn.com/problems/t9-lcci) | [T9 键盘](/lcci/16.20.T9/README.md) | `数组` | 中等 | +| [16.21](https://leetcode-cn.com/problems/sum-swap-lcci) | [交换和](/lcci/16.21.Sum%20Swap/README.md) | `排序`,`数组` | 中等 | +| [16.22](https://leetcode-cn.com/problems/langtons-ant-lcci) | [兰顿蚂蚁](/lcci/16.22.Langtons%20Ant/README.md) | `数组` | 中等 | +| [16.24](https://leetcode-cn.com/problems/pairs-with-sum-lcci) | [数对和](/lcci/16.24.Pairs%20With%20Sum/README.md) | `数组`,`哈希表` | 中等 | +| [16.25](https://leetcode-cn.com/problems/lru-cache-lcci) | [LRU 缓存](/lcci/16.25.LRU%20Cache/README.md) | `设计` | 中等 | +| [16.26](https://leetcode-cn.com/problems/calculator-lcci) | [计算器](/lcci/16.26.Calculator/README.md) | `字符串` | 中等 | +| [17.01](https://leetcode-cn.com/problems/add-without-plus-lcci) | [不用加号的加法](/lcci/17.01.Add%20Without%20Plus/README.md) | `位运算` | 简单 | +| [17.04](https://leetcode-cn.com/problems/missing-number-lcci) | [消失的数字](/lcci/17.04.Missing%20Number/README.md) | `位运算`,`数组`,`数学` | 简单 | +| [17.05](https://leetcode-cn.com/problems/find-longest-subarray-lcci) | [ 字母与数字](/lcci/17.05.Find%20Longest%20Subarray/README.md) | `数组` | 中等 | +| [17.06](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) | [2 出现的次数](/lcci/17.06.Number%20Of%202s%20In%20Range/README.md) | `数学`,`动态规划` | 中等 | +| [17.07](https://leetcode-cn.com/problems/baby-names-lcci) | [婴儿名字](/lcci/17.07.Baby%20Names/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集` | 中等 | +| [17.08](https://leetcode-cn.com/problems/circus-tower-lcci) | [马戏团人塔](/lcci/17.08.Circus%20Tower/README.md) | `排序`,`二分查找`,`动态规划` | 中等 | +| [17.09](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) | [第 k 个数](/lcci/17.09.Get%20Kth%20Magic%20Number/README.md) | `堆`,`队列`,`数学` | 中等 | +| [17.10](https://leetcode-cn.com/problems/find-majority-element-lcci) | [主要元素](/lcci/17.10.Find%20Majority%20Element/README.md) | `位运算`,`数组`,`分治算法` | 简单 | +| [17.11](https://leetcode-cn.com/problems/find-closest-lcci) | [单词距离](/lcci/17.11.Find%20Closest/README.md) | `双指针`,`字符串` | 中等 | +| [17.12](https://leetcode-cn.com/problems/binode-lcci) | [BiNode](/lcci/17.12.BiNode/README.md) | `树`,`二叉搜索树`,`递归` | 简单 | +| [17.13](https://leetcode-cn.com/problems/re-space-lcci) | [恢复空格](/lcci/17.13.Re-Space/README.md) | `记忆化`,`字符串` | 中等 | +| [17.14](https://leetcode-cn.com/problems/smallest-k-lcci) | [最小 K 个数](/lcci/17.14.Smallest%20K/README.md) | `堆`,`排序`,`分治算法` | 中等 | +| [17.15](https://leetcode-cn.com/problems/longest-word-lcci) | [最长单词](/lcci/17.15.Longest%20Word/README.md) | `字符串` | 中等 | +| [17.16](https://leetcode-cn.com/problems/the-masseuse-lcci) | [按摩师](/lcci/17.16.The%20Masseuse/README.md) | `动态规划` | 简单 | +| [17.17](https://leetcode-cn.com/problems/multi-search-lcci) | [多次搜索](/lcci/17.17.Multi%20Search/README.md) | `字典树`,`字符串` | 中等 | +| [17.18](https://leetcode-cn.com/problems/shortest-supersequence-lcci) | [最短超串](/lcci/17.18.Shortest%20Supersequence/README.md) | `None` | 中等 | +| [17.19](https://leetcode-cn.com/problems/missing-two-lcci) | [消失的两个数字](/lcci/17.19.Missing%20Two/README.md) | `数组`,`数学` | 困难 | +| [17.20](https://leetcode-cn.com/problems/continuous-median-lcci) | [连续中值](/lcci/17.20.Continuous%20Median/README.md) | `堆` | 困难 | +| [17.21](https://leetcode-cn.com/problems/volume-of-histogram-lcci) | [直方图的水量](/lcci/17.21.Volume%20of%20Histogram/README.md) | `栈`,`数组`,`双指针` | 困难 | +| [17.22](https://leetcode-cn.com/problems/word-transformer-lcci) | [单词转换](/lcci/17.22.Word%20Transformer/README.md) | `深度优先搜索`,`广度优先搜索`,`数组`,`字符串` | 中等 | +| [17.23](https://leetcode-cn.com/problems/max-black-square-lcci) | [最大黑方阵](/lcci/17.23.Max%20Black%20Square/README.md) | `动态规划` | 中等 | +| [17.24](https://leetcode-cn.com/problems/max-submatrix-lcci) | [最大子矩阵](/lcci/17.24.Max%20Submatrix/README.md) | `动态规划` | 困难 | +| [17.25](https://leetcode-cn.com/problems/word-rectangle-lcci) | [单词矩阵](/lcci/17.25.Word%20Rectangle/README.md) | | 困难 | +| [17.26](https://leetcode-cn.com/problems/sparse-similarity-lcci) | [稀疏相似度](/lcci/17.26.Sparse%20Similarity/README.md) | `哈希表` | 困难 | ## 版权 -著作权归 [GitHub 开源社区 Doocs](https://github.com/doocs) 所有,商业转载请联系 [@yanglbme](mailto:contact@yanglibin.info) 授权,非商业转载请注明出处。 \ No newline at end of file + +著作权归 [GitHub 开源社区 Doocs](https://github.com/doocs) 所有,商业转载请联系 [@yanglbme](mailto:contact@yanglibin.info) 授权,非商业转载请注明出处。 diff --git a/lcci/README_EN.md b/lcci/README_EN.md index 8bf9fe54e30b7..9ecb4fc11313f 100644 --- a/lcci/README_EN.md +++ b/lcci/README_EN.md @@ -1,122 +1,125 @@ -# [*Cracking the Coding Interview, 6th Edition*](http://ahmed-badawy.com/blog/wp-content/uploads/2018/10/Cracking-the-Coding-Interview-6th-Edition-189-Programming-Questions-and-Solutions.pdf) -*Cracking the Coding Interview, 6th Edition* is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hundreds of software engineers. The result is this book. +# [_Cracking the Coding Interview, 6th Edition_](http://ahmed-badawy.com/blog/wp-content/uploads/2018/10/Cracking-the-Coding-Interview-6th-Edition-189-Programming-Questions-and-Solutions.pdf) + +_Cracking the Coding Interview, 6th Edition_ is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hundreds of software engineers. The result is this book. [中文文档](/lcci/README.md) ## Solutions + Press Control+F(or Command+F on the Mac) to search anything you want. -| # | Solution | Tag | Difficulty | -| --- | --- | --- | --- | -| [01.01](https://leetcode-cn.com/problems/is-unique-lcci) | [Is Unique](/lcci/01.01.Is%20Unique/README_EN.md) | `Array` | Easy | -| [01.02](https://leetcode-cn.com/problems/check-permutation-lcci) | [Check Permutation](/lcci/01.02.Check%20Permutation/README_EN.md) | `Array`,`String` | Easy | -| [01.03](https://leetcode-cn.com/problems/string-to-url-lcci) | [String to URL](/lcci/01.03.String%20to%20URL/README_EN.md) | `String` | Easy | -| [01.04](https://leetcode-cn.com/problems/palindrome-permutation-lcci) | [Palindrome Permutation](/lcci/01.04.Palindrome%20Permutation/README_EN.md) | `Hash Table`,`String` | Easy | -| [01.05](https://leetcode-cn.com/problems/one-away-lcci) | [One Away](/lcci/01.05.One%20Away/README_EN.md) | `String`,`Dynamic Programming` | Medium | -| [01.06](https://leetcode-cn.com/problems/compress-string-lcci) | [Compress String](/lcci/01.06.Compress%20String/README_EN.md) | `String` | Easy | -| [01.07](https://leetcode-cn.com/problems/rotate-matrix-lcci) | [Rotate Matrix](/lcci/01.07.Rotate%20Matrix/README_EN.md) | `Array` | Medium | -| [01.08](https://leetcode-cn.com/problems/zero-matrix-lcci) | [Zero Matrix](/lcci/01.08.Zero%20Matrix/README_EN.md) | `Array` | Medium | -| [01.09](https://leetcode-cn.com/problems/string-rotation-lcci) | [String Rotation](/lcci/01.09.String%20Rotation/README_EN.md) | `String` | Easy | -| [02.01](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) | [Remove Duplicate Node](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) | `Linked List` | Easy | -| [02.02](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) | [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) | `Linked List`,`Two Pointers` | Easy | -| [02.03](https://leetcode-cn.com/problems/delete-middle-node-lcci) | [Delete Middle Node](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) | `Linked List` | Easy | -| [02.04](https://leetcode-cn.com/problems/partition-list-lcci) | [Partition List](/lcci/02.04.Partition%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | -| [02.05](https://leetcode-cn.com/problems/sum-lists-lcci) | [Sum Lists](/lcci/02.05.Sum%20Lists/README_EN.md) | `Linked List`,`Math` | Medium | -| [02.06](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) | [Palindrome Linked List](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) | `Linked List` | Easy | -| [02.07](https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci) | [Intersection of Two Linked Lists](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) | `Linked List` | Easy | -| [02.08](https://leetcode-cn.com/problems/linked-list-cycle-lcci) | [Linked List Cycle](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) | `Linked List` | Medium | -| [03.01](https://leetcode-cn.com/problems/three-in-one-lcci) | [Three in One](/lcci/03.01.Three%20in%20One/README_EN.md) | `Design` | Easy | -| [03.02](https://leetcode-cn.com/problems/min-stack-lcci) | [Min Stack](/lcci/03.02.Min%20Stack/README_EN.md) | `Stack` | Easy | -| [03.03](https://leetcode-cn.com/problems/stack-of-plates-lcci) | [Stack of Plates](/lcci/03.03.Stack%20of%20Plates/README_EN.md) | `Design` | Medium | -| [03.04](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) | [Implement Queue using Stacks](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) | `Stack` | Easy | -| [03.05](https://leetcode-cn.com/problems/sort-of-stacks-lcci) | [Sort of Stacks](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) | `Design` | Medium | -| [03.06](https://leetcode-cn.com/problems/animal-shelter-lcci) | [Animal Shelter](/lcci/03.06.Animal%20Shelter/README_EN.md) | `Design` | Easy | -| [04.01](https://leetcode-cn.com/problems/route-between-nodes-lcci) | [Route Between Nodes](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) | `Graph` | Medium | -| [04.02](https://leetcode-cn.com/problems/minimum-height-tree-lcci) | [Minimum Height Tree](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | -| [04.03](https://leetcode-cn.com/problems/list-of-depth-lcci) | [List of Depth](/lcci/04.03.List%20of%20Depth/README_EN.md) | `Tree`,`Breadth-first Search` | Medium | -| [04.04](https://leetcode-cn.com/problems/check-balance-lcci) | [Check Balance](/lcci/04.04.Check%20Balance/README_EN.md) | `Tree`,`Depth-first Search` | Easy | -| [04.05](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) | [Legal Binary Search Tree](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [04.06](https://leetcode-cn.com/problems/successor-lcci) | [Successor](/lcci/04.06.Successor/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [04.08](https://leetcode-cn.com/problems/first-common-ancestor-lcci) | [First Common Ancestor](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) | `Tree` | Medium | -| [04.09](https://leetcode-cn.com/problems/bst-sequences-lcci) | [BST Sequences](/lcci/04.09.BST%20Sequences/README_EN.md) | `Tree`,`Dynamic Programming` | Hard | -| [04.10](https://leetcode-cn.com/problems/check-subtree-lcci) | [Check SubTree](/lcci/04.10.Check%20SubTree/README_EN.md) | `Tree` | Medium | -| [04.12](https://leetcode-cn.com/problems/paths-with-sum-lcci) | [Paths with Sum](/lcci/04.12.Paths%20with%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [05.01](https://leetcode-cn.com/problems/insert-into-bits-lcci) | [Insert Into Bits](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) | `Bit Manipulation` | Easy | -| [05.02](https://leetcode-cn.com/problems/bianry-number-to-string-lcci) | [Bianry Number to String](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) | `String` | Medium | -| [05.03](https://leetcode-cn.com/problems/reverse-bits-lcci) | [Reverse Bits](/lcci/05.03.Reverse%20Bits/README_EN.md) | `Bit Manipulation` | Easy | -| [05.04](https://leetcode-cn.com/problems/closed-number-lcci) | [Closed Number](/lcci/05.04.Closed%20Number/README_EN.md) | `Bit Manipulation` | Medium | -| [05.06](https://leetcode-cn.com/problems/convert-integer-lcci) | [Convert Integer](/lcci/05.06.Convert%20Integer/README_EN.md) | `Bit Manipulation` | Easy | -| [05.07](https://leetcode-cn.com/problems/exchange-lcci) | [Exchange](/lcci/05.07.Exchange/README_EN.md) | `Bit Manipulation` | Easy | -| [05.08](https://leetcode-cn.com/problems/draw-line-lcci) | [Draw Line](/lcci/05.08.Draw%20Line/README_EN.md) | `Array` | Medium | -| [08.01](https://leetcode-cn.com/problems/three-steps-problem-lcci) | [Three Steps Problem](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) | `Dynamic Programming` | Easy | -| [08.02](https://leetcode-cn.com/problems/robot-in-a-grid-lcci) | [Robot in a Grid](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) | `Dynamic Programming` | Medium | -| [08.03](https://leetcode-cn.com/problems/magic-index-lcci) | [Magic Index](/lcci/08.03.Magic%20Index/README_EN.md) | `Array`,`Binary Search` | Easy | -| [08.04](https://leetcode-cn.com/problems/power-set-lcci) | [Power Set](/lcci/08.04.Power%20Set/README_EN.md) | `Bit Manipulation`,`Array`,`Backtracking` | Medium | -| [08.05](https://leetcode-cn.com/problems/recursive-mulitply-lcci) | [Recursive Mulitply](/lcci/08.05.Recursive%20Mulitply/README_EN.md) | `Recursion` | Medium | -| [08.06](https://leetcode-cn.com/problems/hanota-lcci) | [Hanota](/lcci/08.06.Hanota/README_EN.md) | `Recursion` | Easy | -| [08.07](https://leetcode-cn.com/problems/permutation-i-lcci) | [Permutation I](/lcci/08.07.Permutation%20I/README_EN.md) | `Backtracking` | Medium | -| [08.08](https://leetcode-cn.com/problems/permutation-ii-lcci) | [Permutation II](/lcci/08.08.Permutation%20II/README_EN.md) | `Backtracking` | Medium | -| [08.09](https://leetcode-cn.com/problems/bracket-lcci) | [Bracket](/lcci/08.09.Bracket/README_EN.md) | `String`,`Backtracking` | Medium | -| [08.10](https://leetcode-cn.com/problems/color-fill-lcci) | [Color Fill](/lcci/08.10.Color%20Fill/README_EN.md) | `Depth-first Search` | Easy | -| [08.11](https://leetcode-cn.com/problems/coin-lcci) | [Coin](/lcci/08.11.Coin/README_EN.md) | `Dynamic Programming` | Medium | -| [08.12](https://leetcode-cn.com/problems/eight-queens-lcci) | [Eight Queens](/lcci/08.12.Eight%20Queens/README_EN.md) | `Backtracking` | Hard | -| [08.13](https://leetcode-cn.com/problems/pile-box-lcci) | [Pile Box](/lcci/08.13.Pile%20Box/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | -| [08.14](https://leetcode-cn.com/problems/boolean-evaluation-lcci) | [Boolean Evaluation](/lcci/08.14.Boolean%20Evaluation/README_EN.md) | `Stack`,`String` | Medium | -| [10.01](https://leetcode-cn.com/problems/sorted-merge-lcci) | [Sorted Merge](/lcci/10.01.Sorted%20Merge/README_EN.md) | `Array`,`Two Pointers` | Easy | -| [10.02](https://leetcode-cn.com/problems/group-anagrams-lcci) | [Group Anagrams](/lcci/10.02.Group%20Anagrams/README_EN.md) | `Hash Table`,`String` | Medium | -| [10.03](https://leetcode-cn.com/problems/search-rotate-array-lcci) | [Search Rotate Array](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | -| [10.05](https://leetcode-cn.com/problems/sparse-array-search-lcci) | [Sparse Array Search](/lcci/10.05.Sparse%20Array%20Search/README_EN.md) | `Binary Search` | Easy | -| [10.09](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) | [Sorted Matrix Search](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) | `Two Pointers`,`Binary Search`,`Divide and Conquer` | Medium | -| [10.10](https://leetcode-cn.com/problems/rank-from-stream-lcci) | [Rank from Stream](/lcci/10.10.Rank%20from%20Stream/README_EN.md) | | Medium | -| [10.11](https://leetcode-cn.com/problems/peaks-and-valleys-lcci) | [Peaks and Valleys](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) | | Medium | -| [16.01](https://leetcode-cn.com/problems/swap-numbers-lcci) | [Swap Numbers](/lcci/16.01.Swap%20Numbers/README_EN.md) | `Bit Manipulation`,`Math` | Medium | -| [16.02](https://leetcode-cn.com/problems/words-frequency-lcci) | [Words Frequency](/lcci/16.02.Words%20Frequency/README_EN.md) | `Design`,`Hash Table` | Medium | -| [16.03](https://leetcode-cn.com/problems/intersection-lcci) | [Intersection](/lcci/16.03.Intersection/README_EN.md) | `Geometry`,`Math` | Hard | -| [16.04](https://leetcode-cn.com/problems/tic-tac-toe-lcci) | [Tic-Tac-Toe](/lcci/16.04.Tic-Tac-Toe/README_EN.md) | `Array` | Medium | -| [16.05](https://leetcode-cn.com/problems/factorial-zeros-lcci) | [Factorial Zeros](/lcci/16.05.Factorial%20Zeros/README_EN.md) | `Math` | Easy | -| [16.06](https://leetcode-cn.com/problems/smallest-difference-lcci) | [Smallest Difference](/lcci/16.06.Smallest%20Difference/README_EN.md) | `Array`,`Two Pointers` | Medium | -| [16.07](https://leetcode-cn.com/problems/maximum-lcci) | [Maximum](/lcci/16.07.Maximum/README_EN.md) | `Bit Manipulation`,`Math` | Easy | -| [16.08](https://leetcode-cn.com/problems/english-int-lcci) | [English Int](/lcci/16.08.English%20Int/README_EN.md) | `Math`,`String` | Hard | -| [16.09](https://leetcode-cn.com/problems/operations-lcci) | [Operations](/lcci/16.09.Operations/README_EN.md) | `Design` | Medium | -| [16.10](https://leetcode-cn.com/problems/living-people-lcci) | [Living People](/lcci/16.10.Living%20People/README_EN.md) | `Array` | Medium | -| [16.11](https://leetcode-cn.com/problems/diving-board-lcci) | [Diving Board](/lcci/16.11.Diving%20Board/README_EN.md) | `Recursion`,`Memoization` | Easy | -| [16.13](https://leetcode-cn.com/problems/bisect-squares-lcci) | [Bisect Squares](/lcci/16.13.Bisect%20Squares/README_EN.md) | `Geometry` | Medium | -| [16.14](https://leetcode-cn.com/problems/best-line-lcci) | [Best Line](/lcci/16.14.Best%20Line/README_EN.md) | `Geometry`,`Hash Table` | Medium | -| [16.15](https://leetcode-cn.com/problems/master-mind-lcci) | [Master Mind](/lcci/16.15.Master%20Mind/README_EN.md) | `Array` | Easy | -| [16.16](https://leetcode-cn.com/problems/sub-sort-lcci) | [Sub Sort](/lcci/16.16.Sub%20Sort/README_EN.md) | `Sort`,`Array` | Medium | -| [16.17](https://leetcode-cn.com/problems/contiguous-sequence-lcci) | [Contiguous Sequence](/lcci/16.17.Contiguous%20Sequence/README_EN.md) | `Array`,`Divide and Conquer`,`Dynamic Programming` | Easy | -| [16.18](https://leetcode-cn.com/problems/pattern-matching-lcci) | [Pattern Matching](/lcci/16.18.Pattern%20Matching/README_EN.md) | `String` | Medium | -| [16.19](https://leetcode-cn.com/problems/pond-sizes-lcci) | [Pond Sizes](/lcci/16.19.Pond%20Sizes/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | -| [16.20](https://leetcode-cn.com/problems/t9-lcci) | [T9](/lcci/16.20.T9/README_EN.md) | `Array` | Medium | -| [16.21](https://leetcode-cn.com/problems/sum-swap-lcci) | [Sum Swap](/lcci/16.21.Sum%20Swap/README_EN.md) | `Sort`,`Array` | Medium | -| [16.22](https://leetcode-cn.com/problems/langtons-ant-lcci) | [Langtons Ant](/lcci/16.22.Langtons%20Ant/README_EN.md) | `Array` | Medium | -| [16.24](https://leetcode-cn.com/problems/pairs-with-sum-lcci) | [Pairs With Sum](/lcci/16.24.Pairs%20With%20Sum/README_EN.md) | `Array`,`Hash Table` | Medium | -| [16.25](https://leetcode-cn.com/problems/lru-cache-lcci) | [LRU Cache](/lcci/16.25.LRU%20Cache/README_EN.md) | `Design` | Medium | -| [16.26](https://leetcode-cn.com/problems/calculator-lcci) | [Calculator](/lcci/16.26.Calculator/README_EN.md) | `String` | Medium | -| [17.01](https://leetcode-cn.com/problems/add-without-plus-lcci) | [Add Without Plus](/lcci/17.01.Add%20Without%20Plus/README_EN.md) | `Bit Manipulation` | Easy | -| [17.04](https://leetcode-cn.com/problems/missing-number-lcci) | [Missing Number](/lcci/17.04.Missing%20Number/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Easy | -| [17.05](https://leetcode-cn.com/problems/find-longest-subarray-lcci) | [Find Longest Subarray](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) | `Array` | Medium | -| [17.06](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) | [Number Of 2s In Range](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) | `Math`,`Dynamic Programming` | Medium | -| [17.07](https://leetcode-cn.com/problems/baby-names-lcci) | [Baby Names](/lcci/17.07.Baby%20Names/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | -| [17.08](https://leetcode-cn.com/problems/circus-tower-lcci) | [Circus Tower](/lcci/17.08.Circus%20Tower/README_EN.md) | `Sort`,`Binary Search`,`Dynamic Programming` | Medium | -| [17.09](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) | [Get Kth Magic Number](/lcci/17.09.Get%20Kth%20Magic%20Number/README_EN.md) | `Heap`,`Queue`,`Math` | Medium | -| [17.10](https://leetcode-cn.com/problems/find-majority-element-lcci) | [Find Majority Element](/lcci/17.10.Find%20Majority%20Element/README_EN.md) | `Bit Manipulation`,`Array`,`Divide and Conquer` | Easy | -| [17.11](https://leetcode-cn.com/problems/find-closest-lcci) | [Find Closest](/lcci/17.11.Find%20Closest/README_EN.md) | `Two Pointers`,`String` | Medium | -| [17.12](https://leetcode-cn.com/problems/binode-lcci) | [BiNode](/lcci/17.12.BiNode/README_EN.md) | `Tree`,`Binary Search Tree`,`Recursion` | Easy | -| [17.13](https://leetcode-cn.com/problems/re-space-lcci) | [Re-Space](/lcci/17.13.Re-Space/README_EN.md) | `Memoization`,`String` | Medium | -| [17.14](https://leetcode-cn.com/problems/smallest-k-lcci) | [Smallest K](/lcci/17.14.Smallest%20K/README_EN.md) | `Heap`,`Sort`,`Divide and Conquer` | Medium | -| [17.15](https://leetcode-cn.com/problems/longest-word-lcci) | [Longest Word](/lcci/17.15.Longest%20Word/README_EN.md) | `String` | Medium | -| [17.16](https://leetcode-cn.com/problems/the-masseuse-lcci) | [The Masseuse](/lcci/17.16.The%20Masseuse/README_EN.md) | `Dynamic Programming` | Easy | -| [17.17](https://leetcode-cn.com/problems/multi-search-lcci) | [Multi Search](/lcci/17.17.Multi%20Search/README_EN.md) | `Trie`,`String` | Medium | -| [17.18](https://leetcode-cn.com/problems/shortest-supersequence-lcci) | [Shortest Supersequence](/lcci/17.18.Shortest%20Supersequence/README_EN.md) | `Sliding Window` | Medium | -| [17.19](https://leetcode-cn.com/problems/missing-two-lcci) | [Missing Two](/lcci/17.19.Missing%20Two/README_EN.md) | `Array`,`Math` | Hard | -| [17.20](https://leetcode-cn.com/problems/continuous-median-lcci) | [Continuous Median](/lcci/17.20.Continuous%20Median/README_EN.md) | `Heap` | Hard | -| [17.21](https://leetcode-cn.com/problems/volume-of-histogram-lcci) | [Volume of Histogram](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) | `Stack`,`Array`,`Two Pointers` | Hard | -| [17.22](https://leetcode-cn.com/problems/word-transformer-lcci) | [Word Transformer](/lcci/17.22.Word%20Transformer/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Array`,`String` | Medium | -| [17.23](https://leetcode-cn.com/problems/max-black-square-lcci) | [Max Black Square](/lcci/17.23.Max%20Black%20Square/README_EN.md) | `Dynamic Programming` | Medium | -| [17.24](https://leetcode-cn.com/problems/max-submatrix-lcci) | [Max Submatrix](/lcci/17.24.Max%20Submatrix/README_EN.md) | `Dynamic Programming` | Hard | -| [17.25](https://leetcode-cn.com/problems/word-rectangle-lcci) | [Word Rectangle](/lcci/17.25.Word%20Rectangle/README_EN.md) | | Hard | -| [17.26](https://leetcode-cn.com/problems/sparse-similarity-lcci) | [Sparse Similarity](/lcci/17.26.Sparse%20Similarity/README_EN.md) | `Hash Table` | Hard | +| # | Solution | Tag | Difficulty | +| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------- | +| [01.01](https://leetcode-cn.com/problems/is-unique-lcci) | [Is Unique](/lcci/01.01.Is%20Unique/README_EN.md) | `Array` | Easy | +| [01.02](https://leetcode-cn.com/problems/check-permutation-lcci) | [Check Permutation](/lcci/01.02.Check%20Permutation/README_EN.md) | `Array`,`String` | Easy | +| [01.03](https://leetcode-cn.com/problems/string-to-url-lcci) | [String to URL](/lcci/01.03.String%20to%20URL/README_EN.md) | `String` | Easy | +| [01.04](https://leetcode-cn.com/problems/palindrome-permutation-lcci) | [Palindrome Permutation](/lcci/01.04.Palindrome%20Permutation/README_EN.md) | `Hash Table`,`String` | Easy | +| [01.05](https://leetcode-cn.com/problems/one-away-lcci) | [One Away](/lcci/01.05.One%20Away/README_EN.md) | `String`,`Dynamic Programming` | Medium | +| [01.06](https://leetcode-cn.com/problems/compress-string-lcci) | [Compress String](/lcci/01.06.Compress%20String/README_EN.md) | `String` | Easy | +| [01.07](https://leetcode-cn.com/problems/rotate-matrix-lcci) | [Rotate Matrix](/lcci/01.07.Rotate%20Matrix/README_EN.md) | `Array` | Medium | +| [01.08](https://leetcode-cn.com/problems/zero-matrix-lcci) | [Zero Matrix](/lcci/01.08.Zero%20Matrix/README_EN.md) | `Array` | Medium | +| [01.09](https://leetcode-cn.com/problems/string-rotation-lcci) | [String Rotation](/lcci/01.09.String%20Rotation/README_EN.md) | `String` | Easy | +| [02.01](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) | [Remove Duplicate Node](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) | `Linked List` | Easy | +| [02.02](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) | [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) | `Linked List`,`Two Pointers` | Easy | +| [02.03](https://leetcode-cn.com/problems/delete-middle-node-lcci) | [Delete Middle Node](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) | `Linked List` | Easy | +| [02.04](https://leetcode-cn.com/problems/partition-list-lcci) | [Partition List](/lcci/02.04.Partition%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | +| [02.05](https://leetcode-cn.com/problems/sum-lists-lcci) | [Sum Lists](/lcci/02.05.Sum%20Lists/README_EN.md) | `Linked List`,`Math` | Medium | +| [02.06](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) | [Palindrome Linked List](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) | `Linked List` | Easy | +| [02.07](https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci) | [Intersection of Two Linked Lists](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) | `Linked List` | Easy | +| [02.08](https://leetcode-cn.com/problems/linked-list-cycle-lcci) | [Linked List Cycle](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) | `Linked List` | Medium | +| [03.01](https://leetcode-cn.com/problems/three-in-one-lcci) | [Three in One](/lcci/03.01.Three%20in%20One/README_EN.md) | `Design` | Easy | +| [03.02](https://leetcode-cn.com/problems/min-stack-lcci) | [Min Stack](/lcci/03.02.Min%20Stack/README_EN.md) | `Stack` | Easy | +| [03.03](https://leetcode-cn.com/problems/stack-of-plates-lcci) | [Stack of Plates](/lcci/03.03.Stack%20of%20Plates/README_EN.md) | `Design` | Medium | +| [03.04](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) | [Implement Queue using Stacks](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) | `Stack` | Easy | +| [03.05](https://leetcode-cn.com/problems/sort-of-stacks-lcci) | [Sort of Stacks](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) | `Design` | Medium | +| [03.06](https://leetcode-cn.com/problems/animal-shelter-lcci) | [Animal Shelter](/lcci/03.06.Animal%20Shelter/README_EN.md) | `Design` | Easy | +| [04.01](https://leetcode-cn.com/problems/route-between-nodes-lcci) | [Route Between Nodes](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) | `Graph` | Medium | +| [04.02](https://leetcode-cn.com/problems/minimum-height-tree-lcci) | [Minimum Height Tree](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | +| [04.03](https://leetcode-cn.com/problems/list-of-depth-lcci) | [List of Depth](/lcci/04.03.List%20of%20Depth/README_EN.md) | `Tree`,`Breadth-first Search` | Medium | +| [04.04](https://leetcode-cn.com/problems/check-balance-lcci) | [Check Balance](/lcci/04.04.Check%20Balance/README_EN.md) | `Tree`,`Depth-first Search` | Easy | +| [04.05](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) | [Legal Binary Search Tree](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | +| [04.06](https://leetcode-cn.com/problems/successor-lcci) | [Successor](/lcci/04.06.Successor/README_EN.md) | `Tree`,`Depth-first Search` | Medium | +| [04.08](https://leetcode-cn.com/problems/first-common-ancestor-lcci) | [First Common Ancestor](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) | `Tree` | Medium | +| [04.09](https://leetcode-cn.com/problems/bst-sequences-lcci) | [BST Sequences](/lcci/04.09.BST%20Sequences/README_EN.md) | `Tree`,`Dynamic Programming` | Hard | +| [04.10](https://leetcode-cn.com/problems/check-subtree-lcci) | [Check SubTree](/lcci/04.10.Check%20SubTree/README_EN.md) | `Tree` | Medium | +| [04.12](https://leetcode-cn.com/problems/paths-with-sum-lcci) | [Paths with Sum](/lcci/04.12.Paths%20with%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Medium | +| [05.01](https://leetcode-cn.com/problems/insert-into-bits-lcci) | [Insert Into Bits](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) | `Bit Manipulation` | Easy | +| [05.02](https://leetcode-cn.com/problems/bianry-number-to-string-lcci) | [Bianry Number to String](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) | `String` | Medium | +| [05.03](https://leetcode-cn.com/problems/reverse-bits-lcci) | [Reverse Bits](/lcci/05.03.Reverse%20Bits/README_EN.md) | `Bit Manipulation` | Easy | +| [05.04](https://leetcode-cn.com/problems/closed-number-lcci) | [Closed Number](/lcci/05.04.Closed%20Number/README_EN.md) | `Bit Manipulation` | Medium | +| [05.06](https://leetcode-cn.com/problems/convert-integer-lcci) | [Convert Integer](/lcci/05.06.Convert%20Integer/README_EN.md) | `Bit Manipulation` | Easy | +| [05.07](https://leetcode-cn.com/problems/exchange-lcci) | [Exchange](/lcci/05.07.Exchange/README_EN.md) | `Bit Manipulation` | Easy | +| [05.08](https://leetcode-cn.com/problems/draw-line-lcci) | [Draw Line](/lcci/05.08.Draw%20Line/README_EN.md) | `Array` | Medium | +| [08.01](https://leetcode-cn.com/problems/three-steps-problem-lcci) | [Three Steps Problem](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) | `Dynamic Programming` | Easy | +| [08.02](https://leetcode-cn.com/problems/robot-in-a-grid-lcci) | [Robot in a Grid](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) | `Dynamic Programming` | Medium | +| [08.03](https://leetcode-cn.com/problems/magic-index-lcci) | [Magic Index](/lcci/08.03.Magic%20Index/README_EN.md) | `Array`,`Binary Search` | Easy | +| [08.04](https://leetcode-cn.com/problems/power-set-lcci) | [Power Set](/lcci/08.04.Power%20Set/README_EN.md) | `Bit Manipulation`,`Array`,`Backtracking` | Medium | +| [08.05](https://leetcode-cn.com/problems/recursive-mulitply-lcci) | [Recursive Mulitply](/lcci/08.05.Recursive%20Mulitply/README_EN.md) | `Recursion` | Medium | +| [08.06](https://leetcode-cn.com/problems/hanota-lcci) | [Hanota](/lcci/08.06.Hanota/README_EN.md) | `Recursion` | Easy | +| [08.07](https://leetcode-cn.com/problems/permutation-i-lcci) | [Permutation I](/lcci/08.07.Permutation%20I/README_EN.md) | `Backtracking` | Medium | +| [08.08](https://leetcode-cn.com/problems/permutation-ii-lcci) | [Permutation II](/lcci/08.08.Permutation%20II/README_EN.md) | `Backtracking` | Medium | +| [08.09](https://leetcode-cn.com/problems/bracket-lcci) | [Bracket](/lcci/08.09.Bracket/README_EN.md) | `String`,`Backtracking` | Medium | +| [08.10](https://leetcode-cn.com/problems/color-fill-lcci) | [Color Fill](/lcci/08.10.Color%20Fill/README_EN.md) | `Depth-first Search` | Easy | +| [08.11](https://leetcode-cn.com/problems/coin-lcci) | [Coin](/lcci/08.11.Coin/README_EN.md) | `Dynamic Programming` | Medium | +| [08.12](https://leetcode-cn.com/problems/eight-queens-lcci) | [Eight Queens](/lcci/08.12.Eight%20Queens/README_EN.md) | `Backtracking` | Hard | +| [08.13](https://leetcode-cn.com/problems/pile-box-lcci) | [Pile Box](/lcci/08.13.Pile%20Box/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | +| [08.14](https://leetcode-cn.com/problems/boolean-evaluation-lcci) | [Boolean Evaluation](/lcci/08.14.Boolean%20Evaluation/README_EN.md) | `Stack`,`String` | Medium | +| [10.01](https://leetcode-cn.com/problems/sorted-merge-lcci) | [Sorted Merge](/lcci/10.01.Sorted%20Merge/README_EN.md) | `Array`,`Two Pointers` | Easy | +| [10.02](https://leetcode-cn.com/problems/group-anagrams-lcci) | [Group Anagrams](/lcci/10.02.Group%20Anagrams/README_EN.md) | `Hash Table`,`String` | Medium | +| [10.03](https://leetcode-cn.com/problems/search-rotate-array-lcci) | [Search Rotate Array](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | +| [10.05](https://leetcode-cn.com/problems/sparse-array-search-lcci) | [Sparse Array Search](/lcci/10.05.Sparse%20Array%20Search/README_EN.md) | `Binary Search` | Easy | +| [10.09](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) | [Sorted Matrix Search](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) | `Two Pointers`,`Binary Search`,`Divide and Conquer` | Medium | +| [10.10](https://leetcode-cn.com/problems/rank-from-stream-lcci) | [Rank from Stream](/lcci/10.10.Rank%20from%20Stream/README_EN.md) | | Medium | +| [10.11](https://leetcode-cn.com/problems/peaks-and-valleys-lcci) | [Peaks and Valleys](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) | | Medium | +| [16.01](https://leetcode-cn.com/problems/swap-numbers-lcci) | [Swap Numbers](/lcci/16.01.Swap%20Numbers/README_EN.md) | `Bit Manipulation`,`Math` | Medium | +| [16.02](https://leetcode-cn.com/problems/words-frequency-lcci) | [Words Frequency](/lcci/16.02.Words%20Frequency/README_EN.md) | `Design`,`Hash Table` | Medium | +| [16.03](https://leetcode-cn.com/problems/intersection-lcci) | [Intersection](/lcci/16.03.Intersection/README_EN.md) | `Geometry`,`Math` | Hard | +| [16.04](https://leetcode-cn.com/problems/tic-tac-toe-lcci) | [Tic-Tac-Toe](/lcci/16.04.Tic-Tac-Toe/README_EN.md) | `Array` | Medium | +| [16.05](https://leetcode-cn.com/problems/factorial-zeros-lcci) | [Factorial Zeros](/lcci/16.05.Factorial%20Zeros/README_EN.md) | `Math` | Easy | +| [16.06](https://leetcode-cn.com/problems/smallest-difference-lcci) | [Smallest Difference](/lcci/16.06.Smallest%20Difference/README_EN.md) | `Array`,`Two Pointers` | Medium | +| [16.07](https://leetcode-cn.com/problems/maximum-lcci) | [Maximum](/lcci/16.07.Maximum/README_EN.md) | `Bit Manipulation`,`Math` | Easy | +| [16.08](https://leetcode-cn.com/problems/english-int-lcci) | [English Int](/lcci/16.08.English%20Int/README_EN.md) | `Math`,`String` | Hard | +| [16.09](https://leetcode-cn.com/problems/operations-lcci) | [Operations](/lcci/16.09.Operations/README_EN.md) | `Design` | Medium | +| [16.10](https://leetcode-cn.com/problems/living-people-lcci) | [Living People](/lcci/16.10.Living%20People/README_EN.md) | `Array` | Medium | +| [16.11](https://leetcode-cn.com/problems/diving-board-lcci) | [Diving Board](/lcci/16.11.Diving%20Board/README_EN.md) | `Recursion`,`Memoization` | Easy | +| [16.13](https://leetcode-cn.com/problems/bisect-squares-lcci) | [Bisect Squares](/lcci/16.13.Bisect%20Squares/README_EN.md) | `Geometry` | Medium | +| [16.14](https://leetcode-cn.com/problems/best-line-lcci) | [Best Line](/lcci/16.14.Best%20Line/README_EN.md) | `Geometry`,`Hash Table` | Medium | +| [16.15](https://leetcode-cn.com/problems/master-mind-lcci) | [Master Mind](/lcci/16.15.Master%20Mind/README_EN.md) | `Array` | Easy | +| [16.16](https://leetcode-cn.com/problems/sub-sort-lcci) | [Sub Sort](/lcci/16.16.Sub%20Sort/README_EN.md) | `Sort`,`Array` | Medium | +| [16.17](https://leetcode-cn.com/problems/contiguous-sequence-lcci) | [Contiguous Sequence](/lcci/16.17.Contiguous%20Sequence/README_EN.md) | `Array`,`Divide and Conquer`,`Dynamic Programming` | Easy | +| [16.18](https://leetcode-cn.com/problems/pattern-matching-lcci) | [Pattern Matching](/lcci/16.18.Pattern%20Matching/README_EN.md) | `String` | Medium | +| [16.19](https://leetcode-cn.com/problems/pond-sizes-lcci) | [Pond Sizes](/lcci/16.19.Pond%20Sizes/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | +| [16.20](https://leetcode-cn.com/problems/t9-lcci) | [T9](/lcci/16.20.T9/README_EN.md) | `Array` | Medium | +| [16.21](https://leetcode-cn.com/problems/sum-swap-lcci) | [Sum Swap](/lcci/16.21.Sum%20Swap/README_EN.md) | `Sort`,`Array` | Medium | +| [16.22](https://leetcode-cn.com/problems/langtons-ant-lcci) | [Langtons Ant](/lcci/16.22.Langtons%20Ant/README_EN.md) | `Array` | Medium | +| [16.24](https://leetcode-cn.com/problems/pairs-with-sum-lcci) | [Pairs With Sum](/lcci/16.24.Pairs%20With%20Sum/README_EN.md) | `Array`,`Hash Table` | Medium | +| [16.25](https://leetcode-cn.com/problems/lru-cache-lcci) | [LRU Cache](/lcci/16.25.LRU%20Cache/README_EN.md) | `Design` | Medium | +| [16.26](https://leetcode-cn.com/problems/calculator-lcci) | [Calculator](/lcci/16.26.Calculator/README_EN.md) | `String` | Medium | +| [17.01](https://leetcode-cn.com/problems/add-without-plus-lcci) | [Add Without Plus](/lcci/17.01.Add%20Without%20Plus/README_EN.md) | `Bit Manipulation` | Easy | +| [17.04](https://leetcode-cn.com/problems/missing-number-lcci) | [Missing Number](/lcci/17.04.Missing%20Number/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Easy | +| [17.05](https://leetcode-cn.com/problems/find-longest-subarray-lcci) | [Find Longest Subarray](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) | `Array` | Medium | +| [17.06](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) | [Number Of 2s In Range](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) | `Math`,`Dynamic Programming` | Medium | +| [17.07](https://leetcode-cn.com/problems/baby-names-lcci) | [Baby Names](/lcci/17.07.Baby%20Names/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | +| [17.08](https://leetcode-cn.com/problems/circus-tower-lcci) | [Circus Tower](/lcci/17.08.Circus%20Tower/README_EN.md) | `Sort`,`Binary Search`,`Dynamic Programming` | Medium | +| [17.09](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) | [Get Kth Magic Number](/lcci/17.09.Get%20Kth%20Magic%20Number/README_EN.md) | `Heap`,`Queue`,`Math` | Medium | +| [17.10](https://leetcode-cn.com/problems/find-majority-element-lcci) | [Find Majority Element](/lcci/17.10.Find%20Majority%20Element/README_EN.md) | `Bit Manipulation`,`Array`,`Divide and Conquer` | Easy | +| [17.11](https://leetcode-cn.com/problems/find-closest-lcci) | [Find Closest](/lcci/17.11.Find%20Closest/README_EN.md) | `Two Pointers`,`String` | Medium | +| [17.12](https://leetcode-cn.com/problems/binode-lcci) | [BiNode](/lcci/17.12.BiNode/README_EN.md) | `Tree`,`Binary Search Tree`,`Recursion` | Easy | +| [17.13](https://leetcode-cn.com/problems/re-space-lcci) | [Re-Space](/lcci/17.13.Re-Space/README_EN.md) | `Memoization`,`String` | Medium | +| [17.14](https://leetcode-cn.com/problems/smallest-k-lcci) | [Smallest K](/lcci/17.14.Smallest%20K/README_EN.md) | `Heap`,`Sort`,`Divide and Conquer` | Medium | +| [17.15](https://leetcode-cn.com/problems/longest-word-lcci) | [Longest Word](/lcci/17.15.Longest%20Word/README_EN.md) | `String` | Medium | +| [17.16](https://leetcode-cn.com/problems/the-masseuse-lcci) | [The Masseuse](/lcci/17.16.The%20Masseuse/README_EN.md) | `Dynamic Programming` | Easy | +| [17.17](https://leetcode-cn.com/problems/multi-search-lcci) | [Multi Search](/lcci/17.17.Multi%20Search/README_EN.md) | `Trie`,`String` | Medium | +| [17.18](https://leetcode-cn.com/problems/shortest-supersequence-lcci) | [Shortest Supersequence](/lcci/17.18.Shortest%20Supersequence/README_EN.md) | `Sliding Window` | Medium | +| [17.19](https://leetcode-cn.com/problems/missing-two-lcci) | [Missing Two](/lcci/17.19.Missing%20Two/README_EN.md) | `Array`,`Math` | Hard | +| [17.20](https://leetcode-cn.com/problems/continuous-median-lcci) | [Continuous Median](/lcci/17.20.Continuous%20Median/README_EN.md) | `Heap` | Hard | +| [17.21](https://leetcode-cn.com/problems/volume-of-histogram-lcci) | [Volume of Histogram](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) | `Stack`,`Array`,`Two Pointers` | Hard | +| [17.22](https://leetcode-cn.com/problems/word-transformer-lcci) | [Word Transformer](/lcci/17.22.Word%20Transformer/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Array`,`String` | Medium | +| [17.23](https://leetcode-cn.com/problems/max-black-square-lcci) | [Max Black Square](/lcci/17.23.Max%20Black%20Square/README_EN.md) | `Dynamic Programming` | Medium | +| [17.24](https://leetcode-cn.com/problems/max-submatrix-lcci) | [Max Submatrix](/lcci/17.24.Max%20Submatrix/README_EN.md) | `Dynamic Programming` | Hard | +| [17.25](https://leetcode-cn.com/problems/word-rectangle-lcci) | [Word Rectangle](/lcci/17.25.Word%20Rectangle/README_EN.md) | | Hard | +| [17.26](https://leetcode-cn.com/problems/sparse-similarity-lcci) | [Sparse Similarity](/lcci/17.26.Sparse%20Similarity/README_EN.md) | `Hash Table` | Hard | ## Copyright -[@Doocs](https://github.com/doocs) \ No newline at end of file + +[@Doocs](https://github.com/doocs) diff --git a/lcci/summary.md b/lcci/summary.md index 2678dcb02f242..7faec2b946ff2 100644 --- a/lcci/summary.md +++ b/lcci/summary.md @@ -1,110 +1,110 @@ - LeetCode 《程序员面试金典(第 6 版)》题解 - - [01.01. 判定字符是否唯一](/lcci/01.01.Is%20Unique/README.md) - - [01.02. 判定是否互为字符重排](/lcci/01.02.Check%20Permutation/README.md) - - [01.03. URL化](/lcci/01.03.String%20to%20URL/README.md) - - [01.04. 回文排列](/lcci/01.04.Palindrome%20Permutation/README.md) - - [01.05. 一次编辑](/lcci/01.05.One%20Away/README.md) - - [01.06. 字符串压缩](/lcci/01.06.Compress%20String/README.md) - - [01.07. 旋转矩阵](/lcci/01.07.Rotate%20Matrix/README.md) - - [01.08. 零矩阵](/lcci/01.08.Zero%20Matrix/README.md) - - [01.09. 字符串轮转](/lcci/01.09.String%20Rotation/README.md) - - [02.01. 移除重复节点](/lcci/02.01.Remove%20Duplicate%20Node/README.md) - - [02.02. 返回倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) - - [02.03. 删除中间节点](/lcci/02.03.Delete%20Middle%20Node/README.md) - - [02.04. 分割链表](/lcci/02.04.Partition%20List/README.md) - - [02.05. 链表求和](/lcci/02.05.Sum%20Lists/README.md) - - [02.06. 回文链表](/lcci/02.06.Palindrome%20Linked%20List/README.md) - - [02.07. 链表相交](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README.md) - - [02.08. 环路检测](/lcci/02.08.Linked%20List%20Cycle/README.md) - - [03.01. 三合一](/lcci/03.01.Three%20in%20One/README.md) - - [03.02. 栈的最小值](/lcci/03.02.Min%20Stack/README.md) - - [03.03. 堆盘子](/lcci/03.03.Stack%20of%20Plates/README.md) - - [03.04. 化栈为队](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) - - [03.05. 栈排序](/lcci/03.05.Sort%20of%20Stacks/README.md) - - [03.06. 动物收容所](/lcci/03.06.Animal%20Shelter/README.md) - - [04.01. 节点间通路](/lcci/04.01.Route%20Between%20Nodes/README.md) - - [04.02. 最小高度树](/lcci/04.02.Minimum%20Height%20Tree/README.md) - - [04.03. 特定深度节点链表](/lcci/04.03.List%20of%20Depth/README.md) - - [04.04. 检查平衡性](/lcci/04.04.Check%20Balance/README.md) - - [04.05. 合法二叉搜索树](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) - - [04.06. 后继者](/lcci/04.06.Successor/README.md) - - [04.08. 首个共同祖先](/lcci/04.08.First%20Common%20Ancestor/README.md) - - [04.09. 二叉搜索树序列](/lcci/04.09.BST%20Sequences/README.md) - - [04.10. 检查子树](/lcci/04.10.Check%20SubTree/README.md) - - [04.12. 求和路径](/lcci/04.12.Paths%20with%20Sum/README.md) - - [05.01. 插入](/lcci/05.01.Insert%20Into%20Bits/README.md) - - [05.02. 二进制数转字符串](/lcci/05.02.Bianry%20Number%20to%20String/README.md) - - [05.03. 翻转数位](/lcci/05.03.Reverse%20Bits/README.md) - - [05.04. 下一个数](/lcci/05.04.Closed%20Number/README.md) - - [05.06. 整数转换](/lcci/05.06.Convert%20Integer/README.md) - - [05.07. 配对交换](/lcci/05.07.Exchange/README.md) - - [05.08. 绘制直线](/lcci/05.08.Draw%20Line/README.md) - - [08.01. 三步问题](/lcci/08.01.Three%20Steps%20Problem/README.md) - - [08.02. 迷路的机器人](/lcci/08.02.Robot%20in%20a%20Grid/README.md) - - [08.03. 魔术索引](/lcci/08.03.Magic%20Index/README.md) - - [08.04. 幂集](/lcci/08.04.Power%20Set/README.md) - - [08.05. 递归乘法](/lcci/08.05.Recursive%20Mulitply/README.md) - - [08.06. 汉诺塔问题](/lcci/08.06.Hanota/README.md) - - [08.07. 无重复字符串的排列组合](/lcci/08.07.Permutation%20I/README.md) - - [08.08. 有重复字符串的排列组合](/lcci/08.08.Permutation%20II/README.md) - - [08.09. 括号](/lcci/08.09.Bracket/README.md) - - [08.10. 颜色填充](/lcci/08.10.Color%20Fill/README.md) - - [08.11. 硬币](/lcci/08.11.Coin/README.md) - - [08.12. 八皇后](/lcci/08.12.Eight%20Queens/README.md) - - [08.13. 堆箱子](/lcci/08.13.Pile%20Box/README.md) - - [08.14. 布尔运算](/lcci/08.14.Boolean%20Evaluation/README.md) - - [10.01. 合并排序的数组](/lcci/10.01.Sorted%20Merge/README.md) - - [10.02. 变位词组](/lcci/10.02.Group%20Anagrams/README.md) - - [10.03. 搜索旋转数组](/lcci/10.03.Search%20Rotate%20Array/README.md) - - [10.05. 稀疏数组搜索](/lcci/10.05.Sparse%20Array%20Search/README.md) - - [10.09. 排序矩阵查找](/lcci/10.09.Sorted%20Matrix%20Search/README.md) - - [10.10. 数字流的秩](/lcci/10.10.Rank%20from%20Stream/README.md) - - [10.11. 峰与谷](/lcci/10.11.Peaks%20and%20Valleys/README.md) - - [16.01. 交换数字](/lcci/16.01.Swap%20Numbers/README.md) - - [16.02. 单词频率](/lcci/16.02.Words%20Frequency/README.md) - - [16.03. 交点](/lcci/16.03.Intersection/README.md) - - [16.04. 井字游戏](/lcci/16.04.Tic-Tac-Toe/README.md) - - [16.05. 阶乘尾数](/lcci/16.05.Factorial%20Zeros/README.md) - - [16.06. 最小差](/lcci/16.06.Smallest%20Difference/README.md) - - [16.07. 最大数值](/lcci/16.07.Maximum/README.md) - - [16.08. 整数的英语表示](/lcci/16.08.English%20Int/README.md) - - [16.09. 运算](/lcci/16.09.Operations/README.md) - - [16.10. 生存人数](/lcci/16.10.Living%20People/README.md) - - [16.11. 跳水板](/lcci/16.11.Diving%20Board/README.md) - - [16.13. 平分正方形](/lcci/16.13.Bisect%20Squares/README.md) - - [16.14. 最佳直线](/lcci/16.14.Best%20Line/README.md) - - [16.15. 珠玑妙算](/lcci/16.15.Master%20Mind/README.md) - - [16.16. 部分排序](/lcci/16.16.Sub%20Sort/README.md) - - [16.17. 连续数列](/lcci/16.17.Contiguous%20Sequence/README.md) - - [16.18. 模式匹配](/lcci/16.18.Pattern%20Matching/README.md) - - [16.19. 水域大小](/lcci/16.19.Pond%20Sizes/README.md) - - [16.20. T9键盘](/lcci/16.20.T9/README.md) - - [16.21. 交换和](/lcci/16.21.Sum%20Swap/README.md) - - [16.22. 兰顿蚂蚁](/lcci/16.22.Langtons%20Ant/README.md) - - [16.24. 数对和](/lcci/16.24.Pairs%20With%20Sum/README.md) - - [16.25. LRU缓存](/lcci/16.25.LRU%20Cache/README.md) - - [16.26. 计算器](/lcci/16.26.Calculator/README.md) - - [17.01. 不用加号的加法](/lcci/17.01.Add%20Without%20Plus/README.md) - - [17.04. 消失的数字](/lcci/17.04.Missing%20Number/README.md) - - [17.05. 字母与数字](/lcci/17.05.Find%20Longest%20Subarray/README.md) - - [17.06. 2出现的次数](/lcci/17.06.Number%20Of%202s%20In%20Range/README.md) - - [17.07. 婴儿名字](/lcci/17.07.Baby%20Names/README.md) - - [17.08. 马戏团人塔](/lcci/17.08.Circus%20Tower/README.md) - - [17.09. 第 k 个数](/lcci/17.09.Get%20Kth%20Magic%20Number/README.md) - - [17.10. 主要元素](/lcci/17.10.Find%20Majority%20Element/README.md) - - [17.11. 单词距离](/lcci/17.11.Find%20Closest/README.md) - - [17.12. BiNode](/lcci/17.12.BiNode/README.md) - - [17.13. 恢复空格](/lcci/17.13.Re-Space/README.md) - - [17.14. 最小K个数](/lcci/17.14.Smallest%20K/README.md) - - [17.15. 最长单词](/lcci/17.15.Longest%20Word/README.md) - - [17.16. 按摩师](/lcci/17.16.The%20Masseuse/README.md) - - [17.17. 多次搜索](/lcci/17.17.Multi%20Search/README.md) - - [17.18. 最短超串](/lcci/17.18.Shortest%20Supersequence/README.md) - - [17.19. 消失的两个数字](/lcci/17.19.Missing%20Two/README.md) - - [17.20. 连续中值](/lcci/17.20.Continuous%20Median/README.md) - - [17.21. 直方图的水量](/lcci/17.21.Volume%20of%20Histogram/README.md) - - [17.22. 单词转换](/lcci/17.22.Word%20Transformer/README.md) - - [17.23. 最大黑方阵](/lcci/17.23.Max%20Black%20Square/README.md) - - [17.24. 最大子矩阵](/lcci/17.24.Max%20Submatrix/README.md) - - [17.25. 单词矩阵](/lcci/17.25.Word%20Rectangle/README.md) - - [17.26. 稀疏相似度](/lcci/17.26.Sparse%20Similarity/README.md) \ No newline at end of file + - [01.01. 判定字符是否唯一](/lcci/01.01.Is%20Unique/README.md) + - [01.02. 判定是否互为字符重排](/lcci/01.02.Check%20Permutation/README.md) + - [01.03. URL 化](/lcci/01.03.String%20to%20URL/README.md) + - [01.04. 回文排列](/lcci/01.04.Palindrome%20Permutation/README.md) + - [01.05. 一次编辑](/lcci/01.05.One%20Away/README.md) + - [01.06. 字符串压缩](/lcci/01.06.Compress%20String/README.md) + - [01.07. 旋转矩阵](/lcci/01.07.Rotate%20Matrix/README.md) + - [01.08. 零矩阵](/lcci/01.08.Zero%20Matrix/README.md) + - [01.09. 字符串轮转](/lcci/01.09.String%20Rotation/README.md) + - [02.01. 移除重复节点](/lcci/02.01.Remove%20Duplicate%20Node/README.md) + - [02.02. 返回倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) + - [02.03. 删除中间节点](/lcci/02.03.Delete%20Middle%20Node/README.md) + - [02.04. 分割链表](/lcci/02.04.Partition%20List/README.md) + - [02.05. 链表求和](/lcci/02.05.Sum%20Lists/README.md) + - [02.06. 回文链表](/lcci/02.06.Palindrome%20Linked%20List/README.md) + - [02.07. 链表相交](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README.md) + - [02.08. 环路检测](/lcci/02.08.Linked%20List%20Cycle/README.md) + - [03.01. 三合一](/lcci/03.01.Three%20in%20One/README.md) + - [03.02. 栈的最小值](/lcci/03.02.Min%20Stack/README.md) + - [03.03. 堆盘子](/lcci/03.03.Stack%20of%20Plates/README.md) + - [03.04. 化栈为队](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) + - [03.05. 栈排序](/lcci/03.05.Sort%20of%20Stacks/README.md) + - [03.06. 动物收容所](/lcci/03.06.Animal%20Shelter/README.md) + - [04.01. 节点间通路](/lcci/04.01.Route%20Between%20Nodes/README.md) + - [04.02. 最小高度树](/lcci/04.02.Minimum%20Height%20Tree/README.md) + - [04.03. 特定深度节点链表](/lcci/04.03.List%20of%20Depth/README.md) + - [04.04. 检查平衡性](/lcci/04.04.Check%20Balance/README.md) + - [04.05. 合法二叉搜索树](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) + - [04.06. 后继者](/lcci/04.06.Successor/README.md) + - [04.08. 首个共同祖先](/lcci/04.08.First%20Common%20Ancestor/README.md) + - [04.09. 二叉搜索树序列](/lcci/04.09.BST%20Sequences/README.md) + - [04.10. 检查子树](/lcci/04.10.Check%20SubTree/README.md) + - [04.12. 求和路径](/lcci/04.12.Paths%20with%20Sum/README.md) + - [05.01. 插入](/lcci/05.01.Insert%20Into%20Bits/README.md) + - [05.02. 二进制数转字符串](/lcci/05.02.Bianry%20Number%20to%20String/README.md) + - [05.03. 翻转数位](/lcci/05.03.Reverse%20Bits/README.md) + - [05.04. 下一个数](/lcci/05.04.Closed%20Number/README.md) + - [05.06. 整数转换](/lcci/05.06.Convert%20Integer/README.md) + - [05.07. 配对交换](/lcci/05.07.Exchange/README.md) + - [05.08. 绘制直线](/lcci/05.08.Draw%20Line/README.md) + - [08.01. 三步问题](/lcci/08.01.Three%20Steps%20Problem/README.md) + - [08.02. 迷路的机器人](/lcci/08.02.Robot%20in%20a%20Grid/README.md) + - [08.03. 魔术索引](/lcci/08.03.Magic%20Index/README.md) + - [08.04. 幂集](/lcci/08.04.Power%20Set/README.md) + - [08.05. 递归乘法](/lcci/08.05.Recursive%20Mulitply/README.md) + - [08.06. 汉诺塔问题](/lcci/08.06.Hanota/README.md) + - [08.07. 无重复字符串的排列组合](/lcci/08.07.Permutation%20I/README.md) + - [08.08. 有重复字符串的排列组合](/lcci/08.08.Permutation%20II/README.md) + - [08.09. 括号](/lcci/08.09.Bracket/README.md) + - [08.10. 颜色填充](/lcci/08.10.Color%20Fill/README.md) + - [08.11. 硬币](/lcci/08.11.Coin/README.md) + - [08.12. 八皇后](/lcci/08.12.Eight%20Queens/README.md) + - [08.13. 堆箱子](/lcci/08.13.Pile%20Box/README.md) + - [08.14. 布尔运算](/lcci/08.14.Boolean%20Evaluation/README.md) + - [10.01. 合并排序的数组](/lcci/10.01.Sorted%20Merge/README.md) + - [10.02. 变位词组](/lcci/10.02.Group%20Anagrams/README.md) + - [10.03. 搜索旋转数组](/lcci/10.03.Search%20Rotate%20Array/README.md) + - [10.05. 稀疏数组搜索](/lcci/10.05.Sparse%20Array%20Search/README.md) + - [10.09. 排序矩阵查找](/lcci/10.09.Sorted%20Matrix%20Search/README.md) + - [10.10. 数字流的秩](/lcci/10.10.Rank%20from%20Stream/README.md) + - [10.11. 峰与谷](/lcci/10.11.Peaks%20and%20Valleys/README.md) + - [16.01. 交换数字](/lcci/16.01.Swap%20Numbers/README.md) + - [16.02. 单词频率](/lcci/16.02.Words%20Frequency/README.md) + - [16.03. 交点](/lcci/16.03.Intersection/README.md) + - [16.04. 井字游戏](/lcci/16.04.Tic-Tac-Toe/README.md) + - [16.05. 阶乘尾数](/lcci/16.05.Factorial%20Zeros/README.md) + - [16.06. 最小差](/lcci/16.06.Smallest%20Difference/README.md) + - [16.07. 最大数值](/lcci/16.07.Maximum/README.md) + - [16.08. 整数的英语表示](/lcci/16.08.English%20Int/README.md) + - [16.09. 运算](/lcci/16.09.Operations/README.md) + - [16.10. 生存人数](/lcci/16.10.Living%20People/README.md) + - [16.11. 跳水板](/lcci/16.11.Diving%20Board/README.md) + - [16.13. 平分正方形](/lcci/16.13.Bisect%20Squares/README.md) + - [16.14. 最佳直线](/lcci/16.14.Best%20Line/README.md) + - [16.15. 珠玑妙算](/lcci/16.15.Master%20Mind/README.md) + - [16.16. 部分排序](/lcci/16.16.Sub%20Sort/README.md) + - [16.17. 连续数列](/lcci/16.17.Contiguous%20Sequence/README.md) + - [16.18. 模式匹配](/lcci/16.18.Pattern%20Matching/README.md) + - [16.19. 水域大小](/lcci/16.19.Pond%20Sizes/README.md) + - [16.20. T9 键盘](/lcci/16.20.T9/README.md) + - [16.21. 交换和](/lcci/16.21.Sum%20Swap/README.md) + - [16.22. 兰顿蚂蚁](/lcci/16.22.Langtons%20Ant/README.md) + - [16.24. 数对和](/lcci/16.24.Pairs%20With%20Sum/README.md) + - [16.25. LRU 缓存](/lcci/16.25.LRU%20Cache/README.md) + - [16.26. 计算器](/lcci/16.26.Calculator/README.md) + - [17.01. 不用加号的加法](/lcci/17.01.Add%20Without%20Plus/README.md) + - [17.04. 消失的数字](/lcci/17.04.Missing%20Number/README.md) + - [17.05. 字母与数字](/lcci/17.05.Find%20Longest%20Subarray/README.md) + - [17.06. 2 出现的次数](/lcci/17.06.Number%20Of%202s%20In%20Range/README.md) + - [17.07. 婴儿名字](/lcci/17.07.Baby%20Names/README.md) + - [17.08. 马戏团人塔](/lcci/17.08.Circus%20Tower/README.md) + - [17.09. 第 k 个数](/lcci/17.09.Get%20Kth%20Magic%20Number/README.md) + - [17.10. 主要元素](/lcci/17.10.Find%20Majority%20Element/README.md) + - [17.11. 单词距离](/lcci/17.11.Find%20Closest/README.md) + - [17.12. BiNode](/lcci/17.12.BiNode/README.md) + - [17.13. 恢复空格](/lcci/17.13.Re-Space/README.md) + - [17.14. 最小 K 个数](/lcci/17.14.Smallest%20K/README.md) + - [17.15. 最长单词](/lcci/17.15.Longest%20Word/README.md) + - [17.16. 按摩师](/lcci/17.16.The%20Masseuse/README.md) + - [17.17. 多次搜索](/lcci/17.17.Multi%20Search/README.md) + - [17.18. 最短超串](/lcci/17.18.Shortest%20Supersequence/README.md) + - [17.19. 消失的两个数字](/lcci/17.19.Missing%20Two/README.md) + - [17.20. 连续中值](/lcci/17.20.Continuous%20Median/README.md) + - [17.21. 直方图的水量](/lcci/17.21.Volume%20of%20Histogram/README.md) + - [17.22. 单词转换](/lcci/17.22.Word%20Transformer/README.md) + - [17.23. 最大黑方阵](/lcci/17.23.Max%20Black%20Square/README.md) + - [17.24. 最大子矩阵](/lcci/17.24.Max%20Submatrix/README.md) + - [17.25. 单词矩阵](/lcci/17.25.Word%20Rectangle/README.md) + - [17.26. 稀疏相似度](/lcci/17.26.Sparse%20Similarity/README.md) diff --git a/lcci/summary_en.md b/lcci/summary_en.md index 940f5ac4b80b6..3d362b80aa8d5 100644 --- a/lcci/summary_en.md +++ b/lcci/summary_en.md @@ -1,110 +1,110 @@ - [LCCI Solutions] - - [01.01. Is Unique](/lcci/01.01.Is%20Unique/README_EN.md) - - [01.02. Check Permutation](/lcci/01.02.Check%20Permutation/README_EN.md) - - [01.03. String to URL](/lcci/01.03.String%20to%20URL/README_EN.md) - - [01.04. Palindrome Permutation](/lcci/01.04.Palindrome%20Permutation/README_EN.md) - - [01.05. One Away](/lcci/01.05.One%20Away/README_EN.md) - - [01.06. Compress String](/lcci/01.06.Compress%20String/README_EN.md) - - [01.07. Rotate Matrix](/lcci/01.07.Rotate%20Matrix/README_EN.md) - - [01.08. Zero Matrix](/lcci/01.08.Zero%20Matrix/README_EN.md) - - [01.09. String Rotation](/lcci/01.09.String%20Rotation/README_EN.md) - - [02.01. Remove Duplicate Node](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) - - [02.02. Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) - - [02.03. Delete Middle Node](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) - - [02.04. Partition List](/lcci/02.04.Partition%20List/README_EN.md) - - [02.05. Sum Lists](/lcci/02.05.Sum%20Lists/README_EN.md) - - [02.06. Palindrome Linked List](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) - - [02.07. Intersection of Two Linked Lists](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) - - [02.08. Linked List Cycle](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) - - [03.01. Three in One](/lcci/03.01.Three%20in%20One/README_EN.md) - - [03.02. Min Stack](/lcci/03.02.Min%20Stack/README_EN.md) - - [03.03. Stack of Plates](/lcci/03.03.Stack%20of%20Plates/README_EN.md) - - [03.04. Implement Queue using Stacks](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) - - [03.05. Sort of Stacks](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) - - [03.06. Animal Shelter](/lcci/03.06.Animal%20Shelter/README_EN.md) - - [04.01. Route Between Nodes](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) - - [04.02. Minimum Height Tree](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) - - [04.03. List of Depth](/lcci/04.03.List%20of%20Depth/README_EN.md) - - [04.04. Check Balance](/lcci/04.04.Check%20Balance/README_EN.md) - - [04.05. Legal Binary Search Tree](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) - - [04.06. Successor](/lcci/04.06.Successor/README_EN.md) - - [04.08. First Common Ancestor](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) - - [04.09. BST Sequences](/lcci/04.09.BST%20Sequences/README_EN.md) - - [04.10. Check SubTree](/lcci/04.10.Check%20SubTree/README_EN.md) - - [04.12. Paths with Sum](/lcci/04.12.Paths%20with%20Sum/README_EN.md) - - [05.01. Insert Into Bits](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) - - [05.02. Bianry Number to String](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) - - [05.03. Reverse Bits](/lcci/05.03.Reverse%20Bits/README_EN.md) - - [05.04. Closed Number](/lcci/05.04.Closed%20Number/README_EN.md) - - [05.06. Convert Integer](/lcci/05.06.Convert%20Integer/README_EN.md) - - [05.07. Exchange](/lcci/05.07.Exchange/README_EN.md) - - [05.08. Draw Line](/lcci/05.08.Draw%20Line/README_EN.md) - - [08.01. Three Steps Problem](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) - - [08.02. Robot in a Grid](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) - - [08.03. Magic Index](/lcci/08.03.Magic%20Index/README_EN.md) - - [08.04. Power Set](/lcci/08.04.Power%20Set/README_EN.md) - - [08.05. Recursive Mulitply](/lcci/08.05.Recursive%20Mulitply/README_EN.md) - - [08.06. Hanota](/lcci/08.06.Hanota/README_EN.md) - - [08.07. Permutation I](/lcci/08.07.Permutation%20I/README_EN.md) - - [08.08. Permutation II](/lcci/08.08.Permutation%20II/README_EN.md) - - [08.09. Bracket](/lcci/08.09.Bracket/README_EN.md) - - [08.10. Color Fill](/lcci/08.10.Color%20Fill/README_EN.md) - - [08.11. Coin](/lcci/08.11.Coin/README_EN.md) - - [08.12. Eight Queens](/lcci/08.12.Eight%20Queens/README_EN.md) - - [08.13. Pile Box](/lcci/08.13.Pile%20Box/README_EN.md) - - [08.14. Boolean Evaluation](/lcci/08.14.Boolean%20Evaluation/README_EN.md) - - [10.01. Sorted Merge](/lcci/10.01.Sorted%20Merge/README_EN.md) - - [10.02. Group Anagrams](/lcci/10.02.Group%20Anagrams/README_EN.md) - - [10.03. Search Rotate Array](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) - - [10.05. Sparse Array Search](/lcci/10.05.Sparse%20Array%20Search/README_EN.md) - - [10.09. Sorted Matrix Search](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) - - [10.10. Rank from Stream](/lcci/10.10.Rank%20from%20Stream/README_EN.md) - - [10.11. Peaks and Valleys](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) - - [16.01. Swap Numbers](/lcci/16.01.Swap%20Numbers/README_EN.md) - - [16.02. Words Frequency](/lcci/16.02.Words%20Frequency/README_EN.md) - - [16.03. Intersection](/lcci/16.03.Intersection/README_EN.md) - - [16.04. Tic-Tac-Toe](/lcci/16.04.Tic-Tac-Toe/README_EN.md) - - [16.05. Factorial Zeros](/lcci/16.05.Factorial%20Zeros/README_EN.md) - - [16.06. Smallest Difference](/lcci/16.06.Smallest%20Difference/README_EN.md) - - [16.07. Maximum](/lcci/16.07.Maximum/README_EN.md) - - [16.08. English Int](/lcci/16.08.English%20Int/README_EN.md) - - [16.09. Operations](/lcci/16.09.Operations/README_EN.md) - - [16.10. Living People](/lcci/16.10.Living%20People/README_EN.md) - - [16.11. Diving Board](/lcci/16.11.Diving%20Board/README_EN.md) - - [16.13. Bisect Squares](/lcci/16.13.Bisect%20Squares/README_EN.md) - - [16.14. Best Line](/lcci/16.14.Best%20Line/README_EN.md) - - [16.15. Master Mind](/lcci/16.15.Master%20Mind/README_EN.md) - - [16.16. Sub Sort](/lcci/16.16.Sub%20Sort/README_EN.md) - - [16.17. Contiguous Sequence](/lcci/16.17.Contiguous%20Sequence/README_EN.md) - - [16.18. Pattern Matching](/lcci/16.18.Pattern%20Matching/README_EN.md) - - [16.19. Pond Sizes](/lcci/16.19.Pond%20Sizes/README_EN.md) - - [16.20. T9](/lcci/16.20.T9/README_EN.md) - - [16.21. Sum Swap](/lcci/16.21.Sum%20Swap/README_EN.md) - - [16.22. Langtons Ant](/lcci/16.22.Langtons%20Ant/README_EN.md) - - [16.24. Pairs With Sum](/lcci/16.24.Pairs%20With%20Sum/README_EN.md) - - [16.25. LRU Cache](/lcci/16.25.LRU%20Cache/README_EN.md) - - [16.26. Calculator](/lcci/16.26.Calculator/README_EN.md) - - [17.01. Add Without Plus](/lcci/17.01.Add%20Without%20Plus/README_EN.md) - - [17.04. Missing Number](/lcci/17.04.Missing%20Number/README_EN.md) - - [17.05. Find Longest Subarray](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) - - [17.06. Number Of 2s In Range](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) - - [17.07. Baby Names](/lcci/17.07.Baby%20Names/README_EN.md) - - [17.08. Circus Tower](/lcci/17.08.Circus%20Tower/README_EN.md) - - [17.09. Get Kth Magic Number](/lcci/17.09.Get%20Kth%20Magic%20Number/README_EN.md) - - [17.10. Find Majority Element](/lcci/17.10.Find%20Majority%20Element/README_EN.md) - - [17.11. Find Closest](/lcci/17.11.Find%20Closest/README_EN.md) - - [17.12. BiNode](/lcci/17.12.BiNode/README_EN.md) - - [17.13. Re-Space](/lcci/17.13.Re-Space/README_EN.md) - - [17.14. Smallest K](/lcci/17.14.Smallest%20K/README_EN.md) - - [17.15. Longest Word](/lcci/17.15.Longest%20Word/README_EN.md) - - [17.16. The Masseuse](/lcci/17.16.The%20Masseuse/README_EN.md) - - [17.17. Multi Search](/lcci/17.17.Multi%20Search/README_EN.md) - - [17.18. Shortest Supersequence](/lcci/17.18.Shortest%20Supersequence/README_EN.md) - - [17.19. Missing Two](/lcci/17.19.Missing%20Two/README_EN.md) - - [17.20. Continuous Median](/lcci/17.20.Continuous%20Median/README_EN.md) - - [17.21. Volume of Histogram](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) - - [17.22. Word Transformer](/lcci/17.22.Word%20Transformer/README_EN.md) - - [17.23. Max Black Square](/lcci/17.23.Max%20Black%20Square/README_EN.md) - - [17.24. Max Submatrix](/lcci/17.24.Max%20Submatrix/README_EN.md) - - [17.25. Word Rectangle](/lcci/17.25.Word%20Rectangle/README_EN.md) - - [17.26. Sparse Similarity](/lcci/17.26.Sparse%20Similarity/README_EN.md) \ No newline at end of file + - [01.01. Is Unique](/lcci/01.01.Is%20Unique/README_EN.md) + - [01.02. Check Permutation](/lcci/01.02.Check%20Permutation/README_EN.md) + - [01.03. String to URL](/lcci/01.03.String%20to%20URL/README_EN.md) + - [01.04. Palindrome Permutation](/lcci/01.04.Palindrome%20Permutation/README_EN.md) + - [01.05. One Away](/lcci/01.05.One%20Away/README_EN.md) + - [01.06. Compress String](/lcci/01.06.Compress%20String/README_EN.md) + - [01.07. Rotate Matrix](/lcci/01.07.Rotate%20Matrix/README_EN.md) + - [01.08. Zero Matrix](/lcci/01.08.Zero%20Matrix/README_EN.md) + - [01.09. String Rotation](/lcci/01.09.String%20Rotation/README_EN.md) + - [02.01. Remove Duplicate Node](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) + - [02.02. Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) + - [02.03. Delete Middle Node](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) + - [02.04. Partition List](/lcci/02.04.Partition%20List/README_EN.md) + - [02.05. Sum Lists](/lcci/02.05.Sum%20Lists/README_EN.md) + - [02.06. Palindrome Linked List](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) + - [02.07. Intersection of Two Linked Lists](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) + - [02.08. Linked List Cycle](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) + - [03.01. Three in One](/lcci/03.01.Three%20in%20One/README_EN.md) + - [03.02. Min Stack](/lcci/03.02.Min%20Stack/README_EN.md) + - [03.03. Stack of Plates](/lcci/03.03.Stack%20of%20Plates/README_EN.md) + - [03.04. Implement Queue using Stacks](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) + - [03.05. Sort of Stacks](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) + - [03.06. Animal Shelter](/lcci/03.06.Animal%20Shelter/README_EN.md) + - [04.01. Route Between Nodes](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) + - [04.02. Minimum Height Tree](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) + - [04.03. List of Depth](/lcci/04.03.List%20of%20Depth/README_EN.md) + - [04.04. Check Balance](/lcci/04.04.Check%20Balance/README_EN.md) + - [04.05. Legal Binary Search Tree](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) + - [04.06. Successor](/lcci/04.06.Successor/README_EN.md) + - [04.08. First Common Ancestor](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) + - [04.09. BST Sequences](/lcci/04.09.BST%20Sequences/README_EN.md) + - [04.10. Check SubTree](/lcci/04.10.Check%20SubTree/README_EN.md) + - [04.12. Paths with Sum](/lcci/04.12.Paths%20with%20Sum/README_EN.md) + - [05.01. Insert Into Bits](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) + - [05.02. Bianry Number to String](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) + - [05.03. Reverse Bits](/lcci/05.03.Reverse%20Bits/README_EN.md) + - [05.04. Closed Number](/lcci/05.04.Closed%20Number/README_EN.md) + - [05.06. Convert Integer](/lcci/05.06.Convert%20Integer/README_EN.md) + - [05.07. Exchange](/lcci/05.07.Exchange/README_EN.md) + - [05.08. Draw Line](/lcci/05.08.Draw%20Line/README_EN.md) + - [08.01. Three Steps Problem](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) + - [08.02. Robot in a Grid](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) + - [08.03. Magic Index](/lcci/08.03.Magic%20Index/README_EN.md) + - [08.04. Power Set](/lcci/08.04.Power%20Set/README_EN.md) + - [08.05. Recursive Mulitply](/lcci/08.05.Recursive%20Mulitply/README_EN.md) + - [08.06. Hanota](/lcci/08.06.Hanota/README_EN.md) + - [08.07. Permutation I](/lcci/08.07.Permutation%20I/README_EN.md) + - [08.08. Permutation II](/lcci/08.08.Permutation%20II/README_EN.md) + - [08.09. Bracket](/lcci/08.09.Bracket/README_EN.md) + - [08.10. Color Fill](/lcci/08.10.Color%20Fill/README_EN.md) + - [08.11. Coin](/lcci/08.11.Coin/README_EN.md) + - [08.12. Eight Queens](/lcci/08.12.Eight%20Queens/README_EN.md) + - [08.13. Pile Box](/lcci/08.13.Pile%20Box/README_EN.md) + - [08.14. Boolean Evaluation](/lcci/08.14.Boolean%20Evaluation/README_EN.md) + - [10.01. Sorted Merge](/lcci/10.01.Sorted%20Merge/README_EN.md) + - [10.02. Group Anagrams](/lcci/10.02.Group%20Anagrams/README_EN.md) + - [10.03. Search Rotate Array](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) + - [10.05. Sparse Array Search](/lcci/10.05.Sparse%20Array%20Search/README_EN.md) + - [10.09. Sorted Matrix Search](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) + - [10.10. Rank from Stream](/lcci/10.10.Rank%20from%20Stream/README_EN.md) + - [10.11. Peaks and Valleys](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) + - [16.01. Swap Numbers](/lcci/16.01.Swap%20Numbers/README_EN.md) + - [16.02. Words Frequency](/lcci/16.02.Words%20Frequency/README_EN.md) + - [16.03. Intersection](/lcci/16.03.Intersection/README_EN.md) + - [16.04. Tic-Tac-Toe](/lcci/16.04.Tic-Tac-Toe/README_EN.md) + - [16.05. Factorial Zeros](/lcci/16.05.Factorial%20Zeros/README_EN.md) + - [16.06. Smallest Difference](/lcci/16.06.Smallest%20Difference/README_EN.md) + - [16.07. Maximum](/lcci/16.07.Maximum/README_EN.md) + - [16.08. English Int](/lcci/16.08.English%20Int/README_EN.md) + - [16.09. Operations](/lcci/16.09.Operations/README_EN.md) + - [16.10. Living People](/lcci/16.10.Living%20People/README_EN.md) + - [16.11. Diving Board](/lcci/16.11.Diving%20Board/README_EN.md) + - [16.13. Bisect Squares](/lcci/16.13.Bisect%20Squares/README_EN.md) + - [16.14. Best Line](/lcci/16.14.Best%20Line/README_EN.md) + - [16.15. Master Mind](/lcci/16.15.Master%20Mind/README_EN.md) + - [16.16. Sub Sort](/lcci/16.16.Sub%20Sort/README_EN.md) + - [16.17. Contiguous Sequence](/lcci/16.17.Contiguous%20Sequence/README_EN.md) + - [16.18. Pattern Matching](/lcci/16.18.Pattern%20Matching/README_EN.md) + - [16.19. Pond Sizes](/lcci/16.19.Pond%20Sizes/README_EN.md) + - [16.20. T9](/lcci/16.20.T9/README_EN.md) + - [16.21. Sum Swap](/lcci/16.21.Sum%20Swap/README_EN.md) + - [16.22. Langtons Ant](/lcci/16.22.Langtons%20Ant/README_EN.md) + - [16.24. Pairs With Sum](/lcci/16.24.Pairs%20With%20Sum/README_EN.md) + - [16.25. LRU Cache](/lcci/16.25.LRU%20Cache/README_EN.md) + - [16.26. Calculator](/lcci/16.26.Calculator/README_EN.md) + - [17.01. Add Without Plus](/lcci/17.01.Add%20Without%20Plus/README_EN.md) + - [17.04. Missing Number](/lcci/17.04.Missing%20Number/README_EN.md) + - [17.05. Find Longest Subarray](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) + - [17.06. Number Of 2s In Range](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) + - [17.07. Baby Names](/lcci/17.07.Baby%20Names/README_EN.md) + - [17.08. Circus Tower](/lcci/17.08.Circus%20Tower/README_EN.md) + - [17.09. Get Kth Magic Number](/lcci/17.09.Get%20Kth%20Magic%20Number/README_EN.md) + - [17.10. Find Majority Element](/lcci/17.10.Find%20Majority%20Element/README_EN.md) + - [17.11. Find Closest](/lcci/17.11.Find%20Closest/README_EN.md) + - [17.12. BiNode](/lcci/17.12.BiNode/README_EN.md) + - [17.13. Re-Space](/lcci/17.13.Re-Space/README_EN.md) + - [17.14. Smallest K](/lcci/17.14.Smallest%20K/README_EN.md) + - [17.15. Longest Word](/lcci/17.15.Longest%20Word/README_EN.md) + - [17.16. The Masseuse](/lcci/17.16.The%20Masseuse/README_EN.md) + - [17.17. Multi Search](/lcci/17.17.Multi%20Search/README_EN.md) + - [17.18. Shortest Supersequence](/lcci/17.18.Shortest%20Supersequence/README_EN.md) + - [17.19. Missing Two](/lcci/17.19.Missing%20Two/README_EN.md) + - [17.20. Continuous Median](/lcci/17.20.Continuous%20Median/README_EN.md) + - [17.21. Volume of Histogram](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) + - [17.22. Word Transformer](/lcci/17.22.Word%20Transformer/README_EN.md) + - [17.23. Max Black Square](/lcci/17.23.Max%20Black%20Square/README_EN.md) + - [17.24. Max Submatrix](/lcci/17.24.Max%20Submatrix/README_EN.md) + - [17.25. Word Rectangle](/lcci/17.25.Word%20Rectangle/README_EN.md) + - [17.26. Sparse Similarity](/lcci/17.26.Sparse%20Similarity/README_EN.md) diff --git a/lcof/README.md b/lcof/README.md index 4e15787dee21c..461826a70c4e5 100644 --- a/lcof/README.md +++ b/lcof/README.md @@ -1,91 +1,93 @@ # [《剑指 Offer(第 2 版)》系列](https://leetcode-cn.com/problemset/lcof/) -本书精选谷歌、微软等知名IT企业的典型面试题,系统地总结了如何在面试时写出高质量代码,如何优化代码效率,以及分析、解决难题的常用方法。 + +本书精选谷歌、微软等知名 IT 企业的典型面试题,系统地总结了如何在面试时写出高质量代码,如何优化代码效率,以及分析、解决难题的常用方法。 [English Version](/lcof/README_EN.md) ## 题解 + 以下所有题目均来源 [LeetCode 中国官网](https://leetcode-cn.com/problemset/lcof/),题解由 [doocs/leetcode 贡献者](https://github.com/doocs/leetcode/graphs/contributors) 提供,正在完善中,欢迎贡献你的题解! 快速搜索题号、题解、标签等,请善用 Control+F(或者 Command+F)。 -| 题号 | 题解 | 标签 | 难度 | -| --- | --- | --- | --- | -| [03](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof) | [数组中重复的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9803.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E9%87%8D%E5%A4%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数组`,`哈希表` | 简单 | -| [04](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof) | [二维数组中的查找](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9804.%20%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9F%A5%E6%89%BE/README.md) | `数组`,`双指针` | 简单 | -| [05](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof) | [替换空格](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9805.%20%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/README.md) | | 简单 | -| [06](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof) | [从尾到头打印链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9806.%20%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/README.md) | | 简单 | -| [07](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof) | [重建二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9807.%20%E9%87%8D%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`递归` | 中等 | -| [09](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | [用两个栈实现队列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9809.%20%E7%94%A8%E4%B8%A4%E4%B8%AA%E6%A0%88%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97/README.md) | `栈`,`设计` | 简单 | -| [10- I](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | [斐波那契数列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20I.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/README.md) | `递归` | 简单 | -| [10- II](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof) | [青蛙跳台阶问题](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20II.%20%E9%9D%92%E8%9B%99%E8%B7%B3%E5%8F%B0%E9%98%B6%E9%97%AE%E9%A2%98/README.md) | `递归` | 简单 | -| [11](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof) | [旋转数组的最小数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9811.%20%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/README.md) | `二分查找` | 简单 | -| [12](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof) | [矩阵中的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9812.%20%E7%9F%A9%E9%98%B5%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) | `动态规划` | 中等 | -| [13](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof) | [机器人的运动范围](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9813.%20%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%9A%84%E8%BF%90%E5%8A%A8%E8%8C%83%E5%9B%B4/README.md) | | 中等 | -| [14- I](https://leetcode-cn.com/problems/jian-sheng-zi-lcof) | [剪绳子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20I.%20%E5%89%AA%E7%BB%B3%E5%AD%90/README.md) | `数学`,`动态规划` | 中等 | -| [14- II](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof) | [剪绳子 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20II.%20%E5%89%AA%E7%BB%B3%E5%AD%90%20II/README.md) | `数学`,`动态规划` | 中等 | -| [15](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof) | [二进制中1的个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9815.%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E4%B8%AD1%E7%9A%84%E4%B8%AA%E6%95%B0/README.md) | `位运算` | 简单 | -| [16](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof) | [数值的整数次方](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9816.%20%E6%95%B0%E5%80%BC%E7%9A%84%E6%95%B4%E6%95%B0%E6%AC%A1%E6%96%B9/README.md) | `递归` | 中等 | -| [17](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof) | [打印从1到最大的n位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9817.%20%E6%89%93%E5%8D%B0%E4%BB%8E1%E5%88%B0%E6%9C%80%E5%A4%A7%E7%9A%84n%E4%BD%8D%E6%95%B0/README.md) | `数学` | 简单 | -| [18](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | [删除链表的节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9818.%20%E5%88%A0%E9%99%A4%E9%93%BE%E8%A1%A8%E7%9A%84%E8%8A%82%E7%82%B9/README.md) | `链表` | 简单 | -| [19](https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof) | [正则表达式匹配](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9819.%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8C%B9%E9%85%8D/README.md) | `动态规划` | 困难 | -| [20](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof) | [表示数值的字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9820.%20%E8%A1%A8%E7%A4%BA%E6%95%B0%E5%80%BC%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `数学` | 中等 | -| [21](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof) | [调整数组顺序使奇数位于偶数前面](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9821.%20%E8%B0%83%E6%95%B4%E6%95%B0%E7%BB%84%E9%A1%BA%E5%BA%8F%E4%BD%BF%E5%A5%87%E6%95%B0%E4%BD%8D%E4%BA%8E%E5%81%B6%E6%95%B0%E5%89%8D%E9%9D%A2/README.md) | | 简单 | -| [22](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof) | [链表中倒数第k个节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9822.%20%E9%93%BE%E8%A1%A8%E4%B8%AD%E5%80%92%E6%95%B0%E7%AC%ACk%E4%B8%AA%E8%8A%82%E7%82%B9/README.md) | `链表`,`双指针` | 简单 | -| [24](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof) | [反转链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9824.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8/README.md) | `链表` | 简单 | -| [25](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof) | [合并两个排序的链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9825.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/README.md) | `分治算法` | 简单 | -| [26](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof) | [树的子结构](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9826.%20%E6%A0%91%E7%9A%84%E5%AD%90%E7%BB%93%E6%9E%84/README.md) | `树` | 中等 | -| [27](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof) | [二叉树的镜像](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9827.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/README.md) | `树` | 简单 | -| [28](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof) | [对称的二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9828.%20%E5%AF%B9%E7%A7%B0%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树` | 简单 | -| [29](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof) | [顺时针打印矩阵](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9829.%20%E9%A1%BA%E6%97%B6%E9%92%88%E6%89%93%E5%8D%B0%E7%9F%A9%E9%98%B5/README.md) | `数组` | 简单 | -| [30](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof) | [包含min函数的栈](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9830.%20%E5%8C%85%E5%90%ABmin%E5%87%BD%E6%95%B0%E7%9A%84%E6%A0%88/README.md) | `栈`,`设计` | 简单 | -| [31](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof) | [栈的压入、弹出序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9831.%20%E6%A0%88%E7%9A%84%E5%8E%8B%E5%85%A5%E3%80%81%E5%BC%B9%E5%87%BA%E5%BA%8F%E5%88%97/README.md) | | 中等 | -| [32 - I](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof) | [从上到下打印二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20I.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`广度优先搜索` | 中等 | -| [32 - II](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof) | [从上到下打印二叉树 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20II.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20II/README.md) | `树`,`广度优先搜索` | 简单 | -| [32 - III](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof) | [从上到下打印二叉树 III](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20III.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20III/README.md) | `树`,`广度优先搜索` | 中等 | -| [33](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof) | [二叉搜索树的后序遍历序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9833.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97/README.md) | | 中等 | -| [34](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof) | [二叉树中和为某一值的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9834.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E5%92%8C%E4%B8%BA%E6%9F%90%E4%B8%80%E5%80%BC%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) | `树`,`深度优先搜索` | 中等 | -| [35](https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof) | [复杂链表的复制](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9835.%20%E5%A4%8D%E6%9D%82%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%8D%E5%88%B6/README.md) | `链表` | 中等 | -| [36](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof) | [二叉搜索树与双向链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9836.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%8E%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/README.md) | `分治算法` | 中等 | -| [37](https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof) | [序列化二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9837.%20%E5%BA%8F%E5%88%97%E5%8C%96%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`设计` | 困难 | -| [38](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof) | [字符串的排列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9838.%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%8E%92%E5%88%97/README.md) | `回溯算法` | 中等 | -| [39](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof) | [数组中出现次数超过一半的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9839.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0%E8%B6%85%E8%BF%87%E4%B8%80%E5%8D%8A%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `位运算`,`分治算法` | 简单 | -| [40](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof) | [最小的k个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9840.%20%E6%9C%80%E5%B0%8F%E7%9A%84k%E4%B8%AA%E6%95%B0/README.md) | `堆`,`分治算法` | 简单 | -| [41](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof) | [数据流中的中位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9841.%20%E6%95%B0%E6%8D%AE%E6%B5%81%E4%B8%AD%E7%9A%84%E4%B8%AD%E4%BD%8D%E6%95%B0/README.md) | `堆`,`设计` | 困难 | -| [42](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof) | [连续子数组的最大和](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9842.%20%E8%BF%9E%E7%BB%AD%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/README.md) | `分治算法`,`动态规划` | 简单 | -| [43](https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof) | [1~n整数中1出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9843.%201%EF%BD%9En%E6%95%B4%E6%95%B0%E4%B8%AD1%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) | `数学` | 中等 | -| [44](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof) | [数字序列中某一位的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9844.%20%E6%95%B0%E5%AD%97%E5%BA%8F%E5%88%97%E4%B8%AD%E6%9F%90%E4%B8%80%E4%BD%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数学` | 中等 | -| [45](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof) | [把数组排成最小的数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9845.%20%E6%8A%8A%E6%95%B0%E7%BB%84%E6%8E%92%E6%88%90%E6%9C%80%E5%B0%8F%E7%9A%84%E6%95%B0/README.md) | `排序` | 中等 | -| [46](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | [把数字翻译成字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9846.%20%E6%8A%8A%E6%95%B0%E5%AD%97%E7%BF%BB%E8%AF%91%E6%88%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | | 中等 | -| [47](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof) | [礼物的最大价值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9847.%20%E7%A4%BC%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BB%B7%E5%80%BC/README.md) | `动态规划` | 中等 | -| [48](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof) | [最长不含重复字符的子字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9848.%20%E6%9C%80%E9%95%BF%E4%B8%8D%E5%90%AB%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `哈希表`,`双指针` | 中等 | -| [49](https://leetcode-cn.com/problems/chou-shu-lcof) | [丑数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9849.%20%E4%B8%91%E6%95%B0/README.md) | `数学` | 中等 | -| [50](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | [第一个只出现一次的字符](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9850.%20%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6/README.md) | `哈希表` | 简单 | -| [51](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof) | [数组中的逆序对](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9851.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%80%86%E5%BA%8F%E5%AF%B9/README.md) | | 困难 | -| [52](https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof) | [两个链表的第一个公共节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9852.%20%E4%B8%A4%E4%B8%AA%E9%93%BE%E8%A1%A8%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%AC%E5%85%B1%E8%8A%82%E7%82%B9/README.md) | `链表` | 简单 | -| [53 - I](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof) | [在排序数组中查找数字 I](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20I.%20%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%95%B0%E5%AD%97%20I/README.md) | `数组`,`二分查找` | 简单 | -| [53 - II](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof) | [0~n-1中缺失的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20II.%200%EF%BD%9En-1%E4%B8%AD%E7%BC%BA%E5%A4%B1%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数组`,`二分查找` | 简单 | -| [54](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | [二叉搜索树的第k大节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9854.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E7%AC%ACk%E5%A4%A7%E8%8A%82%E7%82%B9/README.md) | `树` | 简单 | -| [55 - I](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof) | [二叉树的深度](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%B7%B1%E5%BA%A6/README.md) | `树`,`深度优先搜索` | 简单 | -| [55 - II](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof) | [平衡二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20II.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`深度优先搜索` | 简单 | -| [56 - I](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof) | [数组中数字出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20I.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) | | 中等 | -| [56 - II](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof) | [数组中数字出现的次数 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20II.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%20II/README.md) | | 中等 | -| [57](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof) | [和为s的两个数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97/README.md) | | 简单 | -| [57 - II](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof) | [和为s的连续正数序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857%20-%20II.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E8%BF%9E%E7%BB%AD%E6%AD%A3%E6%95%B0%E5%BA%8F%E5%88%97/README.md) | | 简单 | -| [58 - I](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof) | [翻转单词顺序](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20I.%20%E7%BF%BB%E8%BD%AC%E5%8D%95%E8%AF%8D%E9%A1%BA%E5%BA%8F/README.md) | `字符串` | 简单 | -| [58 - II](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof) | [左旋转字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20II.%20%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `字符串` | 简单 | -| [59 - I](https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof) | [滑动窗口的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20I.%20%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) | `栈` | 简单 | -| [59 - II](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof) | [队列的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20II.%20%E9%98%9F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) | `栈` | 中等 | -| [60](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof) | [n个骰子的点数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9860.%20n%E4%B8%AA%E9%AA%B0%E5%AD%90%E7%9A%84%E7%82%B9%E6%95%B0/README.md) | | 简单 | -| [61](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof) | [扑克牌中的顺子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9861.%20%E6%89%91%E5%85%8B%E7%89%8C%E4%B8%AD%E7%9A%84%E9%A1%BA%E5%AD%90/README.md) | | 简单 | -| [62](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof) | [圆圈中最后剩下的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9862.%20%E5%9C%86%E5%9C%88%E4%B8%AD%E6%9C%80%E5%90%8E%E5%89%A9%E4%B8%8B%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | | 简单 | -| [63](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | [股票的最大利润](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9863.%20%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E5%A4%A7%E5%88%A9%E6%B6%A6/README.md) | `动态规划` | 中等 | -| [64](https://leetcode-cn.com/problems/qiu-12n-lcof) | [求1+2+…+n](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9864.%20%E6%B1%821%2B2%2B%E2%80%A6%2Bn/README.md) | | 中等 | -| [65](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof) | [不用加减乘除做加法](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9865.%20%E4%B8%8D%E7%94%A8%E5%8A%A0%E5%87%8F%E4%B9%98%E9%99%A4%E5%81%9A%E5%8A%A0%E6%B3%95/README.md) | | 简单 | -| [66](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof) | [构建乘积数组](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9866.%20%E6%9E%84%E5%BB%BA%E4%B9%98%E7%A7%AF%E6%95%B0%E7%BB%84/README.md) | | 简单 | -| [67](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof) | [把字符串转换成整数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9867.%20%E6%8A%8A%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%88%90%E6%95%B4%E6%95%B0/README.md) | `数学`,`字符串` | 中等 | -| [68 - I](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof) | [二叉搜索树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) | `树` | 简单 | -| [68 - II](https://leetcode-cn.com/problems/er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof) | [二叉树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20II.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) | `树` | 简单 | - +| 题号 | 题解 | 标签 | 难度 | +| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ---- | +| [03](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof) | [数组中重复的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9803.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E9%87%8D%E5%A4%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数组`,`哈希表` | 简单 | +| [04](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof) | [二维数组中的查找](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9804.%20%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9F%A5%E6%89%BE/README.md) | `数组`,`双指针` | 简单 | +| [05](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof) | [替换空格](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9805.%20%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/README.md) | | 简单 | +| [06](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof) | [从尾到头打印链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9806.%20%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/README.md) | | 简单 | +| [07](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof) | [重建二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9807.%20%E9%87%8D%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`递归` | 中等 | +| [09](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | [用两个栈实现队列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9809.%20%E7%94%A8%E4%B8%A4%E4%B8%AA%E6%A0%88%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97/README.md) | `栈`,`设计` | 简单 | +| [10- I](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | [斐波那契数列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20I.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/README.md) | `递归` | 简单 | +| [10- II](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof) | [青蛙跳台阶问题](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20II.%20%E9%9D%92%E8%9B%99%E8%B7%B3%E5%8F%B0%E9%98%B6%E9%97%AE%E9%A2%98/README.md) | `递归` | 简单 | +| [11](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof) | [旋转数组的最小数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9811.%20%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/README.md) | `二分查找` | 简单 | +| [12](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof) | [矩阵中的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9812.%20%E7%9F%A9%E9%98%B5%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) | `动态规划` | 中等 | +| [13](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof) | [机器人的运动范围](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9813.%20%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%9A%84%E8%BF%90%E5%8A%A8%E8%8C%83%E5%9B%B4/README.md) | | 中等 | +| [14- I](https://leetcode-cn.com/problems/jian-sheng-zi-lcof) | [剪绳子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20I.%20%E5%89%AA%E7%BB%B3%E5%AD%90/README.md) | `数学`,`动态规划` | 中等 | +| [14- II](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof) | [剪绳子 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20II.%20%E5%89%AA%E7%BB%B3%E5%AD%90%20II/README.md) | `数学`,`动态规划` | 中等 | +| [15](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof) | [二进制中 1 的个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9815.%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E4%B8%AD1%E7%9A%84%E4%B8%AA%E6%95%B0/README.md) | `位运算` | 简单 | +| [16](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof) | [数值的整数次方](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9816.%20%E6%95%B0%E5%80%BC%E7%9A%84%E6%95%B4%E6%95%B0%E6%AC%A1%E6%96%B9/README.md) | `递归` | 中等 | +| [17](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof) | [打印从 1 到最大的 n 位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9817.%20%E6%89%93%E5%8D%B0%E4%BB%8E1%E5%88%B0%E6%9C%80%E5%A4%A7%E7%9A%84n%E4%BD%8D%E6%95%B0/README.md) | `数学` | 简单 | +| [18](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | [删除链表的节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9818.%20%E5%88%A0%E9%99%A4%E9%93%BE%E8%A1%A8%E7%9A%84%E8%8A%82%E7%82%B9/README.md) | `链表` | 简单 | +| [19](https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof) | [正则表达式匹配](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9819.%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8C%B9%E9%85%8D/README.md) | `动态规划` | 困难 | +| [20](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof) | [表示数值的字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9820.%20%E8%A1%A8%E7%A4%BA%E6%95%B0%E5%80%BC%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `数学` | 中等 | +| [21](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof) | [调整数组顺序使奇数位于偶数前面](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9821.%20%E8%B0%83%E6%95%B4%E6%95%B0%E7%BB%84%E9%A1%BA%E5%BA%8F%E4%BD%BF%E5%A5%87%E6%95%B0%E4%BD%8D%E4%BA%8E%E5%81%B6%E6%95%B0%E5%89%8D%E9%9D%A2/README.md) | | 简单 | +| [22](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof) | [链表中倒数第 k 个节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9822.%20%E9%93%BE%E8%A1%A8%E4%B8%AD%E5%80%92%E6%95%B0%E7%AC%ACk%E4%B8%AA%E8%8A%82%E7%82%B9/README.md) | `链表`,`双指针` | 简单 | +| [24](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof) | [反转链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9824.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8/README.md) | `链表` | 简单 | +| [25](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof) | [合并两个排序的链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9825.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/README.md) | `分治算法` | 简单 | +| [26](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof) | [树的子结构](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9826.%20%E6%A0%91%E7%9A%84%E5%AD%90%E7%BB%93%E6%9E%84/README.md) | `树` | 中等 | +| [27](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof) | [二叉树的镜像](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9827.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/README.md) | `树` | 简单 | +| [28](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof) | [对称的二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9828.%20%E5%AF%B9%E7%A7%B0%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树` | 简单 | +| [29](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof) | [顺时针打印矩阵](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9829.%20%E9%A1%BA%E6%97%B6%E9%92%88%E6%89%93%E5%8D%B0%E7%9F%A9%E9%98%B5/README.md) | `数组` | 简单 | +| [30](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof) | [包含 min 函数的栈](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9830.%20%E5%8C%85%E5%90%ABmin%E5%87%BD%E6%95%B0%E7%9A%84%E6%A0%88/README.md) | `栈`,`设计` | 简单 | +| [31](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof) | [栈的压入、弹出序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9831.%20%E6%A0%88%E7%9A%84%E5%8E%8B%E5%85%A5%E3%80%81%E5%BC%B9%E5%87%BA%E5%BA%8F%E5%88%97/README.md) | | 中等 | +| [32 - I](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof) | [从上到下打印二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20I.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`广度优先搜索` | 中等 | +| [32 - II](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof) | [从上到下打印二叉树 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20II.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20II/README.md) | `树`,`广度优先搜索` | 简单 | +| [32 - III](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof) | [从上到下打印二叉树 III](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20III.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20III/README.md) | `树`,`广度优先搜索` | 中等 | +| [33](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof) | [二叉搜索树的后序遍历序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9833.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97/README.md) | | 中等 | +| [34](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof) | [二叉树中和为某一值的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9834.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E5%92%8C%E4%B8%BA%E6%9F%90%E4%B8%80%E5%80%BC%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) | `树`,`深度优先搜索` | 中等 | +| [35](https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof) | [复杂链表的复制](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9835.%20%E5%A4%8D%E6%9D%82%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%8D%E5%88%B6/README.md) | `链表` | 中等 | +| [36](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof) | [二叉搜索树与双向链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9836.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%8E%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/README.md) | `分治算法` | 中等 | +| [37](https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof) | [序列化二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9837.%20%E5%BA%8F%E5%88%97%E5%8C%96%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`设计` | 困难 | +| [38](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof) | [字符串的排列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9838.%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%8E%92%E5%88%97/README.md) | `回溯算法` | 中等 | +| [39](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof) | [数组中出现次数超过一半的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9839.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0%E8%B6%85%E8%BF%87%E4%B8%80%E5%8D%8A%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `位运算`,`分治算法` | 简单 | +| [40](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof) | [最小的 k 个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9840.%20%E6%9C%80%E5%B0%8F%E7%9A%84k%E4%B8%AA%E6%95%B0/README.md) | `堆`,`分治算法` | 简单 | +| [41](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof) | [数据流中的中位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9841.%20%E6%95%B0%E6%8D%AE%E6%B5%81%E4%B8%AD%E7%9A%84%E4%B8%AD%E4%BD%8D%E6%95%B0/README.md) | `堆`,`设计` | 困难 | +| [42](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof) | [连续子数组的最大和](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9842.%20%E8%BF%9E%E7%BB%AD%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/README.md) | `分治算法`,`动态规划` | 简单 | +| [43](https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof) | [1 ~ n 整数中 1 出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9843.%201%EF%BD%9En%E6%95%B4%E6%95%B0%E4%B8%AD1%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) | `数学` | 中等 | +| [44](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof) | [数字序列中某一位的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9844.%20%E6%95%B0%E5%AD%97%E5%BA%8F%E5%88%97%E4%B8%AD%E6%9F%90%E4%B8%80%E4%BD%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数学` | 中等 | +| [45](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof) | [把数组排成最小的数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9845.%20%E6%8A%8A%E6%95%B0%E7%BB%84%E6%8E%92%E6%88%90%E6%9C%80%E5%B0%8F%E7%9A%84%E6%95%B0/README.md) | `排序` | 中等 | +| [46](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | [把数字翻译成字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9846.%20%E6%8A%8A%E6%95%B0%E5%AD%97%E7%BF%BB%E8%AF%91%E6%88%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | | 中等 | +| [47](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof) | [礼物的最大价值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9847.%20%E7%A4%BC%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BB%B7%E5%80%BC/README.md) | `动态规划` | 中等 | +| [48](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof) | [最长不含重复字符的子字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9848.%20%E6%9C%80%E9%95%BF%E4%B8%8D%E5%90%AB%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `哈希表`,`双指针` | 中等 | +| [49](https://leetcode-cn.com/problems/chou-shu-lcof) | [丑数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9849.%20%E4%B8%91%E6%95%B0/README.md) | `数学` | 中等 | +| [50](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | [第一个只出现一次的字符](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9850.%20%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6/README.md) | `哈希表` | 简单 | +| [51](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof) | [数组中的逆序对](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9851.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%80%86%E5%BA%8F%E5%AF%B9/README.md) | | 困难 | +| [52](https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof) | [两个链表的第一个公共节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9852.%20%E4%B8%A4%E4%B8%AA%E9%93%BE%E8%A1%A8%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%AC%E5%85%B1%E8%8A%82%E7%82%B9/README.md) | `链表` | 简单 | +| [53 - I](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof) | [在排序数组中查找数字 I](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20I.%20%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%95%B0%E5%AD%97%20I/README.md) | `数组`,`二分查找` | 简单 | +| [53 - II](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof) | [0 ~ n-1 中缺失的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20II.%200%EF%BD%9En-1%E4%B8%AD%E7%BC%BA%E5%A4%B1%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | `数组`,`二分查找` | 简单 | +| [54](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | [二叉搜索树的第 k 大节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9854.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E7%AC%ACk%E5%A4%A7%E8%8A%82%E7%82%B9/README.md) | `树` | 简单 | +| [55 - I](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof) | [二叉树的深度](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%B7%B1%E5%BA%A6/README.md) | `树`,`深度优先搜索` | 简单 | +| [55 - II](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof) | [平衡二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20II.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) | `树`,`深度优先搜索` | 简单 | +| [56 - I](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof) | [数组中数字出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20I.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) | | 中等 | +| [56 - II](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof) | [数组中数字出现的次数 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20II.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%20II/README.md) | | 中等 | +| [57](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof) | [和为 s 的两个数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97/README.md) | | 简单 | +| [57 - II](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof) | [和为 s 的连续正数序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857%20-%20II.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E8%BF%9E%E7%BB%AD%E6%AD%A3%E6%95%B0%E5%BA%8F%E5%88%97/README.md) | | 简单 | +| [58 - I](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof) | [翻转单词顺序](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20I.%20%E7%BF%BB%E8%BD%AC%E5%8D%95%E8%AF%8D%E9%A1%BA%E5%BA%8F/README.md) | `字符串` | 简单 | +| [58 - II](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof) | [左旋转字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20II.%20%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) | `字符串` | 简单 | +| [59 - I](https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof) | [滑动窗口的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20I.%20%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) | `栈` | 简单 | +| [59 - II](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof) | [队列的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20II.%20%E9%98%9F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) | `栈` | 中等 | +| [60](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof) | [n 个骰子的点数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9860.%20n%E4%B8%AA%E9%AA%B0%E5%AD%90%E7%9A%84%E7%82%B9%E6%95%B0/README.md) | | 简单 | +| [61](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof) | [扑克牌中的顺子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9861.%20%E6%89%91%E5%85%8B%E7%89%8C%E4%B8%AD%E7%9A%84%E9%A1%BA%E5%AD%90/README.md) | | 简单 | +| [62](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof) | [圆圈中最后剩下的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9862.%20%E5%9C%86%E5%9C%88%E4%B8%AD%E6%9C%80%E5%90%8E%E5%89%A9%E4%B8%8B%E7%9A%84%E6%95%B0%E5%AD%97/README.md) | | 简单 | +| [63](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | [股票的最大利润](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9863.%20%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E5%A4%A7%E5%88%A9%E6%B6%A6/README.md) | `动态规划` | 中等 | +| [64](https://leetcode-cn.com/problems/qiu-12n-lcof) | [求 1+2+…+n](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9864.%20%E6%B1%821%2B2%2B%E2%80%A6%2Bn/README.md) | | 中等 | +| [65](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof) | [不用加减乘除做加法](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9865.%20%E4%B8%8D%E7%94%A8%E5%8A%A0%E5%87%8F%E4%B9%98%E9%99%A4%E5%81%9A%E5%8A%A0%E6%B3%95/README.md) | | 简单 | +| [66](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof) | [构建乘积数组](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9866.%20%E6%9E%84%E5%BB%BA%E4%B9%98%E7%A7%AF%E6%95%B0%E7%BB%84/README.md) | | 简单 | +| [67](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof) | [把字符串转换成整数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9867.%20%E6%8A%8A%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%88%90%E6%95%B4%E6%95%B0/README.md) | `数学`,`字符串` | 中等 | +| [68 - I](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof) | [二叉搜索树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) | `树` | 简单 | +| [68 - II](https://leetcode-cn.com/problems/er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof) | [二叉树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20II.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) | `树` | 简单 | ## 版权 -著作权归 [GitHub 开源社区 Doocs](https://github.com/doocs) 所有,商业转载请联系 [@yanglbme](mailto:contact@yanglibin.info) 授权,非商业转载请注明出处。 \ No newline at end of file + +著作权归 [GitHub 开源社区 Doocs](https://github.com/doocs) 所有,商业转载请联系 [@yanglbme](mailto:contact@yanglibin.info) 授权,非商业转载请注明出处。 diff --git a/lcof/README_EN.md b/lcof/README_EN.md index c570c189c17a2..f4059f3e7d4f2 100644 --- a/lcof/README_EN.md +++ b/lcof/README_EN.md @@ -1,4 +1,5 @@ -# [*Coding Interviews, 2nd Edition*](https://www.researchgate.net/file.PostFileLoader.html?id=5631f4596307d977348b4567&assetKey=AS:289838927499264@1446114393339) +# [_Coding Interviews, 2nd Edition_](https://www.researchgate.net/file.PostFileLoader.html?id=5631f4596307d977348b4567&assetKey=AS:289838927499264@1446114393339) + This book is about coding interview questions from software and Internet companies. It covers five key factors which determine performance of candidates: (1) the basics of programming languages, data structures and algorithms, (2) approaches to writing code with high quality, (3) tips to solve difficult problems, (4) methods to optimize code, (5) soft skills required in interviews. The basics of languages, algorithms and data structures are discussed as well as questions that explore how to write robust solutions after breaking down problems into manageable pieces. It also includes examples to focus on modeling and creative problem solving. Interview questions from the most popular companies in the IT industry are taken as examples to illustrate the five factors above. Besides solutions, it contains detailed analysis, how interviewers evaluate solutions, as well as why they like or dislike them. The author makes clever use of the fact that interviewees will have limited time to program meaningful solutions which in turn, limits the options an interviewer has. So the author covers those bases. @@ -8,9 +9,11 @@ Readers will improve their interview performance after reading this book. It wil [中文文档](/lcof/README.md) ## Solutions + English Solutions is not available for the book. Please switch to Chinese version. Press Control+F(or Command+F on the Mac) to search anything you want. ## Copyright -[@Doocs](https://github.com/doocs) \ No newline at end of file + +[@Doocs](https://github.com/doocs) diff --git a/lcof/README_TEMPLATE.md b/lcof/README_TEMPLATE.md index d9b3840c082d2..96ea4320466f1 100644 --- a/lcof/README_TEMPLATE.md +++ b/lcof/README_TEMPLATE.md @@ -1,14 +1,15 @@ # [题目](这里是题目链接,如:https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) ## 题目描述 - + ## 解法 - + ### Python3 + ```python @@ -16,6 +17,7 @@ ``` ### Java + ```java @@ -23,6 +25,7 @@ ``` ### ... + ``` ``` diff --git a/lcof/summary.md b/lcof/summary.md index 2c3f9c914fd20..d3d03840832d6 100644 --- a/lcof/summary.md +++ b/lcof/summary.md @@ -1,76 +1,76 @@ - LeetCode 《剑指 Offer(第 2 版)》题解 - - [03. 数组中重复的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9803.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E9%87%8D%E5%A4%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) - - [04. 二维数组中的查找](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9804.%20%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9F%A5%E6%89%BE/README.md) - - [05. 替换空格](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9805.%20%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/README.md) - - [06. 从尾到头打印链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9806.%20%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/README.md) - - [07. 重建二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9807.%20%E9%87%8D%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) - - [09. 用两个栈实现队列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9809.%20%E7%94%A8%E4%B8%A4%E4%B8%AA%E6%A0%88%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97/README.md) - - [10- I. 斐波那契数列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20I.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/README.md) - - [10- II. 青蛙跳台阶问题](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20II.%20%E9%9D%92%E8%9B%99%E8%B7%B3%E5%8F%B0%E9%98%B6%E9%97%AE%E9%A2%98/README.md) - - [11. 旋转数组的最小数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9811.%20%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/README.md) - - [12. 矩阵中的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9812.%20%E7%9F%A9%E9%98%B5%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) - - [13. 机器人的运动范围](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9813.%20%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%9A%84%E8%BF%90%E5%8A%A8%E8%8C%83%E5%9B%B4/README.md) - - [14- I. 剪绳子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20I.%20%E5%89%AA%E7%BB%B3%E5%AD%90/README.md) - - [14- II. 剪绳子 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20II.%20%E5%89%AA%E7%BB%B3%E5%AD%90%20II/README.md) - - [15. 二进制中1的个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9815.%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E4%B8%AD1%E7%9A%84%E4%B8%AA%E6%95%B0/README.md) - - [16. 数值的整数次方](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9816.%20%E6%95%B0%E5%80%BC%E7%9A%84%E6%95%B4%E6%95%B0%E6%AC%A1%E6%96%B9/README.md) - - [17. 打印从1到最大的n位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9817.%20%E6%89%93%E5%8D%B0%E4%BB%8E1%E5%88%B0%E6%9C%80%E5%A4%A7%E7%9A%84n%E4%BD%8D%E6%95%B0/README.md) - - [18. 删除链表的节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9818.%20%E5%88%A0%E9%99%A4%E9%93%BE%E8%A1%A8%E7%9A%84%E8%8A%82%E7%82%B9/README.md) - - [19. 正则表达式匹配](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9819.%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8C%B9%E9%85%8D/README.md) - - [20. 表示数值的字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9820.%20%E8%A1%A8%E7%A4%BA%E6%95%B0%E5%80%BC%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) - - [21. 调整数组顺序使奇数位于偶数前面](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9821.%20%E8%B0%83%E6%95%B4%E6%95%B0%E7%BB%84%E9%A1%BA%E5%BA%8F%E4%BD%BF%E5%A5%87%E6%95%B0%E4%BD%8D%E4%BA%8E%E5%81%B6%E6%95%B0%E5%89%8D%E9%9D%A2/README.md) - - [22. 链表中倒数第k个节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9822.%20%E9%93%BE%E8%A1%A8%E4%B8%AD%E5%80%92%E6%95%B0%E7%AC%ACk%E4%B8%AA%E8%8A%82%E7%82%B9/README.md) - - [24. 反转链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9824.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8/README.md) - - [25. 合并两个排序的链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9825.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/README.md) - - [26. 树的子结构](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9826.%20%E6%A0%91%E7%9A%84%E5%AD%90%E7%BB%93%E6%9E%84/README.md) - - [27. 二叉树的镜像](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9827.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/README.md) - - [28. 对称的二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9828.%20%E5%AF%B9%E7%A7%B0%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) - - [29. 顺时针打印矩阵](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9829.%20%E9%A1%BA%E6%97%B6%E9%92%88%E6%89%93%E5%8D%B0%E7%9F%A9%E9%98%B5/README.md) - - [30. 包含min函数的栈](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9830.%20%E5%8C%85%E5%90%ABmin%E5%87%BD%E6%95%B0%E7%9A%84%E6%A0%88/README.md) - - [31. 栈的压入、弹出序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9831.%20%E6%A0%88%E7%9A%84%E5%8E%8B%E5%85%A5%E3%80%81%E5%BC%B9%E5%87%BA%E5%BA%8F%E5%88%97/README.md) - - [32 - I. 从上到下打印二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20I.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) - - [32 - II. 从上到下打印二叉树 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20II.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20II/README.md) - - [32 - III. 从上到下打印二叉树 III](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20III.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20III/README.md) - - [33. 二叉搜索树的后序遍历序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9833.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97/README.md) - - [34. 二叉树中和为某一值的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9834.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E5%92%8C%E4%B8%BA%E6%9F%90%E4%B8%80%E5%80%BC%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) - - [35. 复杂链表的复制](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9835.%20%E5%A4%8D%E6%9D%82%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%8D%E5%88%B6/README.md) - - [36. 二叉搜索树与双向链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9836.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%8E%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/README.md) - - [37. 序列化二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9837.%20%E5%BA%8F%E5%88%97%E5%8C%96%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) - - [38. 字符串的排列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9838.%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%8E%92%E5%88%97/README.md) - - [39. 数组中出现次数超过一半的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9839.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0%E8%B6%85%E8%BF%87%E4%B8%80%E5%8D%8A%E7%9A%84%E6%95%B0%E5%AD%97/README.md) - - [40. 最小的k个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9840.%20%E6%9C%80%E5%B0%8F%E7%9A%84k%E4%B8%AA%E6%95%B0/README.md) - - [41. 数据流中的中位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9841.%20%E6%95%B0%E6%8D%AE%E6%B5%81%E4%B8%AD%E7%9A%84%E4%B8%AD%E4%BD%8D%E6%95%B0/README.md) - - [42. 连续子数组的最大和](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9842.%20%E8%BF%9E%E7%BB%AD%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/README.md) - - [43. 1~n整数中1出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9843.%201%EF%BD%9En%E6%95%B4%E6%95%B0%E4%B8%AD1%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) - - [44. 数字序列中某一位的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9844.%20%E6%95%B0%E5%AD%97%E5%BA%8F%E5%88%97%E4%B8%AD%E6%9F%90%E4%B8%80%E4%BD%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) - - [45. 把数组排成最小的数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9845.%20%E6%8A%8A%E6%95%B0%E7%BB%84%E6%8E%92%E6%88%90%E6%9C%80%E5%B0%8F%E7%9A%84%E6%95%B0/README.md) - - [46. 把数字翻译成字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9846.%20%E6%8A%8A%E6%95%B0%E5%AD%97%E7%BF%BB%E8%AF%91%E6%88%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) - - [47. 礼物的最大价值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9847.%20%E7%A4%BC%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BB%B7%E5%80%BC/README.md) - - [48. 最长不含重复字符的子字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9848.%20%E6%9C%80%E9%95%BF%E4%B8%8D%E5%90%AB%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) - - [49. 丑数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9849.%20%E4%B8%91%E6%95%B0/README.md) - - [50. 第一个只出现一次的字符](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9850.%20%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6/README.md) - - [51. 数组中的逆序对](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9851.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%80%86%E5%BA%8F%E5%AF%B9/README.md) - - [52. 两个链表的第一个公共节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9852.%20%E4%B8%A4%E4%B8%AA%E9%93%BE%E8%A1%A8%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%AC%E5%85%B1%E8%8A%82%E7%82%B9/README.md) - - [53 - I. 在排序数组中查找数字 I](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20I.%20%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%95%B0%E5%AD%97%20I/README.md) - - [53 - II. 0~n-1中缺失的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20II.%200%EF%BD%9En-1%E4%B8%AD%E7%BC%BA%E5%A4%B1%E7%9A%84%E6%95%B0%E5%AD%97/README.md) - - [54. 二叉搜索树的第k大节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9854.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E7%AC%ACk%E5%A4%A7%E8%8A%82%E7%82%B9/README.md) - - [55 - I. 二叉树的深度](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%B7%B1%E5%BA%A6/README.md) - - [55 - II. 平衡二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20II.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) - - [56 - I. 数组中数字出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20I.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) - - [56 - II. 数组中数字出现的次数 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20II.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%20II/README.md) - - [57. 和为s的两个数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97/README.md) - - [57 - II. 和为s的连续正数序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857%20-%20II.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E8%BF%9E%E7%BB%AD%E6%AD%A3%E6%95%B0%E5%BA%8F%E5%88%97/README.md) - - [58 - I. 翻转单词顺序](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20I.%20%E7%BF%BB%E8%BD%AC%E5%8D%95%E8%AF%8D%E9%A1%BA%E5%BA%8F/README.md) - - [58 - II. 左旋转字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20II.%20%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) - - [59 - I. 滑动窗口的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20I.%20%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) - - [59 - II. 队列的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20II.%20%E9%98%9F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) - - [60. n个骰子的点数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9860.%20n%E4%B8%AA%E9%AA%B0%E5%AD%90%E7%9A%84%E7%82%B9%E6%95%B0/README.md) - - [61. 扑克牌中的顺子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9861.%20%E6%89%91%E5%85%8B%E7%89%8C%E4%B8%AD%E7%9A%84%E9%A1%BA%E5%AD%90/README.md) - - [62. 圆圈中最后剩下的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9862.%20%E5%9C%86%E5%9C%88%E4%B8%AD%E6%9C%80%E5%90%8E%E5%89%A9%E4%B8%8B%E7%9A%84%E6%95%B0%E5%AD%97/README.md) - - [63. 股票的最大利润](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9863.%20%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E5%A4%A7%E5%88%A9%E6%B6%A6/README.md) - - [64. 求1+2+…+n](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9864.%20%E6%B1%821%2B2%2B%E2%80%A6%2Bn/README.md) - - [65. 不用加减乘除做加法](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9865.%20%E4%B8%8D%E7%94%A8%E5%8A%A0%E5%87%8F%E4%B9%98%E9%99%A4%E5%81%9A%E5%8A%A0%E6%B3%95/README.md) - - [66. 构建乘积数组](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9866.%20%E6%9E%84%E5%BB%BA%E4%B9%98%E7%A7%AF%E6%95%B0%E7%BB%84/README.md) - - [67. 把字符串转换成整数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9867.%20%E6%8A%8A%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%88%90%E6%95%B4%E6%95%B0/README.md) - - [68 - I. 二叉搜索树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) - - [68 - II. 二叉树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20II.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) + - [03. 数组中重复的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9803.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E9%87%8D%E5%A4%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) + - [04. 二维数组中的查找](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9804.%20%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9F%A5%E6%89%BE/README.md) + - [05. 替换空格](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9805.%20%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/README.md) + - [06. 从尾到头打印链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9806.%20%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/README.md) + - [07. 重建二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9807.%20%E9%87%8D%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) + - [09. 用两个栈实现队列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9809.%20%E7%94%A8%E4%B8%A4%E4%B8%AA%E6%A0%88%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97/README.md) + - [10- I. 斐波那契数列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20I.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/README.md) + - [10- II. 青蛙跳台阶问题](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20II.%20%E9%9D%92%E8%9B%99%E8%B7%B3%E5%8F%B0%E9%98%B6%E9%97%AE%E9%A2%98/README.md) + - [11. 旋转数组的最小数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9811.%20%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/README.md) + - [12. 矩阵中的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9812.%20%E7%9F%A9%E9%98%B5%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) + - [13. 机器人的运动范围](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9813.%20%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%9A%84%E8%BF%90%E5%8A%A8%E8%8C%83%E5%9B%B4/README.md) + - [14- I. 剪绳子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20I.%20%E5%89%AA%E7%BB%B3%E5%AD%90/README.md) + - [14- II. 剪绳子 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9814-%20II.%20%E5%89%AA%E7%BB%B3%E5%AD%90%20II/README.md) + - [15. 二进制中 1 的个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9815.%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E4%B8%AD1%E7%9A%84%E4%B8%AA%E6%95%B0/README.md) + - [16. 数值的整数次方](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9816.%20%E6%95%B0%E5%80%BC%E7%9A%84%E6%95%B4%E6%95%B0%E6%AC%A1%E6%96%B9/README.md) + - [17. 打印从 1 到最大的 n 位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9817.%20%E6%89%93%E5%8D%B0%E4%BB%8E1%E5%88%B0%E6%9C%80%E5%A4%A7%E7%9A%84n%E4%BD%8D%E6%95%B0/README.md) + - [18. 删除链表的节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9818.%20%E5%88%A0%E9%99%A4%E9%93%BE%E8%A1%A8%E7%9A%84%E8%8A%82%E7%82%B9/README.md) + - [19. 正则表达式匹配](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9819.%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8C%B9%E9%85%8D/README.md) + - [20. 表示数值的字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9820.%20%E8%A1%A8%E7%A4%BA%E6%95%B0%E5%80%BC%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) + - [21. 调整数组顺序使奇数位于偶数前面](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9821.%20%E8%B0%83%E6%95%B4%E6%95%B0%E7%BB%84%E9%A1%BA%E5%BA%8F%E4%BD%BF%E5%A5%87%E6%95%B0%E4%BD%8D%E4%BA%8E%E5%81%B6%E6%95%B0%E5%89%8D%E9%9D%A2/README.md) + - [22. 链表中倒数第 k 个节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9822.%20%E9%93%BE%E8%A1%A8%E4%B8%AD%E5%80%92%E6%95%B0%E7%AC%ACk%E4%B8%AA%E8%8A%82%E7%82%B9/README.md) + - [24. 反转链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9824.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8/README.md) + - [25. 合并两个排序的链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9825.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/README.md) + - [26. 树的子结构](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9826.%20%E6%A0%91%E7%9A%84%E5%AD%90%E7%BB%93%E6%9E%84/README.md) + - [27. 二叉树的镜像](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9827.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/README.md) + - [28. 对称的二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9828.%20%E5%AF%B9%E7%A7%B0%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) + - [29. 顺时针打印矩阵](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9829.%20%E9%A1%BA%E6%97%B6%E9%92%88%E6%89%93%E5%8D%B0%E7%9F%A9%E9%98%B5/README.md) + - [30. 包含 min 函数的栈](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9830.%20%E5%8C%85%E5%90%ABmin%E5%87%BD%E6%95%B0%E7%9A%84%E6%A0%88/README.md) + - [31. 栈的压入、弹出序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9831.%20%E6%A0%88%E7%9A%84%E5%8E%8B%E5%85%A5%E3%80%81%E5%BC%B9%E5%87%BA%E5%BA%8F%E5%88%97/README.md) + - [32 - I. 从上到下打印二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20I.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) + - [32 - II. 从上到下打印二叉树 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20II.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20II/README.md) + - [32 - III. 从上到下打印二叉树 III](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20III.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20III/README.md) + - [33. 二叉搜索树的后序遍历序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9833.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97/README.md) + - [34. 二叉树中和为某一值的路径](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9834.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E5%92%8C%E4%B8%BA%E6%9F%90%E4%B8%80%E5%80%BC%E7%9A%84%E8%B7%AF%E5%BE%84/README.md) + - [35. 复杂链表的复制](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9835.%20%E5%A4%8D%E6%9D%82%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%8D%E5%88%B6/README.md) + - [36. 二叉搜索树与双向链表](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9836.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%8E%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/README.md) + - [37. 序列化二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9837.%20%E5%BA%8F%E5%88%97%E5%8C%96%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) + - [38. 字符串的排列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9838.%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%8E%92%E5%88%97/README.md) + - [39. 数组中出现次数超过一半的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9839.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0%E8%B6%85%E8%BF%87%E4%B8%80%E5%8D%8A%E7%9A%84%E6%95%B0%E5%AD%97/README.md) + - [40. 最小的 k 个数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9840.%20%E6%9C%80%E5%B0%8F%E7%9A%84k%E4%B8%AA%E6%95%B0/README.md) + - [41. 数据流中的中位数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9841.%20%E6%95%B0%E6%8D%AE%E6%B5%81%E4%B8%AD%E7%9A%84%E4%B8%AD%E4%BD%8D%E6%95%B0/README.md) + - [42. 连续子数组的最大和](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9842.%20%E8%BF%9E%E7%BB%AD%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/README.md) + - [43. 1 ~ n 整数中 1 出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9843.%201%EF%BD%9En%E6%95%B4%E6%95%B0%E4%B8%AD1%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) + - [44. 数字序列中某一位的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9844.%20%E6%95%B0%E5%AD%97%E5%BA%8F%E5%88%97%E4%B8%AD%E6%9F%90%E4%B8%80%E4%BD%8D%E7%9A%84%E6%95%B0%E5%AD%97/README.md) + - [45. 把数组排成最小的数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9845.%20%E6%8A%8A%E6%95%B0%E7%BB%84%E6%8E%92%E6%88%90%E6%9C%80%E5%B0%8F%E7%9A%84%E6%95%B0/README.md) + - [46. 把数字翻译成字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9846.%20%E6%8A%8A%E6%95%B0%E5%AD%97%E7%BF%BB%E8%AF%91%E6%88%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) + - [47. 礼物的最大价值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9847.%20%E7%A4%BC%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BB%B7%E5%80%BC/README.md) + - [48. 最长不含重复字符的子字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9848.%20%E6%9C%80%E9%95%BF%E4%B8%8D%E5%90%AB%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) + - [49. 丑数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9849.%20%E4%B8%91%E6%95%B0/README.md) + - [50. 第一个只出现一次的字符](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9850.%20%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6/README.md) + - [51. 数组中的逆序对](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9851.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%80%86%E5%BA%8F%E5%AF%B9/README.md) + - [52. 两个链表的第一个公共节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9852.%20%E4%B8%A4%E4%B8%AA%E9%93%BE%E8%A1%A8%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%AC%E5%85%B1%E8%8A%82%E7%82%B9/README.md) + - [53 - I. 在排序数组中查找数字 I](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20I.%20%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%95%B0%E5%AD%97%20I/README.md) + - [53 - II. 0 ~ n-1 中缺失的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9853%20-%20II.%200%EF%BD%9En-1%E4%B8%AD%E7%BC%BA%E5%A4%B1%E7%9A%84%E6%95%B0%E5%AD%97/README.md) + - [54. 二叉搜索树的第 k 大节点](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9854.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E7%AC%ACk%E5%A4%A7%E8%8A%82%E7%82%B9/README.md) + - [55 - I. 二叉树的深度](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%B7%B1%E5%BA%A6/README.md) + - [55 - II. 平衡二叉树](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9855%20-%20II.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91/README.md) + - [56 - I. 数组中数字出现的次数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20I.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0/README.md) + - [56 - II. 数组中数字出现的次数 II](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9856%20-%20II.%20%E6%95%B0%E7%BB%84%E4%B8%AD%E6%95%B0%E5%AD%97%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%20II/README.md) + - [57. 和为 s 的两个数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97/README.md) + - [57 - II. 和为 s 的连续正数序列](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9857%20-%20II.%20%E5%92%8C%E4%B8%BAs%E7%9A%84%E8%BF%9E%E7%BB%AD%E6%AD%A3%E6%95%B0%E5%BA%8F%E5%88%97/README.md) + - [58 - I. 翻转单词顺序](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20I.%20%E7%BF%BB%E8%BD%AC%E5%8D%95%E8%AF%8D%E9%A1%BA%E5%BA%8F/README.md) + - [58 - II. 左旋转字符串](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9858%20-%20II.%20%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/README.md) + - [59 - I. 滑动窗口的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20I.%20%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) + - [59 - II. 队列的最大值](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9859%20-%20II.%20%E9%98%9F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/README.md) + - [60. n 个骰子的点数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9860.%20n%E4%B8%AA%E9%AA%B0%E5%AD%90%E7%9A%84%E7%82%B9%E6%95%B0/README.md) + - [61. 扑克牌中的顺子](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9861.%20%E6%89%91%E5%85%8B%E7%89%8C%E4%B8%AD%E7%9A%84%E9%A1%BA%E5%AD%90/README.md) + - [62. 圆圈中最后剩下的数字](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9862.%20%E5%9C%86%E5%9C%88%E4%B8%AD%E6%9C%80%E5%90%8E%E5%89%A9%E4%B8%8B%E7%9A%84%E6%95%B0%E5%AD%97/README.md) + - [63. 股票的最大利润](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9863.%20%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E5%A4%A7%E5%88%A9%E6%B6%A6/README.md) + - [64. 求 1+2+…+n](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9864.%20%E6%B1%821%2B2%2B%E2%80%A6%2Bn/README.md) + - [65. 不用加减乘除做加法](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9865.%20%E4%B8%8D%E7%94%A8%E5%8A%A0%E5%87%8F%E4%B9%98%E9%99%A4%E5%81%9A%E5%8A%A0%E6%B3%95/README.md) + - [66. 构建乘积数组](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9866.%20%E6%9E%84%E5%BB%BA%E4%B9%98%E7%A7%AF%E6%95%B0%E7%BB%84/README.md) + - [67. 把字符串转换成整数](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9867.%20%E6%8A%8A%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%88%90%E6%95%B4%E6%95%B0/README.md) + - [68 - I. 二叉搜索树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20I.%20%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) + - [68 - II. 二叉树的最近公共祖先](/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9868%20-%20II.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/README.md) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" index 41916fe404c0a..3b7e0c8d3bd89 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" @@ -1,17 +1,18 @@ -# [面试题03. 数组中重复的数字](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) +# [面试题 03. 数组中重复的数字](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) ## 题目描述 + 找出数组中重复的数字。 -在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 +在一个长度为 n 的数组 nums 里的所有数字都在 0 ~ n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 **示例 1:** ``` 输入: [2, 3, 1, 0, 2, 5, 3] -输出:2 或 3 -``` +输出:2 或 3 +``` **限制:** @@ -20,13 +21,15 @@ ``` ## 解法 -0~n-1 范围内的数,分别还原到对应的位置上,如:数字 2 交换到下标为 2 的位置。 + +0 ~ n-1 范围内的数,分别还原到对应的位置上,如:数字 2 交换到下标为 2 的位置。 若交换过程中发现重复,则直接返回。 ### **Python3** + ```python class Solution: def findRepeatNumber(self, nums: List[int]) -> int: @@ -40,6 +43,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int findRepeatNumber(int[] nums) { @@ -63,17 +67,18 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var findRepeatNumber = function(nums) { - let m = {} - for(let num of nums) { - if(m[num]) return num - m[num] = 1 - } +var findRepeatNumber = function (nums) { + let m = {}; + for (let num of nums) { + if (m[num]) return num; + m[num] = 1; + } }; ``` @@ -94,7 +99,9 @@ func findRepeatNumber(nums []int) int { ``` ### **...** + ``` ``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/Solution.js" index a09fb63a5e24c..34a5b3a21460a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/Solution.js" @@ -2,10 +2,10 @@ * @param {number[]} nums * @return {number} */ -var findRepeatNumber = function(nums) { - let m = {} - for(let num of nums) { - if(m[num]) return num - m[num] = 1 - } -}; \ No newline at end of file +var findRepeatNumber = function (nums) { + let m = {}; + for (let num of nums) { + if (m[num]) return num; + m[num] = 1; + } +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" index 84129c987c5c5..813ef953ff8c6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" @@ -1,7 +1,8 @@ -# [面试题04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) +# [面试题 04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) ## 题目描述 -在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 + +在一个 n \* m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 **示例:** @@ -17,9 +18,9 @@ ] ``` -给定 target = 5,返回 `true`。 +给定 target = 5,返回  `true`。 -给定 target = 20,返回 `false`。 +给定  target = 20,返回  `false`。 **限制:** @@ -28,11 +29,13 @@ - `0 <= m <= 1000` ## 解法 + 从左下角(或右上角)开始查找即可。 ### **Python3** + ```python class Solution: def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool: @@ -52,6 +55,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { @@ -76,31 +80,33 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[][]} matrix * @param {number} target * @return {boolean} */ -var findNumberIn2DArray = function(matrix, target) { - let row = matrix.length - let col = matrix[0].length - function dfs(i,j) { - if(i < 0 || j >= col) { - return false - } - if(matrix[i][j] === target) return true - else if(matrix[i][j] > target) { - return dfs(i-1,j) - } else { - return dfs(i,j+1) - } +var findNumberIn2DArray = function (matrix, target) { + let row = matrix.length; + let col = matrix[0].length; + function dfs(i, j) { + if (i < 0 || j >= col) { + return false; + } + if (matrix[i][j] === target) return true; + else if (matrix[i][j] > target) { + return dfs(i - 1, j); + } else { + return dfs(i, j + 1); } - return dfs(row-1,0) + } + return dfs(row - 1, 0); }; ``` ### **Go** + ```go func findNumberIn2DArray(matrix [][]int, target int) bool { if len(matrix) == 0 { @@ -118,13 +124,14 @@ func findNumberIn2DArray(matrix [][]int, target int) bool { j++ } } - return false + return false } ``` - ### **...** + ``` ``` - \ No newline at end of file + + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" index a24d211a46bb4..eb334c8af09c6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" @@ -3,19 +3,19 @@ * @param {number} target * @return {boolean} */ -var findNumberIn2DArray = function(matrix, target) { - let row = matrix.length - let col = matrix[0].length - function dfs(i,j) { - if(i < 0 || j >= col) { - return false - } - if(matrix[i][j] === target) return true - else if(matrix[i][j] > target) { - return dfs(i-1,j) - } else { - return dfs(i,j+1) - } +var findNumberIn2DArray = function (matrix, target) { + let row = matrix.length; + let col = matrix[0].length; + function dfs(i, j) { + if (i < 0 || j >= col) { + return false; } - return dfs(row-1,0) -}; \ No newline at end of file + if (matrix[i][j] === target) return true; + else if (matrix[i][j] > target) { + return dfs(i - 1, j); + } else { + return dfs(i, j + 1); + } + } + return dfs(row - 1, 0); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" index c91e9a1fa80f7..d26bb8168fb5f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" @@ -1,6 +1,7 @@ -# [面试题05. 替换空格](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) +# [面试题 05. 替换空格](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) ## 题目描述 + 请实现一个函数,把字符串 `s` 中的每个空格替换成"%20"。 **示例 1:** @@ -15,11 +16,13 @@ - `0 <= s 的长度 <= 10000` ## 解法 + 使用 replace 替换即可。 ### **Python3** + ```python class Solution: def replaceSpace(self, s: str) -> str: @@ -27,6 +30,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public String replaceSpace(String s) { @@ -36,17 +40,19 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @return {string} */ -var replaceSpace = function(s) { - return s.split(' ').join('%20') +var replaceSpace = function (s) { + return s.split(" ").join("%20"); }; ``` ### **Go** + ```go func replaceSpace(s string) string { return strings.Replace(s, " ", "%20", -1 ) @@ -54,8 +60,9 @@ func replaceSpace(s string) string { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" index 7408d235562c0..4e81b7a194bb6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" @@ -2,6 +2,6 @@ * @param {string} s * @return {string} */ -var replaceSpace = function(s) { - return s.split(' ').join('%20') -}; \ No newline at end of file +var replaceSpace = function (s) { + return s.split(" ").join("%20"); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" index 30b5d814551d7..fd447323280cb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" @@ -1,9 +1,11 @@ -# [面试题06. 从尾到头打印链表](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) +# [面试题 06. 从尾到头打印链表](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) ## 题目描述 + 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 **示例 1:** + ``` 输入:head = [1,3,2] 输出:[2,3,1] @@ -14,11 +16,13 @@ - `0 <= 链表长度 <= 10000` ## 解法 + 栈实现。 ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -36,6 +40,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -63,6 +68,7 @@ class Solution { ``` ### **Go** + ```go /** * Definition for singly-linked list. @@ -83,8 +89,9 @@ func reversePrint(head *ListNode) []int { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" index 2f0547e64aafa..40065372d5c60 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" @@ -9,12 +9,12 @@ * @param {ListNode} head * @return {number[]} */ -var reversePrint = function(head) { - let node = head - let res = [] - while(node) { - res.unshift(node.val) - node = node.next - } - return res -}; \ No newline at end of file +var reversePrint = function (head) { + let node = head; + let res = []; + while (node) { + res.unshift(node.val); + node = node.next; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" index 7f247aff72204..66d596336ffd4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" @@ -1,6 +1,7 @@ -# [面试题07. 重建二叉树](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) +# [面试题 07. 重建二叉树](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) ## 题目描述 + 输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 例如,给出 @@ -20,15 +21,16 @@ 15 7 ``` - **限制:** - `0 <= 节点个数 <= 5000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -42,7 +44,7 @@ class Solution: if preorder is None or inorder is None or len(preorder) != len(inorder): return None return self._build_tree(preorder, 0, len(preorder) - 1, inorder, 0, len(inorder) - 1) - + def _build_tree(self, preorder, s1, e1, inorder, s2, e2): if s1 > e1 or s2 > e2: return None @@ -60,6 +62,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -102,6 +105,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -115,26 +119,26 @@ class Solution { * @param {number[]} inorder * @return {TreeNode} */ -var buildTree = function(preorder, inorder) { - if(!preorder || !preorder.length) return null - let preIdx = 0 - let inMap = {} - for(let i=0;i end) { - return null - } - let preVal = preorder[preIdx] - preIdx++ - let inIdx = inMap[preVal] - let node = new TreeNode(preVal) - node.left = func(start, inIdx - 1) - node.right = func(inIdx + 1, end) - return node +var buildTree = function (preorder, inorder) { + if (!preorder || !preorder.length) return null; + let preIdx = 0; + let inMap = {}; + for (let i = 0; i < inorder.length; i++) { + inMap[inorder[i]] = i; + } + function func(start, end) { + if (start > end) { + return null; } - return func(0, preorder.length - 1) + let preVal = preorder[preIdx]; + preIdx++; + let inIdx = inMap[preVal]; + let node = new TreeNode(preVal); + node.left = func(start, inIdx - 1); + node.right = func(inIdx + 1, end); + return node; + } + return func(0, preorder.length - 1); }; ``` @@ -168,12 +172,10 @@ func helper(preorder, inorder []int, index, start, end int) *TreeNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" index 3b574635c8087..b4d0675d3184e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" @@ -10,24 +10,24 @@ * @param {number[]} inorder * @return {TreeNode} */ -var buildTree = function(preorder, inorder) { - if(!preorder || !preorder.length) return null - let preIdx = 0 - let inMap = {} - for(let i=0;i end) { + return null; } - function func(start, end) { - if(start > end) { - return null - } - let preVal = preorder[preIdx] - preIdx++ - let inIdx = inMap[preVal] - let node = new TreeNode(preVal) - node.left = func(start, inIdx - 1) - node.right = func(inIdx + 1, end) - return node - } - return func(0, preorder.length - 1) -}; \ No newline at end of file + let preVal = preorder[preIdx]; + preIdx++; + let inIdx = inMap[preVal]; + let node = new TreeNode(preVal); + node.left = func(start, inIdx - 1); + node.right = func(inIdx + 1, end); + return node; + } + return func(0, preorder.length - 1); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" index 83014f54757f7..0561cd13bfda6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" @@ -1,7 +1,8 @@ -# [面试题09. 用两个栈实现队列](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) +# [面试题 09. 用两个栈实现队列](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) ## 题目描述 -用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 `appendTail` 和 `deleteHead` ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,`deleteHead` 操作返回 -1 ) + +用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 `appendTail` 和 `deleteHead` ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,`deleteHead`  操作返回 -1 ) **示例 1:** @@ -24,19 +25,21 @@ **提示:** - `1 <= values <= 10000` -- `最多会对 appendTail、deleteHead 进行 10000 次调用` +- `最多会对 appendTail、deleteHead 进行 10000 次调用` ## 解法 + ### **Python3** + ```python class CQueue: def __init__(self): self._s1 = [] self._s2 = [] - + def _check(self): if not self._s2: while self._s1: @@ -58,6 +61,7 @@ class CQueue: ``` ### **Java** + ```java class CQueue { private Stack s1 = new Stack<>(); @@ -66,12 +70,12 @@ class CQueue { public CQueue() { } - + public void appendTail(int value) { s1.push(value); check(); } - + public int deleteHead() { check(); return s2.empty() ? -1 : s2.pop(); @@ -95,34 +99,35 @@ class CQueue { ``` ### **JavaScript** + ```js -var CQueue = function() { - this.data = [] - this.helper = [] +var CQueue = function () { + this.data = []; + this.helper = []; }; -/** +/** * @param {number} value * @return {void} */ -CQueue.prototype.appendTail = function(value) { - this.data.push(value) +CQueue.prototype.appendTail = function (value) { + this.data.push(value); }; /** * @return {number} */ -CQueue.prototype.deleteHead = function() { - if(this.data.length) { - while(this.data.length > 1) { - this.helper.push(this.data.pop()) - } - let res = this.data.pop() - while(this.helper.length) { - this.data.push(this.helper.pop()) - } - return res - } else { - return -1 +CQueue.prototype.deleteHead = function () { + if (this.data.length) { + while (this.data.length > 1) { + this.helper.push(this.data.pop()); } + let res = this.data.pop(); + while (this.helper.length) { + this.data.push(this.helper.pop()); + } + return res; + } else { + return -1; + } }; ``` @@ -164,12 +169,10 @@ func (this *CQueue) DeleteHead() int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" index 1472cd7f86239..2114fa6ec21c8 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" @@ -1,28 +1,28 @@ -var CQueue = function() { - this.data = [] - this.helper = [] +var CQueue = function () { + this.data = []; + this.helper = []; }; -/** +/** * @param {number} value * @return {void} */ -CQueue.prototype.appendTail = function(value) { - this.data.push(value) +CQueue.prototype.appendTail = function (value) { + this.data.push(value); }; /** * @return {number} */ -CQueue.prototype.deleteHead = function() { - if(this.data.length) { - while(this.data.length > 1) { - this.helper.push(this.data.pop()) - } - let res = this.data.pop() - while(this.helper.length) { - this.data.push(this.helper.pop()) - } - return res - } else { - return -1 +CQueue.prototype.deleteHead = function () { + if (this.data.length) { + while (this.data.length > 1) { + this.helper.push(this.data.pop()); + } + let res = this.data.pop(); + while (this.helper.length) { + this.data.push(this.helper.pop()); } -}; \ No newline at end of file + return res; + } else { + return -1; + } +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" index 78a18ad3fb371..93dd56478726a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" @@ -1,6 +1,7 @@ -# [面试题10- I. 斐波那契数列](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) +# [面试题 10- I. 斐波那契数列](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) ## 题目描述 + 写一个函数,输入 `n` ,求斐波那契(Fibonacci)数列的第 `n` 项。斐波那契数列的定义如下: ``` @@ -31,11 +32,13 @@ F(N) = F(N - 1) + F(N - 2), 其中 N > 1. - `0 <= n <= 100` ## 解法 + 递推求解。 ### **Python3** + ```python class Solution: def fib(self, n: int) -> int: @@ -46,6 +49,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int fib(int n) { @@ -61,26 +65,25 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var fib = function(n) { - if(!n) return 0 - let pre = 0 - let cur = 1 - for(let i=2;i<=n;i++) { - let c = (pre + cur)%(1e9+7) - pre = cur - cur = c - } - return cur +var fib = function (n) { + if (!n) return 0; + let pre = 0; + let cur = 1; + for (let i = 2; i <= n; i++) { + let c = (pre + cur) % (1e9 + 7); + pre = cur; + cur = c; + } + return cur; }; ``` - - ### **Go** ```go @@ -98,14 +101,10 @@ func fib(n int) int { } ``` - - - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" index 0b7822ed4593a..c1341428be0c6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" @@ -2,14 +2,14 @@ * @param {number} n * @return {number} */ -var fib = function(n) { - if(!n) return 0 - let pre = 0 - let cur = 1 - for(let i=2;i<=n;i++) { - let c = (pre + cur)%(1e9+7) - pre = cur - cur = c - } - return cur -}; \ No newline at end of file +var fib = function (n) { + if (!n) return 0; + let pre = 0; + let cur = 1; + for (let i = 2; i <= n; i++) { + let c = (pre + cur) % (1e9 + 7); + pre = cur; + cur = c; + } + return cur; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" index 5fea256e5c22f..cb594638a63c6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" @@ -1,7 +1,8 @@ -# [面试题10- II. 青蛙跳台阶问题](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) +# [面试题 10- II. 青蛙跳台阶问题](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) ## 题目描述 -一只青蛙一次可以跳上 1 级台阶,也可以跳上 2 级台阶。求该青蛙跳上一个 `n` 级的台阶总共有多少种跳法。 + +一只青蛙一次可以跳上 1 级台阶,也可以跳上 2 级台阶。求该青蛙跳上一个 `n`  级的台阶总共有多少种跳法。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 @@ -23,14 +24,14 @@ - `0 <= n <= 100` - ## 解法 -青蛙想上第 `n` 级台阶,可从第 `n-1` 级台阶跳一级上去,也可从第 `n-2` 级台阶跳两级上去,即:`f(n) = f(n-1) + f(n-2)`。递推求解即可。 +青蛙想上第 `n` 级台阶,可从第 `n-1` 级台阶跳一级上去,也可从第 `n-2` 级台阶跳两级上去,即:`f(n) = f(n-1) + f(n-2)`。递推求解即可。 ### **Python3** + ```python class Solution: def numWays(self, n: int) -> int: @@ -41,6 +42,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int numWays(int n) { @@ -56,26 +58,25 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var numWays = function(n) { - if(!n) return 1 - let pre = 1 - let cur = 1 - for(let i=2;i<=n;i++) { - let c = (pre + cur) % (1e9 + 7) - pre = cur - cur = c - } - return cur +var numWays = function (n) { + if (!n) return 1; + let pre = 1; + let cur = 1; + for (let i = 2; i <= n; i++) { + let c = (pre + cur) % (1e9 + 7); + pre = cur; + cur = c; + } + return cur; }; ``` - - ### **Go** ```go @@ -96,12 +97,10 @@ func numWays(n int) int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" index 4d1b07d839035..c4be775bb0980 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" @@ -2,14 +2,14 @@ * @param {number} n * @return {number} */ -var numWays = function(n) { - if(!n) return 1 - let pre = 1 - let cur = 1 - for(let i=2;i<=n;i++) { - let c = (pre + cur) % (1e9 + 7) - pre = cur - cur = c - } - return cur -}; \ No newline at end of file +var numWays = function (n) { + if (!n) return 1; + let pre = 1; + let cur = 1; + for (let i = 2; i <= n; i++) { + let c = (pre + cur) % (1e9 + 7); + pre = cur; + cur = c; + } + return cur; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" index 76f18b6526bb5..ce66ddf9e12f1 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" @@ -1,7 +1,8 @@ -# [面试题11. 旋转数组的最小数字](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) +# [面试题 11. 旋转数组的最小数字](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) ## 题目描述 -把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如,数组 `[3,4,5,1,2]` 为 `[1,2,3,4,5]` 的一个旋转,该数组的最小值为 1。   + +把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如,数组  `[3,4,5,1,2]` 为 `[1,2,3,4,5]` 的一个旋转,该数组的最小值为 1。 **示例 1:** @@ -18,9 +19,11 @@ ``` ## 解法 + ### **Python3** + ```python class Solution: def minArray(self, numbers: List[int]) -> int: @@ -39,6 +42,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int minArray(int[] numbers) { @@ -75,26 +79,27 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} numbers * @return {number} */ -var minArray = function(numbers) { - // return Math.min(...numbers) - let left = 0 - let right = numbers.length-1 - while(left < right) { - let mid = left + ~~((right - left)/2) - if(numbers[mid] > numbers[right]) { - left = mid + 1 - } else if(numbers[mid] === numbers[right]) { - right-- - } else { - right = mid - } +var minArray = function (numbers) { + // return Math.min(...numbers) + let left = 0; + let right = numbers.length - 1; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (numbers[mid] > numbers[right]) { + left = mid + 1; + } else if (numbers[mid] === numbers[right]) { + right--; + } else { + right = mid; } - return numbers[left] + } + return numbers[left]; }; ``` @@ -117,14 +122,10 @@ func minArray(nums []int) int { } ``` - - - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/Solution.js" index 8065ce8b2efc8..217e51167e363 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/Solution.js" @@ -2,19 +2,19 @@ * @param {number[]} numbers * @return {number} */ -var minArray = function(numbers) { - // return Math.min(...numbers) - let left = 0 - let right = numbers.length-1 - while(left < right) { - let mid = left + ~~((right - left)/2) - if(numbers[mid] > numbers[right]) { - left = mid + 1 - } else if(numbers[mid] === numbers[right]) { - right-- - } else { - right = mid - } +var minArray = function (numbers) { + // return Math.min(...numbers) + let left = 0; + let right = numbers.length - 1; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (numbers[mid] > numbers[right]) { + left = mid + 1; + } else if (numbers[mid] === numbers[right]) { + right--; + } else { + right = mid; } - return numbers[left] -}; \ No newline at end of file + } + return numbers[left]; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" index 1d7d7bd3c51be..ed9b2e3580f61 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" @@ -1,7 +1,8 @@ -# [面试题12. 矩阵中的路径](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) +# [面试题 12. 矩阵中的路径](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) ## 题目描述 -请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一格开始,每一步可以在矩阵中向左、右、上、下移动一格。如果一条路径经过了矩阵的某一格,那么该路径不能再次进入该格子。例如,在下面的3×4的矩阵中包含一条字符串“bfce”的路径(路径中的字母用加粗标出)。 + +请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一格开始,每一步可以在矩阵中向左、右、上、下移动一格。如果一条路径经过了矩阵的某一格,那么该路径不能再次进入该格子。例如,在下面的 3×4 的矩阵中包含一条字符串“bfce”的路径(路径中的字母用加粗标出)。 ``` [["a","b","c","e"], @@ -11,7 +12,6 @@ 但矩阵中不包含字符串“abfb”的路径,因为字符串的第一个字符 b 占据了矩阵中的第一行第二个格子之后,路径不能再次进入这个格子。 - **示例 1:** ``` @@ -32,9 +32,11 @@ - `1 <= board[i].length <= 200` ## 解法 + ### **Python3** + ```python class Solution: def exist(self, board: List[List[str]], word: str) -> bool: @@ -47,7 +49,7 @@ class Solution: if self.visit(board, visited, i, j, rows, cols, word): return True return False - + def visit(self, board, visited, i, j, rows, cols, word) -> bool: if not word: return True @@ -60,6 +62,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public boolean exist(char[][] board, String word) { @@ -100,43 +103,52 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {character[][]} board * @param {string} word * @return {boolean} */ -var exist = function(board, word) { - let row = board.length - let col = board[0].length - let res = false - let isRead = [...new Array(row)].map(()=>Array(col).fill(0)) - for(let i=0;i Array(col).fill(0)); + for (let i = 0; i < row; i++) { + for (let j = 0; j < col; j++) { + if (res) break; + if (board[i][j] === word[0]) { + dfs(i, j, word); + } } - function dfs(i,j,word) { - if(i < 0 || j < 0 || i >= row || j >= col || res || isRead[i][j] || board[i][j] !== word[0]) { - return - } - isRead[i][j] = 1 - word = word.substring(1) - if(word.length) { - dfs(i-1,j,word) - dfs(i+1,j,word) - dfs(i,j-1,word) - dfs(i,j+1,word) - } else { - res = true - return - } - isRead[i][j] = 0 + } + function dfs(i, j, word) { + if ( + i < 0 || + j < 0 || + i >= row || + j >= col || + res || + isRead[i][j] || + board[i][j] !== word[0] + ) { + return; } - return res + isRead[i][j] = 1; + word = word.substring(1); + if (word.length) { + dfs(i - 1, j, word); + dfs(i + 1, j, word); + dfs(i, j - 1, word); + dfs(i, j + 1, word); + } else { + res = true; + return; + } + isRead[i][j] = 0; + } + return res; }; ``` @@ -181,12 +193,10 @@ func bfs(board [][]byte, i, j int, isVisited [][]bool, word string, index int) b } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" index 0be1068eb59b3..2dfdb071543ba 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" @@ -3,35 +3,43 @@ * @param {string} word * @return {boolean} */ -var exist = function(board, word) { - let row = board.length - let col = board[0].length - let res = false - let isRead = [...new Array(row)].map(()=>Array(col).fill(0)) - for(let i=0;i Array(col).fill(0)); + for (let i = 0; i < row; i++) { + for (let j = 0; j < col; j++) { + if (res) break; + if (board[i][j] === word[0]) { + dfs(i, j, word); + } } - function dfs(i,j,word) { - if(i < 0 || j < 0 || i >= row || j >= col || res || isRead[i][j] || board[i][j] !== word[0]) { - return - } - isRead[i][j] = 1 - word = word.substring(1) - if(word.length) { - dfs(i-1,j,word) - dfs(i+1,j,word) - dfs(i,j-1,word) - dfs(i,j+1,word) - } else { - res = true - return - } - isRead[i][j] = 0 + } + function dfs(i, j, word) { + if ( + i < 0 || + j < 0 || + i >= row || + j >= col || + res || + isRead[i][j] || + board[i][j] !== word[0] + ) { + return; } - return res -}; \ No newline at end of file + isRead[i][j] = 1; + word = word.substring(1); + if (word.length) { + dfs(i - 1, j, word); + dfs(i + 1, j, word); + dfs(i, j - 1, word); + dfs(i, j + 1, word); + } else { + res = true; + return; + } + isRead[i][j] = 0; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" index 007213876c0f8..a39c48a8a0087 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" @@ -1,7 +1,8 @@ -# [面试题13. 机器人的运动范围](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) +# [面试题 13. 机器人的运动范围](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) ## 题目描述 -地上有一个m行n列的方格,从坐标 `[0,0]` 到坐标 `[m-1,n-1]` 。一个机器人从坐标 `[0, 0]` 的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于k的格子。例如,当k为18时,机器人能够进入方格 `[35, 37]` ,因为 3+5+3+7=18。但它不能进入方格 `[35, 38]`,因为 3+5+3+8=19。请问该机器人能够到达多少个格子? + +地上有一个 m 行 n 列的方格,从坐标 `[0,0]` 到坐标 `[m-1,n-1]` 。一个机器人从坐标 `[0, 0]` 的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于 k 的格子。例如,当 k 为 18 时,机器人能够进入方格 `[35, 37]` ,因为 3+5+3+7=18。但它不能进入方格 `[35, 38]`,因为 3+5+3+8=19。请问该机器人能够到达多少个格子? **示例 1:** @@ -20,12 +21,14 @@ **提示:** - `1 <= n,m <= 100` -- `0 <= k <= 20` +- `0 <= k <= 20` ## 解法 + ### **Python3** + ```python class Solution: @@ -37,7 +40,7 @@ class Solution: visited = [[False for j in range(n)] for i in range(m)] self.visit(0, 0, m, n, k, visited) return self._cnt - + def visit(self, i, j, m, n, k, visited): if i < 0 or i >= m or j < 0 or j >= n or visited[i][j] or self.cal(i, j) > k: return @@ -54,6 +57,7 @@ class Solution: ``` ### **Java** + ```java class Solution { private int cnt; @@ -94,6 +98,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} m @@ -101,31 +106,51 @@ class Solution { * @param {number} k * @return {number} */ -var movingCount = function(m, n, k) { - let res = 0 - let isRead = [...new Array(m)].map(()=>Array(n).fill(0)) - let moving = [[0,-1],[0,1],[1,0],[-1,0]] - let queue = [[0,0]] - isRead[0][0] = 1 - while(queue.length) { - let [x,y] = queue.shift() - for(let [dx,dy] of moving) { - let X = x + dx - let Y = y + dy - if(X >= 0 && Y >= 0 && X < m && Y < n && !isRead[X][Y] && isValid(X,Y)) { - queue.push([X,Y]) - isRead[X][Y] = 1 - } - } - res++ - } - function isValid(x,y) { - let r = 0 - r += x.toString().split('').reduce((acc,cur)=>acc+ +cur,0) + y.toString().split('').reduce((acc,cur)=>acc+ +cur,0) - if(r <= k) return true - else return false +var movingCount = function (m, n, k) { + let res = 0; + let isRead = [...new Array(m)].map(() => Array(n).fill(0)); + let moving = [ + [0, -1], + [0, 1], + [1, 0], + [-1, 0], + ]; + let queue = [[0, 0]]; + isRead[0][0] = 1; + while (queue.length) { + let [x, y] = queue.shift(); + for (let [dx, dy] of moving) { + let X = x + dx; + let Y = y + dy; + if ( + X >= 0 && + Y >= 0 && + X < m && + Y < n && + !isRead[X][Y] && + isValid(X, Y) + ) { + queue.push([X, Y]); + isRead[X][Y] = 1; + } } - return res + res++; + } + function isValid(x, y) { + let r = 0; + r += + x + .toString() + .split("") + .reduce((acc, cur) => acc + +cur, 0) + + y + .toString() + .split("") + .reduce((acc, cur) => acc + +cur, 0); + if (r <= k) return true; + else return false; + } + return res; }; ``` @@ -150,12 +175,10 @@ func dfs(x, y, m, n, k int, visited [][]bool) int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" index e3e2f110a43e7..1782cbf01d1a8 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" @@ -4,29 +4,49 @@ * @param {number} k * @return {number} */ -var movingCount = function(m, n, k) { - let res = 0 - let isRead = [...new Array(m)].map(()=>Array(n).fill(0)) - let moving = [[0,-1],[0,1],[1,0],[-1,0]] - let queue = [[0,0]] - isRead[0][0] = 1 - while(queue.length) { - let [x,y] = queue.shift() - for(let [dx,dy] of moving) { - let X = x + dx - let Y = y + dy - if(X >= 0 && Y >= 0 && X < m && Y < n && !isRead[X][Y] && isValid(X,Y)) { - queue.push([X,Y]) - isRead[X][Y] = 1 - } - } - res++ +var movingCount = function (m, n, k) { + let res = 0; + let isRead = [...new Array(m)].map(() => Array(n).fill(0)); + let moving = [ + [0, -1], + [0, 1], + [1, 0], + [-1, 0], + ]; + let queue = [[0, 0]]; + isRead[0][0] = 1; + while (queue.length) { + let [x, y] = queue.shift(); + for (let [dx, dy] of moving) { + let X = x + dx; + let Y = y + dy; + if ( + X >= 0 && + Y >= 0 && + X < m && + Y < n && + !isRead[X][Y] && + isValid(X, Y) + ) { + queue.push([X, Y]); + isRead[X][Y] = 1; + } } - function isValid(x,y) { - let r = 0 - r += x.toString().split('').reduce((acc,cur)=>acc+ +cur,0) + y.toString().split('').reduce((acc,cur)=>acc+ +cur,0) - if(r <= k) return true - else return false - } - return res -}; \ No newline at end of file + res++; + } + function isValid(x, y) { + let r = 0; + r += + x + .toString() + .split("") + .reduce((acc, cur) => acc + +cur, 0) + + y + .toString() + .split("") + .reduce((acc, cur) => acc + +cur, 0); + if (r <= k) return true; + else return false; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" index 481d75c8911d8..cb52a49166838 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" @@ -1,16 +1,18 @@ -# [面试题14- I. 剪绳子](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) +# [面试题 14- I. 剪绳子](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) ## 题目描述 -给你一根长度为 `n` 的绳子,请把绳子剪成整数长度的 `m` 段(m、n 都是整数,n>1 并且 m>1),每段绳子的长度记为 `k[0],k[1]...k[m-1]` 。请问 `k[0]*k[1]*...*k[m-1]` 可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为 2、3、3 的三段,此时得到的最大乘积是 18。 + +给你一根长度为 `n` 的绳子,请把绳子剪成整数长度的 `m` 段(m、n 都是整数,n>1 并且 m>1),每段绳子的长度记为 `k[0],k[1]...k[m-1]` 。请问 `k[0]*k[1]*...*k[m-1]` 可能的最大乘积是多少?例如,当绳子的长度是 8 时,我们把它剪成长度分别为 2、3、3 的三段,此时得到的最大乘积是 18。 **示例 1:** + ``` 输入: 2 输出: 1 解释: 2 = 1 + 1, 1 × 1 = 1 ``` -**示例 2:** +**示例  2:** ``` 输入: 10 @@ -23,9 +25,11 @@ - `2 <= n <= 58` ## 解法 + ### **Python3** + ```python class Solution: def cuttingRope(self, n: int) -> int: @@ -39,6 +43,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int cuttingRope(int n) { @@ -57,35 +62,34 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var cuttingRope = function(n) { - // 数学方法 - if(n <= 3) return n-1 - let a = ~~(n / 3) - let b = n % 3 - if(b === 1) { - return 3**(a-1) * 2 * 2 - } - if(b === 0) return 3**a - return 3**a * b - // dp 方法 - // let dp = new Array(n+1).fill(0) - // dp[0] = 1 - // for(let i=1;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" index 93a49f4508e28..0c3fff55fd89b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" @@ -2,23 +2,23 @@ * @param {number} n * @return {number} */ -var cuttingRope = function(n) { - // 数学方法 - if(n <= 3) return n-1 - let a = ~~(n / 3) - let b = n % 3 - if(b === 1) { - return 3**(a-1) * 2 * 2 - } - if(b === 0) return 3**a - return 3**a * b - // dp 方法 - // let dp = new Array(n+1).fill(0) - // dp[0] = 1 - // for(let i=1;i1 并且 m>1),每段绳子的长度记为 `k[0],k[1]...k[m-1]` 。请问 `k[0]*k[1]*...*k[m-1]` 可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为 2、3、3 的三段,此时得到的最大乘积是 18。 + +给你一根长度为 `n` 的绳子,请把绳子剪成整数长度的 `m` 段(m、n 都是整数,n>1 并且 m>1),每段绳子的长度记为 `k[0],k[1]...k[m-1]` 。请问 `k[0]*k[1]*...*k[m-1]` 可能的最大乘积是多少?例如,当绳子的长度是 8 时,我们把它剪成长度分别为 2、3、3 的三段,此时得到的最大乘积是 18。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 @@ -13,7 +14,7 @@ 解释: 2 = 1 + 1, 1 × 1 = 1 ``` -**示例 2:** +**示例  2:** ``` 输入: 10 @@ -26,9 +27,11 @@ - `2 <= n <= 1000` ## 解法 + ### **Python3** + ```python class Solution: def cuttingRope(self, n: int) -> int: @@ -42,6 +45,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int cuttingRope(int n) { @@ -65,28 +69,29 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var cuttingRope = function(n) { - if(n <= 3) return n-1 - let a = ~~(n / 3) - let b = n % 3 - const MOD = 1e9 + 7 - function myPow(x) { - let r = 1 - for(let i=0;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" index 1f989fa72436b..bb0dd1e17769b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" @@ -2,21 +2,21 @@ * @param {number} n * @return {number} */ -var cuttingRope = function(n) { - if(n <= 3) return n-1 - let a = ~~(n / 3) - let b = n % 3 - const MOD = 1e9 + 7 - function myPow(x) { - let r = 1 - for(let i=0;i ### **Python3** + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -44,6 +47,7 @@ class Solution: ``` ### **Java** + ```java public class Solution { // you need to treat n as an unsigned value @@ -59,18 +63,19 @@ public class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n - a positive integer * @return {number} */ -var hammingWeight = function(n) { - let cnt = 0 - while(n) { - cnt += n & 1 - n >>>= 1 - } - return cnt +var hammingWeight = function (n) { + let cnt = 0; + while (n) { + cnt += n & 1; + n >>>= 1; + } + return cnt; }; ``` @@ -88,12 +93,10 @@ func hammingWeight(num uint32) int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" index 430e3f32be185..8acf0349b6731 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" @@ -2,11 +2,11 @@ * @param {number} n - a positive integer * @return {number} */ -var hammingWeight = function(n) { - let cnt = 0 - while(n) { - cnt += n & 1 - n >>>= 1 - } - return cnt -}; \ No newline at end of file +var hammingWeight = function (n) { + let cnt = 0; + while (n) { + cnt += n & 1; + n >>>= 1; + } + return cnt; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" index ce8b0bd2b1c28..567a1a6a0b69d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" @@ -1,6 +1,7 @@ -# [面试题16. 数值的整数次方](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) +# [面试题 16. 数值的整数次方](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) ## 题目描述 + 实现函数 double Power(double base, int exponent),求 base 的 exponent 次方。不得使用库函数,同时不需要考虑大数问题。 **示例 1:** @@ -10,14 +11,14 @@ 输出: 1024.00000 ``` -**示例 2:** +**示例  2:** ``` 输入: 2.10000, 3 输出: 9.26100 ``` -**示例 3:** +**示例  3:** ``` 输入: 2.00000, -2 @@ -27,13 +28,15 @@ **说明:** -- `-100.0 < x < 100.0` -- n 是 32 位有符号整数,其数值范围是  `[−231, 231 − 1]` 。 +- `-100.0 < x < 100.0` +- n  是 32 位有符号整数,其数值范围是   `[−231, 231 − 1]` 。 ## 解法 + ### **Python3** + ```python class Solution: cache = {} @@ -54,6 +57,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public double myPow(double x, int n) { @@ -67,28 +71,29 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} x * @param {number} n * @return {number} */ -var myPow = function(x, n) { - let r = 1 - let tmp = x - let tag = 0 - if(n < 0) { - tag = 1 - n = -n +var myPow = function (x, n) { + let r = 1; + let tmp = x; + let tag = 0; + if (n < 0) { + tag = 1; + n = -n; + } + while (n) { + if (n & 1) { + r *= tmp; } - while(n) { - if(n & 1) { - r *= tmp - } - tmp *= tmp - n >>>= 1 - } - return tag ? 1/r : r + tmp *= tmp; + n >>>= 1; + } + return tag ? 1 / r : r; }; ``` @@ -101,9 +106,9 @@ func myPow(x float64, n int) float64 { for p != 0 { if p&1 == 1 { res *= x - } + } x *= x - p = p >>1 + p = p >>1 } if n < 0 { return 1/res @@ -120,12 +125,10 @@ func abs(x int) int { ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" index 546c5946ad56e..f80d273fe8cc5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" @@ -3,20 +3,20 @@ * @param {number} n * @return {number} */ -var myPow = function(x, n) { - let r = 1 - let tmp = x - let tag = 0 - if(n < 0) { - tag = 1 - n = -n +var myPow = function (x, n) { + let r = 1; + let tmp = x; + let tag = 0; + if (n < 0) { + tag = 1; + n = -n; + } + while (n) { + if (n & 1) { + r *= tmp; } - while(n) { - if(n & 1) { - r *= tmp - } - tmp *= tmp - n >>>= 1 - } - return tag ? 1/r : r -}; \ No newline at end of file + tmp *= tmp; + n >>>= 1; + } + return tag ? 1 / r : r; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" index dff0a6a45392b..723684a4dad29 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" @@ -1,6 +1,7 @@ -# [面试题17. 打印从1到最大的n位数](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) +# [面试题 17. 打印从 1 到最大的 n 位数](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) ## 题目描述 + 输入数字 `n`,按顺序打印出从 1 到最大的 n 位十进制数。比如输入 3,则打印出 1、2、3 一直到最大的 3 位数 999。 **示例 1:** @@ -16,9 +17,11 @@ - n 为正整数 ## 解法 + ### **Python3** + ```python class Solution: def printNumbers(self, n: int) -> List[int]: @@ -26,6 +29,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int[] printNumbers(int n) { @@ -40,17 +44,18 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number[]} */ -var printNumbers = function(n) { - let res = [] - for(let i=1;i<10**n;i++) { - res.push(i) - } - return res +var printNumbers = function (n) { + let res = []; + for (let i = 1; i < 10 ** n; i++) { + res.push(i); + } + return res; }; ``` @@ -70,12 +75,10 @@ func printNumbers(n int) []int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/Solution.js" index 7a7c367793b7c..93bec4c9cc2dc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/Solution.js" @@ -2,10 +2,10 @@ * @param {number} n * @return {number[]} */ -var printNumbers = function(n) { - let res = [] - for(let i=1;i<10**n;i++) { - res.push(i) - } - return res -}; \ No newline at end of file +var printNumbers = function (n) { + let res = []; + for (let i = 1; i < 10 ** n; i++) { + res.push(i); + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" index ac7bacc31e739..46d496d862b5d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" @@ -1,6 +1,7 @@ -# [面试题18. 删除链表的节点](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) +# [面试题 18. 删除链表的节点](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) ## 题目描述 + 给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。 返回删除后的链表的头节点。 @@ -37,6 +38,7 @@ ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -57,6 +59,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -85,6 +88,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for singly-linked list. @@ -98,21 +102,21 @@ class Solution { * @param {number} val * @return {ListNode} */ -var deleteNode = function(head, val) { - let node = head - if(node.val === val) { - node = node.next - head = node - } else { - while(node.next) { - if(node.next.val === val) { - node.next = node.next.next - break - } - node = node.next - } +var deleteNode = function (head, val) { + let node = head; + if (node.val === val) { + node = node.next; + head = node; + } else { + while (node.next) { + if (node.next.val === val) { + node.next = node.next.next; + break; + } + node = node.next; } - return head + } + return head; }; ``` @@ -138,12 +142,10 @@ func deleteNode(head *ListNode, val int) *ListNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" index a240bcaeefacf..351fc084f3ac2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" @@ -10,19 +10,19 @@ * @param {number} val * @return {ListNode} */ -var deleteNode = function(head, val) { - let node = head - if(node.val === val) { - node = node.next - head = node - } else { - while(node.next) { - if(node.next.val === val) { - node.next = node.next.next - break - } - node = node.next - } +var deleteNode = function (head, val) { + let node = head; + if (node.val === val) { + node = node.next; + head = node; + } else { + while (node.next) { + if (node.next.val === val) { + node.next = node.next.next; + break; + } + node = node.next; } - return head -}; \ No newline at end of file + } + return head; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" index d66b80c22b3ff..4e07285ab6710 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" @@ -1,7 +1,8 @@ -# [面试题19. 正则表达式匹配](https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof/) +# [面试题 19. 正则表达式匹配](https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof/) ## 题目描述 -请实现一个函数用来匹配包含`'. '`和`'*'`的正则表达式。模式中的字符`'.'`表示任意一个字符,而`'*'`表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串`"aaa"`与模式`"a.a"`和`"ab*ac*a"`匹配,但与`"aa.a"`和`"ab*a"`均不匹配。 + +请实现一个函数用来匹配包含`'. '`和`'*'`的正则表达式。模式中的字符`'.'`表示任意一个字符,而`'*'`表示它前面的字符可以出现任意次(含 0 次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串`"aaa"`与模式`"a.a"`和`"ab*ac*a"`匹配,但与`"aa.a"`和`"ab*a"`均不匹配。 **示例 1:** @@ -23,7 +24,7 @@ p = "a*" 解释: 因为 '*' 代表可以匹配零个或多个前面的那一个元素, 在这里前面的元素就是 'a'。因此,字符串 "aa" 可被视为 'a' 重复了一次。 ``` -**示例 3:** +**示例  3:** ``` 输入: @@ -52,24 +53,25 @@ p = "mis*is*p*." 输出: false ``` -- `s` 可能为空,且只包含从 `a-z` 的小写字母。 -- `p` 可能为空,且只包含从 `a-z` 的小写字母,以及字符 `.` 和 `*`。 - +- `s`  可能为空,且只包含从  `a-z`  的小写字母。 +- `p`  可能为空,且只包含从  `a-z`  的小写字母,以及字符  `.`  和  `*`。 ## 解法 + 动态规划法,`dp[i][j]` 表示 s 的前 i 项和 p 的前 j 项是否匹配。 现在如果已知了 `dp[i-1][j-1]` 的状态,我们该如何确定 `dp[i][j]` 的状态呢?我们可以分三种情况讨论,其中,前两种情况考虑了所有能匹配的情况,剩下的就是不能匹配的情况了: 1. `s[i] == p[j]` or `p[j] == '.'`:比如 ab**b** 和 ab**b**,或者 ab**b** 和 ab. ,很容易得到 `dp[i][j]` = `dp[i-1][j-1]` = True。因为 ab 和 ab 是匹配的,如果后面分别加一个 b,或者 s 加一个 b 而 p 加一个 `.` ,仍然是匹配的。 2. `p[j] == '*'`:当 `p[j] == '*'` 时,由于 `*` 与前面的字符相关,因此我们比较 `*` 前面的字符 `p[j-1]` 和 `s[i]` 的关系。根据 `*` 前面的字符与 s[i] 是否相等,又可分为以下两种情况: - - `p[j-1] != s[i]`:如果 `*` 前一个字符匹配不上,`*` 匹配了 0 次,应忽略这两个字符,看 `p[j-2]` 和 `s[i]` 是否匹配。 这时 `dp[i][j] = dp[i][j-2]`。 - - `p[j-1] == s[i]` or `p[j-1] == '.'`:`*` 前面的字符可以与 s[i] 匹配,这种情况下,`*` 可能匹配了前面的字符的 0 个,也可能匹配了前面字符的多个,当匹配 0 个时,如 `ab` 和 `abb*`,或者 `ab` 和 `ab.*` ,这时我们需要去掉 p 中的 `b*` 或 `.*` 后进行比较,即 `dp[i][j] = dp[i][j-2]`;当匹配多个时,如 `abbb` 和 `ab*`,或者 `abbb` 和 `a.*`,我们需要将 s[i] 前面的与 p 重新比较,即 `dp[i][j] = dp[i-1][j]`。 + - `p[j-1] != s[i]`:如果 `*` 前一个字符匹配不上,`*` 匹配了 0 次,应忽略这两个字符,看 `p[j-2]` 和 `s[i]` 是否匹配。 这时 `dp[i][j] = dp[i][j-2]`。 + - `p[j-1] == s[i]` or `p[j-1] == '.'`:`*` 前面的字符可以与 s[i] 匹配,这种情况下,`*` 可能匹配了前面的字符的 0 个,也可能匹配了前面字符的多个,当匹配 0 个时,如 `ab` 和 `abb*`,或者 `ab` 和 `ab.*` ,这时我们需要去掉 p 中的 `b*` 或 `.*` 后进行比较,即 `dp[i][j] = dp[i][j-2]`;当匹配多个时,如 `abbb` 和 `ab*`,或者 `abbb` 和 `a.*`,我们需要将 s[i] 前面的与 p 重新比较,即 `dp[i][j] = dp[i-1][j]`。 3. 其他情况:以上两种情况把能匹配的都考虑全面了,所以其他情况为不匹配,即 `dp[i][j] = False`。 ### **Python3** + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -97,6 +99,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public boolean isMatch(String s, String p) { @@ -133,35 +136,37 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @param {string} p * @return {boolean} */ -var isMatch = function(s, p) { - // 回溯大法好 - let memo = {} - function recursive(i,j) { - if(memo[[i,j]] !== undefined) return memo[[i,j]] - if(j === p.length) return i === s.length - let tmp = i < s.length && (s[i] === p[j] || p[j] === '.') - let ans = false - if(p[j+1] === '*') { - ans = recursive(i,j+2) || tmp && recursive(i+1,j) - } else { - ans = tmp && recursive(i+1,j+1) - } - memo[[i,j]] = ans - return ans +var isMatch = function (s, p) { + // 回溯大法好 + let memo = {}; + function recursive(i, j) { + if (memo[[i, j]] !== undefined) return memo[[i, j]]; + if (j === p.length) return i === s.length; + let tmp = i < s.length && (s[i] === p[j] || p[j] === "."); + let ans = false; + if (p[j + 1] === "*") { + ans = recursive(i, j + 2) || (tmp && recursive(i + 1, j)); + } else { + ans = tmp && recursive(i + 1, j + 1); } - return recursive(0,0) + memo[[i, j]] = ans; + return ans; + } + return recursive(0, 0); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.js" index 734eab92de1c4..1e9abb2603f7b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.js" @@ -3,21 +3,21 @@ * @param {string} p * @return {boolean} */ -var isMatch = function(s, p) { - // 回溯大法好 - let memo = {} - function recursive(i,j) { - if(memo[[i,j]] !== undefined) return memo[[i,j]] - if(j === p.length) return i === s.length - let tmp = i < s.length && (s[i] === p[j] || p[j] === '.') - let ans = false - if(p[j+1] === '*') { - ans = recursive(i,j+2) || tmp && recursive(i+1,j) - } else { - ans = tmp && recursive(i+1,j+1) - } - memo[[i,j]] = ans - return ans +var isMatch = function (s, p) { + // 回溯大法好 + let memo = {}; + function recursive(i, j) { + if (memo[[i, j]] !== undefined) return memo[[i, j]]; + if (j === p.length) return i === s.length; + let tmp = i < s.length && (s[i] === p[j] || p[j] === "."); + let ans = false; + if (p[j + 1] === "*") { + ans = recursive(i, j + 2) || (tmp && recursive(i + 1, j)); + } else { + ans = tmp && recursive(i + 1, j + 1); } - return recursive(0,0) -}; \ No newline at end of file + memo[[i, j]] = ans; + return ans; + } + return recursive(0, 0); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" index 7f381c75f659b..84c627a4ad05e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" @@ -1,13 +1,17 @@ -# [面试题20. 表示数值的字符串](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/) +# [面试题 20. 表示数值的字符串](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/) ## 题目描述 + + 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100"、"5e2"、"-123"、"3.1416"、"0123"及"-1E-16"都表示数值,但"12e"、"1a3.14"、"1.2.3"、"+-5"及"12e+5.4"都不是。 注意:本题与主站 65 题相同:https://leetcode-cn.com/problems/valid-number/ ## 解法 + + 遍历字符串: - 出现 `+`/`-` 时,位置必须是在第 0 位,或者 `e`/`E` 的后面一位 @@ -17,6 +21,7 @@ ### **Python3** + ```python @@ -47,6 +52,7 @@ class Solution: ``` ### **Java** + ```java @@ -87,19 +93,21 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @return {boolean} */ -var isNumber = function(s) { - return s !== ' ' && !isNaN(+s) +var isNumber = function (s) { + return s !== " " && !isNaN(+s); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" index 1aa939067f7b4..905f6a8d20ce4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" @@ -2,6 +2,6 @@ * @param {string} s * @return {boolean} */ -var isNumber = function(s) { - return s !== ' ' && !isNaN(+s) -}; \ No newline at end of file +var isNumber = function (s) { + return s !== " " && !isNaN(+s); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" index 1f0958363056c..12a04a241256d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" @@ -1,13 +1,14 @@ -# [面试题21. 调整数组顺序使奇数位于偶数前面](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) +# [面试题 21. 调整数组顺序使奇数位于偶数前面](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) ## 题目描述 + 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。 **示例:** ``` 输入:nums = [1,2,3,4] -输出:[1,3,2,4] +输出:[1,3,2,4] 注:[3,1,2,4] 也是正确的答案之一。 ``` @@ -17,9 +18,11 @@ - 1 <= nums[i] <= 10000 ## 解法 + ### **Python3** + ```python class Solution: def exchange(self, nums: List[int]) -> List[int]: @@ -36,6 +39,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int[] exchange(int[] nums) { @@ -55,32 +59,34 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number[]} */ -var exchange = function(nums) { - let left = 0 - let right = nums.length-1 - while(left < right) { - let c = nums[left] - nums[left] = nums[right] - nums[right] = c - while(nums[left]%2) { - left++ - } - while(nums[right]%2===0) { - right-- - } +var exchange = function (nums) { + let left = 0; + let right = nums.length - 1; + while (left < right) { + let c = nums[left]; + nums[left] = nums[right]; + nums[right] = c; + while (nums[left] % 2) { + left++; } - return nums + while (nums[right] % 2 === 0) { + right--; + } + } + return nums; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/Solution.js" index 041d5d3865c22..5a359aeb34c3a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/Solution.js" @@ -2,19 +2,19 @@ * @param {number[]} nums * @return {number[]} */ -var exchange = function(nums) { - let left = 0 - let right = nums.length-1 - while(left < right) { - let c = nums[left] - nums[left] = nums[right] - nums[right] = c - while(nums[left]%2) { - left++ - } - while(nums[right]%2===0) { - right-- - } +var exchange = function (nums) { + let left = 0; + let right = nums.length - 1; + while (left < right) { + let c = nums[left]; + nums[left] = nums[right]; + nums[right] = c; + while (nums[left] % 2) { + left++; } - return nums -}; \ No newline at end of file + while (nums[right] % 2 === 0) { + right--; + } + } + return nums; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" index 29c4636714dc5..0971a56616a34 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" @@ -1,8 +1,8 @@ -# [面试题22. 链表中倒数第k个节点](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) +# [面试题 22. 链表中倒数第 k 个节点](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) ## 题目描述 -输入一个链表,输出该链表中倒数第 k 个节点。为了符合大多数人的习惯,本题从 1 开始计数,即链表的尾节点是倒数第 1 个节点。例如,一个链表有 6 个节点,从头节点开始,它们的值依次是 1、2、3、4、5、6。这个链表的倒数第 3 个节点是值为 4 的节点。 +输入一个链表,输出该链表中倒数第 k 个节点。为了符合大多数人的习惯,本题从 1 开始计数,即链表的尾节点是倒数第 1 个节点。例如,一个链表有 6 个节点,从头节点开始,它们的值依次是 1、2、3、4、5、6。这个链表的倒数第 3 个节点是值为 4 的节点。 **示例:** @@ -19,6 +19,7 @@ ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -30,7 +31,7 @@ class Solution: def getKthFromEnd(self, head: ListNode, k: int) -> ListNode: if not (head or head.next): return head - + p = q = head for _ in range(k): p = p.next @@ -42,6 +43,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -70,36 +72,37 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {ListNode} head * @param {number} k * @return {ListNode} */ -var getKthFromEnd = function(head, k) { - // 递归 - // let cnt = 1 - // function func(node) { - // if(!node || !node.next) return node - // let newNode = func(node.next) - // if(cnt === k) return newNode - // else cnt++ - // return node - // } - // return func(head) - - // 快慢指针 - let slow = head - let fast = head - while(k) { - fast = fast.next - k-- - } - while(fast) { - slow = slow.next - fast = fast.next - } - return slow +var getKthFromEnd = function (head, k) { + // 递归 + // let cnt = 1 + // function func(node) { + // if(!node || !node.next) return node + // let newNode = func(node.next) + // if(cnt === k) return newNode + // else cnt++ + // return node + // } + // return func(head) + + // 快慢指针 + let slow = head; + let fast = head; + while (k) { + fast = fast.next; + k--; + } + while (fast) { + slow = slow.next; + fast = fast.next; + } + return slow; }; ``` @@ -122,12 +125,10 @@ func getKthFromEnd(head *ListNode, k int) *ListNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/Solution.js" index 4cda330163a80..b27a23fc8cbaf 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/Solution.js" @@ -3,28 +3,28 @@ * @param {number} k * @return {ListNode} */ -var getKthFromEnd = function(head, k) { - // 递归 - // let cnt = 1 - // function func(node) { - // if(!node || !node.next) return node - // let newNode = func(node.next) - // if(cnt === k) return newNode - // else cnt++ - // return node - // } - // return func(head) +var getKthFromEnd = function (head, k) { + // 递归 + // let cnt = 1 + // function func(node) { + // if(!node || !node.next) return node + // let newNode = func(node.next) + // if(cnt === k) return newNode + // else cnt++ + // return node + // } + // return func(head) - // 快慢指针 - let slow = head - let fast = head - while(k) { - fast = fast.next - k-- - } - while(fast) { - slow = slow.next - fast = fast.next - } - return slow -}; \ No newline at end of file + // 快慢指针 + let slow = head; + let fast = head; + while (k) { + fast = fast.next; + k--; + } + while (fast) { + slow = slow.next; + fast = fast.next; + } + return slow; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" index 77591d310ee8c..8e78c4fdb0c39 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" @@ -1,9 +1,11 @@ -# [面试题24. 反转链表](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) +# [面试题 24. 反转链表](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) ## 题目描述 + 定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 **示例:** + ``` 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL @@ -21,10 +23,10 @@ 当遍历结束后,返回 `pre` 指针即可。 - ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -44,6 +46,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -69,6 +72,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for singly-linked list. @@ -81,16 +85,16 @@ class Solution { * @param {ListNode} head * @return {ListNode} */ -var reverseList = function(head) { - let node = head - let pre = null - while(node) { - let cur = node - node = cur.next - cur.next = pre - pre = cur - } - return pre +var reverseList = function (head) { + let node = head; + let pre = null; + while (node) { + let cur = node; + node = cur.next; + cur.next = pre; + pre = cur; + } + return pre; }; ``` @@ -113,12 +117,10 @@ func reverseList(head *ListNode) *ListNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" index 174b7ed781f80..19d396c343ed4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" @@ -9,14 +9,14 @@ * @param {ListNode} head * @return {ListNode} */ -var reverseList = function(head) { - let node = head - let pre = null - while(node) { - let cur = node - node = cur.next - cur.next = pre - pre = cur - } - return pre -}; \ No newline at end of file +var reverseList = function (head) { + let node = head; + let pre = null; + while (node) { + let cur = node; + node = cur.next; + cur.next = pre; + pre = cur; + } + return pre; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" index 0283da4b49da9..90b9e9873f8ca 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" @@ -1,9 +1,10 @@ -# [面试题25. 合并两个排序的链表](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) +# [面试题 25. 合并两个排序的链表](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) ## 题目描述 + 输入两个递增排序的链表,合并这两个链表并使新链表中的节点仍然是递增排序的。 -**示例1:** +**示例 1:** ``` 输入:1->2->4, 1->3->4 @@ -21,6 +22,7 @@ ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -51,6 +53,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -91,6 +94,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for singly-linked list. @@ -104,40 +108,40 @@ class Solution { * @param {ListNode} l2 * @return {ListNode} */ -var mergeTwoLists = function(l1, l2) { - // 法一 - 递归 - if (!l1) return l2 - if (!l2) return l1 - if (l1.val < l2.val) { - l1.next = mergeTwoLists(l1.next, l2) - return l1 - } else { - l2.next = mergeTwoLists(l2.next, l1) - return l2 - } - // 法二 - 遍历 - // if(!l1 || !l2) return l1 ? l1 : l2 - // let a = l1 - // let b = l2 - // let res = l1 - // if(a.val > b.val) { - // let c = a - // a = b - // b = c - // res = l2 - // } - // while(a && b) { - // while(a.next && a.next.val < b.val) { - // a = a.next - // } - // let tmp = a.next - // let rec = b.next - // a.next = b - // a.next.next = tmp - // a = a.next - // b = rec - // } - // return res +var mergeTwoLists = function (l1, l2) { + // 法一 - 递归 + if (!l1) return l2; + if (!l2) return l1; + if (l1.val < l2.val) { + l1.next = mergeTwoLists(l1.next, l2); + return l1; + } else { + l2.next = mergeTwoLists(l2.next, l1); + return l2; + } + // 法二 - 遍历 + // if(!l1 || !l2) return l1 ? l1 : l2 + // let a = l1 + // let b = l2 + // let res = l1 + // if(a.val > b.val) { + // let c = a + // a = b + // b = c + // res = l2 + // } + // while(a && b) { + // while(a.next && a.next.val < b.val) { + // a = a.next + // } + // let tmp = a.next + // let rec = b.next + // a.next = b + // a.next.next = tmp + // a = a.next + // b = rec + // } + // return res }; ``` @@ -160,12 +164,10 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.js" index ddfb6a5343c94..2e75798caacfc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.js" @@ -10,38 +10,38 @@ * @param {ListNode} l2 * @return {ListNode} */ -var mergeTwoLists = function(l1, l2) { - // 法一 - 递归 - if (!l1) return l2 - if (!l2) return l1 - if (l1.val < l2.val) { - l1.next = mergeTwoLists(l1.next, l2) - return l1 - } else { - l2.next = mergeTwoLists(l2.next, l1) - return l2 - } - // 法二 - 遍历 - // if(!l1 || !l2) return l1 ? l1 : l2 - // let a = l1 - // let b = l2 - // let res = l1 - // if(a.val > b.val) { - // let c = a - // a = b - // b = c - // res = l2 - // } - // while(a && b) { - // while(a.next && a.next.val < b.val) { - // a = a.next - // } - // let tmp = a.next - // let rec = b.next - // a.next = b - // a.next.next = tmp - // a = a.next - // b = rec - // } - // return res -}; \ No newline at end of file +var mergeTwoLists = function (l1, l2) { + // 法一 - 递归 + if (!l1) return l2; + if (!l2) return l1; + if (l1.val < l2.val) { + l1.next = mergeTwoLists(l1.next, l2); + return l1; + } else { + l2.next = mergeTwoLists(l2.next, l1); + return l2; + } + // 法二 - 遍历 + // if(!l1 || !l2) return l1 ? l1 : l2 + // let a = l1 + // let b = l2 + // let res = l1 + // if(a.val > b.val) { + // let c = a + // a = b + // b = c + // res = l2 + // } + // while(a && b) { + // while(a.next && a.next.val < b.val) { + // a = a.next + // } + // let tmp = a.next + // let rec = b.next + // a.next = b + // a.next.next = tmp + // a = a.next + // b = rec + // } + // return res +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" index 9535ec0d179dc..c7c9ad75cace5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" @@ -1,7 +1,8 @@ -# [面试题26. 树的子结构](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) +# [面试题 26. 树的子结构](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) ## 题目描述 -输入两棵二叉树 A 和 B,判断 B 是不是 A W的子结构。(约定空树不是任意一个树的子结构) + +输入两棵二叉树 A 和 B,判断 B 是不是 A W 的子结构。(约定空树不是任意一个树的子结构) B 是 A 的子结构, 即 A 中有出现和 B 相同的结构和节点值。 @@ -46,9 +47,11 @@ B 是 A 的子结构, 即 A 中有出现和 B 相同的结构和节点值。 - `0 <= 节点个数 <= 10000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +82,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -105,7 +109,7 @@ class Solution { return isSame(A, B) || sub(A.left, B) || sub(A.right, B); } return sub(A.left, B) || sub(A.right, B); - + } private boolean isSame(TreeNode A, TreeNode B) { @@ -121,6 +125,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -134,32 +139,32 @@ class Solution { * @param {TreeNode} B * @return {boolean} */ -var isSubStructure = function(A, B) { - if(!B || !A) return false - let res - function dfs(A,B,bool) { - if(!A || !B) { - if(B) { - return false - } else { - return true - } - } - if(A.val === B.val) { - let left = dfs(A.left,B.left,true) - let right = dfs(A.right,B.right,true) - if(left && right) return true - else return false - } else { - if(bool) return false - else { - let left = dfs(A.left,B,false) - let right = dfs(A.right,B,false) - return left || right - } - } +var isSubStructure = function (A, B) { + if (!B || !A) return false; + let res; + function dfs(A, B, bool) { + if (!A || !B) { + if (B) { + return false; + } else { + return true; + } + } + if (A.val === B.val) { + let left = dfs(A.left, B.left, true); + let right = dfs(A.right, B.right, true); + if (left && right) return true; + else return false; + } else { + if (bool) return false; + else { + let left = dfs(A.left, B, false); + let right = dfs(A.right, B, false); + return left || right; + } } - return dfs(A,B,false) || false + } + return dfs(A, B, false) || false; }; ``` @@ -171,7 +176,7 @@ func isSubStructure(A *TreeNode, B *TreeNode) bool { if A == nil || B == nil { return false } - return helper(A,B) || isSubStructure(A.Left,B) || isSubStructure(A.Right,B) + return helper(A,B) || isSubStructure(A.Left,B) || isSubStructure(A.Right,B) } func helper(a *TreeNode, b *TreeNode) bool { @@ -185,12 +190,10 @@ func helper(a *TreeNode, b *TreeNode) bool { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" index 14497eff83d11..5b8f7b87ef971 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" @@ -10,30 +10,30 @@ * @param {TreeNode} B * @return {boolean} */ -var isSubStructure = function(A, B) { - if(!B || !A) return false - let res - function dfs(A,B,bool) { - if(!A || !B) { - if(B) { - return false - } else { - return true - } - } - if(A.val === B.val) { - let left = dfs(A.left,B.left,true) - let right = dfs(A.right,B.right,true) - if(left && right) return true - else return false - } else { - if(bool) return false - else { - let left = dfs(A.left,B,false) - let right = dfs(A.right,B,false) - return left || right - } - } +var isSubStructure = function (A, B) { + if (!B || !A) return false; + let res; + function dfs(A, B, bool) { + if (!A || !B) { + if (B) { + return false; + } else { + return true; + } } - return dfs(A,B,false) || false -}; \ No newline at end of file + if (A.val === B.val) { + let left = dfs(A.left, B.left, true); + let right = dfs(A.right, B.right, true); + if (left && right) return true; + else return false; + } else { + if (bool) return false; + else { + let left = dfs(A.left, B, false); + let right = dfs(A.right, B, false); + return left || right; + } + } + } + return dfs(A, B, false) || false; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" index ccc23fb68711d..1cae0f847d0cc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" @@ -1,6 +1,7 @@ -# [面试题27. 二叉树的镜像](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) +# [面试题 27. 二叉树的镜像](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) ## 题目描述 + 请完成一个函数,输入一个二叉树,该函数输出它的镜像。 例如输入: @@ -35,9 +36,11 @@ - `0 <= 节点个数 <= 1000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -50,7 +53,7 @@ class Solution: def mirrorTree(self, root: TreeNode) -> TreeNode: if root is None or (root.left is None and root.right is None): return root - + self.mirrorTree(root.left) self.mirrorTree(root.right) root.left, root.right = root.right, root.left @@ -58,6 +61,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -84,6 +88,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -96,16 +101,16 @@ class Solution { * @param {TreeNode} root * @return {TreeNode} */ -var mirrorTree = function(root) { - function dfs(node) { - if(!node) return null - let left = dfs(node.left) - let right = dfs(node.right) - node.left = right - node.right = left - return node - } - return dfs(root) +var mirrorTree = function (root) { + function dfs(node) { + if (!node) return null; + let left = dfs(node.left); + let right = dfs(node.right); + node.left = right; + node.right = left; + return node; + } + return dfs(root); }; ``` @@ -123,12 +128,10 @@ func mirrorTree(root *TreeNode) *TreeNode { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.js" index 658dce7b33f14..ae98a387c34ac 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.js" @@ -9,14 +9,14 @@ * @param {TreeNode} root * @return {TreeNode} */ -var mirrorTree = function(root) { - function dfs(node) { - if(!node) return null - let left = dfs(node.left) - let right = dfs(node.right) - node.left = right - node.right = left - return node - } - return dfs(root) -}; \ No newline at end of file +var mirrorTree = function (root) { + function dfs(node) { + if (!node) return null; + let left = dfs(node.left); + let right = dfs(node.right); + node.left = right; + node.right = left; + return node; + } + return dfs(root); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" index a43a3f4170983..73af090f9255e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" @@ -1,9 +1,10 @@ -# [面试题28. 对称的二叉树](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) +# [面试题 28. 对称的二叉树](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) ## 题目描述 + 请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 -例如,二叉树 `[1,2,2,3,4,4,3]` 是对称的。 +例如,二叉树  `[1,2,2,3,4,4,3]` 是对称的。 ```     1 @@ -13,7 +14,7 @@ 3  4 4  3 ``` -但是下面这个 `[1,2,2,null,3,null,3]` 则不是镜像对称的: +但是下面这个  `[1,2,2,null,3,null,3]` 则不是镜像对称的: ```     1 @@ -42,9 +43,11 @@ - `0 <= 节点个数 <= 1000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -58,7 +61,7 @@ class Solution: if root is None: return True return self.symmetric(root.left, root.right) - + def symmetric(self, node1, node2) -> bool: if node1 is None and node2 is None: return True @@ -68,6 +71,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -99,6 +103,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -111,14 +116,14 @@ class Solution { * @param {TreeNode} root * @return {boolean} */ -var isSymmetric = function(root) { - function dfs(a,b) { - if(!a && !b) return true - if(!a || !b) return false - return a.val === b.val && dfs(a.left,b.right) && dfs(a.right,b.left) - } - if(!root) return true - return dfs(root.left,root.right) +var isSymmetric = function (root) { + function dfs(a, b) { + if (!a && !b) return true; + if (!a || !b) return false; + return a.val === b.val && dfs(a.left, b.right) && dfs(a.right, b.left); + } + if (!root) return true; + return dfs(root.left, root.right); }; ``` @@ -146,12 +151,10 @@ func isSymme(a *TreeNode, b *TreeNode) bool { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/Solution.js" index 34de87681578e..aa4dbc2b00766 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/Solution.js" @@ -9,12 +9,12 @@ * @param {TreeNode} root * @return {boolean} */ -var isSymmetric = function(root) { - function dfs(a,b) { - if(!a && !b) return true - if(!a || !b) return false - return a.val === b.val && dfs(a.left,b.right) && dfs(a.right,b.left) - } - if(!root) return true - return dfs(root.left,root.right) -}; \ No newline at end of file +var isSymmetric = function (root) { + function dfs(a, b) { + if (!a && !b) return true; + if (!a || !b) return false; + return a.val === b.val && dfs(a.left, b.right) && dfs(a.right, b.left); + } + if (!root) return true; + return dfs(root.left, root.right); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" index 95f589ce100f4..13cc19cda6c15 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" @@ -1,6 +1,7 @@ -# [面试题29. 顺时针打印矩阵](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) +# [面试题 29. 顺时针打印矩阵](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) ## 题目描述 + 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。 **示例 1:** @@ -20,12 +21,14 @@ **限制:** - `0 <= matrix.length <= 100` -- `0 <= matrix[i].length <= 100` +- `0 <= matrix[i].length <= 100` ## 解法 + ### **Python3** + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -52,6 +55,7 @@ class Solution: ``` ### **Java** + ```java class Solution { private int index; @@ -100,46 +104,59 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[][]} matrix * @return {number[]} */ -var spiralOrder = function(matrix) { - if(!matrix || !matrix.length) return [] - let row = matrix.length - let col = matrix[0].length - let res = [] - let moves = { - 'right': [0,1], - 'down': [1,0], - 'left': [0,-1], - 'up': [-1,0] +var spiralOrder = function (matrix) { + if (!matrix || !matrix.length) return []; + let row = matrix.length; + let col = matrix[0].length; + let res = []; + let moves = { + right: [0, 1], + down: [1, 0], + left: [0, -1], + up: [-1, 0], + }; + let k = 0; + function dfs(i, j, dir) { + if (i < 0 || j < 0 || i >= row || j >= col || res.length === row * col) { + return; } - let k = 0 - function dfs(i,j,dir) { - if(i < 0 || j < 0 || i >= row || j >= col || res.length === row * col) { - return - } - res.push(matrix[i][j]) - switch(dir) { - case 'right': if(j === col-1 - k) dir = 'down';break - case 'down': if(i === row-1 - k) dir = 'left';break - case 'left': if(j === k) { dir = 'up';k++; } break - case 'up': if(i === k) dir = 'right';break + res.push(matrix[i][j]); + switch (dir) { + case "right": + if (j === col - 1 - k) dir = "down"; + break; + case "down": + if (i === row - 1 - k) dir = "left"; + break; + case "left": + if (j === k) { + dir = "up"; + k++; } - let x = i+moves[dir][0] - let y = j+moves[dir][1] - dfs(x,y,dir) + break; + case "up": + if (i === k) dir = "right"; + break; } - dfs(0,0,'right') - return res + let x = i + moves[dir][0]; + let y = j + moves[dir][1]; + dfs(x, y, dir); + } + dfs(0, 0, "right"); + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.js" index 21b86cd33ef64..849ab7b476e20 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.js" @@ -2,33 +2,44 @@ * @param {number[][]} matrix * @return {number[]} */ -var spiralOrder = function(matrix) { - if(!matrix || !matrix.length) return [] - let row = matrix.length - let col = matrix[0].length - let res = [] - let moves = { - 'right': [0,1], - 'down': [1,0], - 'left': [0,-1], - 'up': [-1,0] +var spiralOrder = function (matrix) { + if (!matrix || !matrix.length) return []; + let row = matrix.length; + let col = matrix[0].length; + let res = []; + let moves = { + right: [0, 1], + down: [1, 0], + left: [0, -1], + up: [-1, 0], + }; + let k = 0; + function dfs(i, j, dir) { + if (i < 0 || j < 0 || i >= row || j >= col || res.length === row * col) { + return; } - let k = 0 - function dfs(i,j,dir) { - if(i < 0 || j < 0 || i >= row || j >= col || res.length === row * col) { - return + res.push(matrix[i][j]); + switch (dir) { + case "right": + if (j === col - 1 - k) dir = "down"; + break; + case "down": + if (i === row - 1 - k) dir = "left"; + break; + case "left": + if (j === k) { + dir = "up"; + k++; } - res.push(matrix[i][j]) - switch(dir) { - case 'right': if(j === col-1 - k) dir = 'down';break - case 'down': if(i === row-1 - k) dir = 'left';break - case 'left': if(j === k) { dir = 'up';k++; } break - case 'up': if(i === k) dir = 'right';break - } - let x = i+moves[dir][0] - let y = j+moves[dir][1] - dfs(x,y,dir) + break; + case "up": + if (i === k) dir = "right"; + break; } - dfs(0,0,'right') - return res -}; \ No newline at end of file + let x = i + moves[dir][0]; + let y = j + moves[dir][1]; + dfs(x, y, dir); + } + dfs(0, 0, "right"); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" index bdb34e7dad1de..f367182748b37 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" @@ -1,6 +1,7 @@ -# [面试题30. 包含min函数的栈](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) +# [面试题 30. 包含 min 函数的栈](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) ## 题目描述 + 定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的 min 函数在该栈中,调用 min、push 及 pop 的时间复杂度都是 O(1)。 **示例:** @@ -21,9 +22,11 @@ minStack.min(); --> 返回 -2. - 各函数的调用总次数不超过 20000 次 ## 解法 + ### **Python3** + ```python class MinStack: @@ -58,31 +61,32 @@ class MinStack: ``` ### **Java** + ```java class MinStack { private Stack s1; private Stack s2; - + /** initialize your data structure here. */ public MinStack() { s1 = new Stack<>(); s2 = new Stack<>(); } - + public void push(int x) { s1.push(x); s2.push((s2.empty() || s2.peek() > x) ? x : s2.peek()); } - + public void pop() { s1.pop(); s2.pop(); } - + public int top() { return s1.peek(); } - + public int min() { return s2.peek(); } @@ -99,50 +103,51 @@ class MinStack { ``` ### **JavaScript** + ```js /** * initialize your data structure here. */ -var MinStack = function() { - this.stack = [] - this.minStack = [] +var MinStack = function () { + this.stack = []; + this.minStack = []; }; -/** +/** * @param {number} x * @return {void} */ -MinStack.prototype.push = function(x) { - this.stack.unshift(x) - if(!this.minStack.length || this.minStack[0] >= x) { - this.minStack.unshift(x) - } +MinStack.prototype.push = function (x) { + this.stack.unshift(x); + if (!this.minStack.length || this.minStack[0] >= x) { + this.minStack.unshift(x); + } }; /** * @return {void} */ -MinStack.prototype.pop = function() { - if(this.stack.shift() === this.minStack[0]) { - this.minStack.shift() - } +MinStack.prototype.pop = function () { + if (this.stack.shift() === this.minStack[0]) { + this.minStack.shift(); + } }; /** * @return {number} */ -MinStack.prototype.top = function() { - return this.stack[0] +MinStack.prototype.top = function () { + return this.stack[0]; }; /** * @return {number} */ -MinStack.prototype.min = function() { - return this.minStack[0] +MinStack.prototype.min = function () { + return this.minStack[0]; }; -/** +/** * Your MinStack object will be instantiated and called as such: * var obj = new MinStack() * obj.push(x) @@ -153,8 +158,9 @@ MinStack.prototype.min = function() { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.js" index 4593816272b44..b0edfd8dd3ece 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.js" @@ -1,50 +1,50 @@ /** * initialize your data structure here. */ -var MinStack = function() { - this.stack = [] - this.minStack = [] +var MinStack = function () { + this.stack = []; + this.minStack = []; }; -/** +/** * @param {number} x * @return {void} */ -MinStack.prototype.push = function(x) { - this.stack.unshift(x) - if(!this.minStack.length || this.minStack[0] >= x) { - this.minStack.unshift(x) - } +MinStack.prototype.push = function (x) { + this.stack.unshift(x); + if (!this.minStack.length || this.minStack[0] >= x) { + this.minStack.unshift(x); + } }; /** * @return {void} */ -MinStack.prototype.pop = function() { - if(this.stack.shift() === this.minStack[0]) { - this.minStack.shift() - } +MinStack.prototype.pop = function () { + if (this.stack.shift() === this.minStack[0]) { + this.minStack.shift(); + } }; /** * @return {number} */ -MinStack.prototype.top = function() { - return this.stack[0] +MinStack.prototype.top = function () { + return this.stack[0]; }; /** * @return {number} */ -MinStack.prototype.min = function() { - return this.minStack[0] +MinStack.prototype.min = function () { + return this.minStack[0]; }; -/** +/** * Your MinStack object will be instantiated and called as such: * var obj = new MinStack() * obj.push(x) * obj.pop() * var param_3 = obj.top() * var param_4 = obj.min() - */ \ No newline at end of file + */ diff --git "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" index 726b720981165..b6260a33256c2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" @@ -1,7 +1,9 @@ -# [面试题31. 栈的压入、弹出序列](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) +# [面试题 31. 栈的压入、弹出序列](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) ## 题目描述 + + 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如,序列 {1,2,3,4,5} 是某栈的压栈序列,序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列,但 {4,3,5,1,2} 就不可能是该压栈序列的弹出序列。 **示例 1:** @@ -26,15 +28,18 @@ push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1 1. `0 <= pushed.length == popped.length <= 1000` 2. `0 <= pushed[i], popped[i] < 1000` -3. `pushed` 是 `popped` 的排列。 +3. `pushed`  是  `popped`  的排列。 ## 解法 + + 借助一个辅助栈实现。 ### **Python3** + ```python @@ -49,10 +54,11 @@ class Solution: pushed = pushed[1:] t.pop() return True - + ``` ### **Java** + ```java @@ -75,37 +81,39 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} pushed * @param {number[]} popped * @return {boolean} */ -var validateStackSequences = function(pushed, popped) { - let stack = [] - while(pushed.length && popped.length) { - if(pushed[0] === popped[0]) { - pushed.shift() - popped.shift() - } else if(popped[0] === stack[0]) { - stack.shift() - popped.shift() - } else { - stack.unshift(pushed.shift()) - } +var validateStackSequences = function (pushed, popped) { + let stack = []; + while (pushed.length && popped.length) { + if (pushed[0] === popped[0]) { + pushed.shift(); + popped.shift(); + } else if (popped[0] === stack[0]) { + stack.shift(); + popped.shift(); + } else { + stack.unshift(pushed.shift()); } - while(stack.length) { - if(stack[0] !== popped[0]) return false - stack.shift() - popped.shift() - } - return true + } + while (stack.length) { + if (stack[0] !== popped[0]) return false; + stack.shift(); + popped.shift(); + } + return true; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/Solution.js" index fe9857e320dfa..52c7806182149 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/Solution.js" @@ -3,23 +3,23 @@ * @param {number[]} popped * @return {boolean} */ -var validateStackSequences = function(pushed, popped) { - let stack = [] - while(pushed.length && popped.length) { - if(pushed[0] === popped[0]) { - pushed.shift() - popped.shift() - } else if(popped[0] === stack[0]) { - stack.shift() - popped.shift() - } else { - stack.unshift(pushed.shift()) - } +var validateStackSequences = function (pushed, popped) { + let stack = []; + while (pushed.length && popped.length) { + if (pushed[0] === popped[0]) { + pushed.shift(); + popped.shift(); + } else if (popped[0] === stack[0]) { + stack.shift(); + popped.shift(); + } else { + stack.unshift(pushed.shift()); } - while(stack.length) { - if(stack[0] !== popped[0]) return false - stack.shift() - popped.shift() - } - return true -}; \ No newline at end of file + } + while (stack.length) { + if (stack[0] !== popped[0]) return false; + stack.shift(); + popped.shift(); + } + return true; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" index 0cb97662f3656..dcc9cd89e45a0 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" @@ -1,6 +1,7 @@ -# [面试题32 - I. 从上到下打印二叉树](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) +# [面试题 32 - I. 从上到下打印二叉树](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) ## 题目描述 + 从上到下打印出二叉树的每个节点,同一层的节点按照从左到右的顺序打印。 **例如:** @@ -26,9 +27,11 @@ - `节点总数 <= 1000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -53,10 +56,11 @@ class Solution: s.put(node.left) if node.right: s.put(node.right) - return res + return res ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -98,6 +102,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -110,17 +115,17 @@ class Solution { * @param {TreeNode} root * @return {number[]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - while(queue.length) { - let node = queue.shift() - if(!node) continue - res.push(node.val) - queue.push(node.left,node.right) - } - return res +var levelOrder = function (root) { + if (!root) return []; + let queue = [root]; + let res = []; + while (queue.length) { + let node = queue.shift(); + if (!node) continue; + res.push(node.val); + queue.push(node.left, node.right); + } + return res; }; ``` @@ -150,12 +155,10 @@ func levelOrder(root *TreeNode) []int { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.js" index be2973fdb59c6..ed12160ee35c3 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.js" @@ -9,15 +9,15 @@ * @param {TreeNode} root * @return {number[]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - while(queue.length) { - let node = queue.shift() - if(!node) continue - res.push(node.val) - queue.push(node.left,node.right) - } - return res -}; \ No newline at end of file +var levelOrder = function (root) { + if (!root) return []; + let queue = [root]; + let res = []; + while (queue.length) { + let node = queue.shift(); + if (!node) continue; + res.push(node.val); + queue.push(node.left, node.right); + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" index 4c0115bee05ac..898261c5abca6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" @@ -1,6 +1,7 @@ -# [面试题32 - II. 从上到下打印二叉树 II](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) +# [面试题 32 - II. 从上到下打印二叉树 II](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) ## 题目描述 + 从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。 **例如:** @@ -30,9 +31,11 @@ - `节点总数 <= 1000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -69,6 +72,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -112,6 +116,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -124,23 +129,23 @@ class Solution { * @param {TreeNode} root * @return {number[][]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - let depth = 0 - while(queue.length) { - let len = queue.length - for(let i=0;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.js" index ceba808387dbf..3647f4ad7c8e8 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.js" @@ -9,21 +9,21 @@ * @param {TreeNode} root * @return {number[][]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - let depth = 0 - while(queue.length) { - let len = queue.length - for(let i=0;i ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -73,6 +76,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -121,6 +125,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -133,29 +138,29 @@ class Solution { * @param {TreeNode} root * @return {number[][]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - let depth = 0 - let dir = true - while(queue.length) { - let len = queue.length - for(let i=0;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.js" index 5f1c74803e080..e8411332450df 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.js" @@ -9,27 +9,27 @@ * @param {TreeNode} root * @return {number[][]} */ -var levelOrder = function(root) { - if(!root) return [] - let queue = [root] - let res = [] - let depth = 0 - let dir = true - while(queue.length) { - let len = queue.length - for(let i=0;i -输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果。如果是则返回 `true`,否则返回 `false`。假设输入的数组的任意两个数字都互不相同。 + +输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果。如果是则返回  `true`,否则返回  `false`。假设输入的数组的任意两个数字都互不相同。 参考以下这棵二叉搜索树: @@ -33,13 +35,15 @@ - `数组长度 <= 1000` ## 解法 + -二叉搜索树的后序遍历序列是 `[左子树, 右子树, 根结点]`,且左子树结点值均小于根结点,右子树结点值均大于根结点,递归判断即可。 +二叉搜索树的后序遍历序列是 `[左子树, 右子树, 根结点]`,且左子树结点值均小于根结点,右子树结点值均大于根结点,递归判断即可。 ### **Python3** + ```python @@ -55,10 +59,11 @@ class Solution: if postorder[j] < postorder[-1]: return False return (i == 0 or self.verifyPostorder(postorder[:i])) and (i == n - 1 or self.verifyPostorder(postorder[i:-1])) - + ``` ### **Java** + ```java @@ -93,22 +98,26 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} postorder * @return {boolean} */ -var verifyPostorder = function(postorder) { - if(!postorder || postorder.length < 2) return true - let mid = 0 - let root = postorder[postorder.length-1] - for(let i=0;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.js" index a2782d95ea013..76f3161919669 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.js" @@ -2,15 +2,18 @@ * @param {number[]} postorder * @return {boolean} */ -var verifyPostorder = function(postorder) { - if(!postorder || postorder.length < 2) return true - let mid = 0 - let root = postorder[postorder.length-1] - for(let i=0;i + 输入一棵二叉树和一个整数,打印出二叉树中节点值的和为输入整数的所有路径。从树的根节点开始往下一直到叶节点所经过的节点形成一条路径。 **示例:** -给定如下二叉树,以及目标和 `sum = 22`, +给定如下二叉树,以及目标和  `sum = 22`, ``` 5 @@ -32,12 +34,15 @@ 1. `节点总数 <= 10000` ## 解法 + + 先序遍历+路径记录。 ### **Python3** + ```python @@ -62,13 +67,14 @@ class Solution: dfs(root.left, target) dfs(root.right, target) path.pop() - + dfs(root, sum) return res ``` ### **Java** + ```java @@ -110,6 +116,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -123,28 +130,28 @@ class Solution { * @param {number} sum * @return {number[][]} */ -var pathSum = function(root, sum) { - if(!root) return [] - let res = [] - function dfs(node,sum,arr) { - if(!node) return - arr = [...arr,node.val] - if(node.val === sum && !node.left && !node.right) { - res.push(arr) - return - } - dfs(node.left,sum - node.val,arr) - dfs(node.right,sum - node.val,arr) +var pathSum = function (root, sum) { + if (!root) return []; + let res = []; + function dfs(node, sum, arr) { + if (!node) return; + arr = [...arr, node.val]; + if (node.val === sum && !node.left && !node.right) { + res.push(arr); + return; } - dfs(root,sum,[]) - return res + dfs(node.left, sum - node.val, arr); + dfs(node.right, sum - node.val, arr); + } + dfs(root, sum, []); + return res; }; ``` ### **Go** ```go -var res [][]int +var res [][]int func pathSum(root *TreeNode, sum int) [][]int { res = [][]int{} if root == nil { @@ -171,12 +178,10 @@ func helper(node *TreeNode, target int, ans []int) { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.js" index 0f577c7ab117e..94e89520e9b59 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.js" @@ -10,19 +10,19 @@ * @param {number} sum * @return {number[][]} */ -var pathSum = function(root, sum) { - if(!root) return [] - let res = [] - function dfs(node,sum,arr) { - if(!node) return - arr = [...arr,node.val] - if(node.val === sum && !node.left && !node.right) { - res.push(arr) - return - } - dfs(node.left,sum - node.val,arr) - dfs(node.right,sum - node.val,arr) +var pathSum = function (root, sum) { + if (!root) return []; + let res = []; + function dfs(node, sum, arr) { + if (!node) return; + arr = [...arr, node.val]; + if (node.val === sum && !node.left && !node.right) { + res.push(arr); + return; } - dfs(root,sum,[]) - return res -}; \ No newline at end of file + dfs(node.left, sum - node.val, arr); + dfs(node.right, sum - node.val, arr); + } + dfs(root, sum, []); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" index 062fb20b1d509..59cc795513057 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" @@ -1,7 +1,9 @@ -# [面试题35. 复杂链表的复制](https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/) +# [面试题 35. 复杂链表的复制](https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/) ## 题目描述 + + 请实现 `copyRandomList` 函数,复制一个复杂链表。在复杂链表中,每个节点除了有一个 `next` 指针指向下一个节点,还有一个 `random` 指针指向链表中的任意节点或者 `null`。 **示例 1:** @@ -22,7 +24,6 @@ 输出:[[1,1],[2,1]] ``` - **示例 3:** ![](./images/e3.png) @@ -43,16 +44,17 @@ **提示:** - `-10000 <= Node.val <= 10000` -- `Node.random` 为空(null)或指向链表中的节点。 +- `Node.random`  为空(null)或指向链表中的节点。 - 节点数目不超过 1000 。 ## 解法 - + ### **Python3** + ```python @@ -84,6 +86,7 @@ class Solution: ``` ### **Java** + ```java @@ -129,6 +132,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * // Definition for a Node. @@ -142,18 +146,18 @@ class Solution { * @param {Node} head * @return {Node} */ -var copyRandomList = function(head) { - function copy(node) { - if(!node) return null - if(isRead.get(node)) return isRead.get(node) - let newNode = new Node(node.val) - isRead.set(node, newNode) - newNode.random = copy(node.random) - newNode.next = copy(node.next) - return newNode - } - let isRead = new Map() - return copy(head) +var copyRandomList = function (head) { + function copy(node) { + if (!node) return null; + if (isRead.get(node)) return isRead.get(node); + let newNode = new Node(node.val); + isRead.set(node, newNode); + newNode.random = copy(node.random); + newNode.next = copy(node.next); + return newNode; + } + let isRead = new Map(); + return copy(head); }; ``` @@ -205,12 +209,10 @@ func copyRandomList(head *Node) *Node { } ``` - - ### **...** ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/Solution.js" index a239f32eea2e4..17301c7671122 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/Solution.js" @@ -10,16 +10,16 @@ * @param {Node} head * @return {Node} */ -var copyRandomList = function(head) { - function copy(node) { - if(!node) return null - if(isRead.get(node)) return isRead.get(node) - let newNode = new Node(node.val) - isRead.set(node, newNode) - newNode.random = copy(node.random) - newNode.next = copy(node.next) - return newNode - } - let isRead = new Map() - return copy(head) -}; \ No newline at end of file +var copyRandomList = function (head) { + function copy(node) { + if (!node) return null; + if (isRead.get(node)) return isRead.get(node); + let newNode = new Node(node.val); + isRead.set(node, newNode); + newNode.random = copy(node.random); + newNode.next = copy(node.next); + return newNode; + } + let isRead = new Map(); + return copy(head); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" index dd1b26d61cc23..8e98fdb63bc0b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" @@ -1,7 +1,9 @@ -# [面试题36. 二叉搜索树与双向链表](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/) +# [面试题 36. 二叉搜索树与双向链表](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/) ## 题目描述 + + 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的循环双向链表。要求不能创建任何新的节点,只能调整树中节点指针的指向。 为了让您更好地理解问题,以下面的二叉搜索树为例: @@ -21,7 +23,9 @@ **注意**:此题对比原题有改动。 ## 解法 + + 二叉搜索树中序遍历得到有序序列;根结点指向左子树最后一个结点,根结点也指向右子树第一个结点。 利用虚拟头结点递归遍历求解。 @@ -29,6 +33,7 @@ ### **Python3** + ```python @@ -66,6 +71,7 @@ class Solution: ``` ### **Java** + ```java @@ -120,6 +126,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * // Definition for a Node. @@ -133,37 +140,38 @@ class Solution { * @param {Node} root * @return {Node} */ -var treeToDoublyList = function(root) { - if(!root) return null - function dfs(node) { - if(!node) return null - dfs(node.left) - arr.push(node) - dfs(node.right) +var treeToDoublyList = function (root) { + if (!root) return null; + function dfs(node) { + if (!node) return null; + dfs(node.left); + arr.push(node); + dfs(node.right); + } + let arr = []; + dfs(root); + let len = arr.length; + let res = arr[0]; + for (let i = 0; i < len; i++) { + if (i + 1 < len) { + arr[i].right = arr[i + 1]; + } else { + arr[i].right = arr[0]; } - let arr = [] - dfs(root) - let len = arr.length - let res = arr[0] - for(let i=0;i= 0) { - arr[i].left = arr[i-1] - } else { - arr[i].left = arr[len-1] - } + if (i - 1 >= 0) { + arr[i].left = arr[i - 1]; + } else { + arr[i].left = arr[len - 1]; } - return res + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/Solution.js" index fb321a85a25a0..084fe4084894d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/Solution.js" @@ -10,29 +10,29 @@ * @param {Node} root * @return {Node} */ -var treeToDoublyList = function(root) { - if(!root) return null - function dfs(node) { - if(!node) return null - dfs(node.left) - arr.push(node) - dfs(node.right) +var treeToDoublyList = function (root) { + if (!root) return null; + function dfs(node) { + if (!node) return null; + dfs(node.left); + arr.push(node); + dfs(node.right); + } + let arr = []; + dfs(root); + let len = arr.length; + let res = arr[0]; + for (let i = 0; i < len; i++) { + if (i + 1 < len) { + arr[i].right = arr[i + 1]; + } else { + arr[i].right = arr[0]; } - let arr = [] - dfs(root) - let len = arr.length - let res = arr[0] - for(let i=0;i= 0) { - arr[i].left = arr[i-1] - } else { - arr[i].left = arr[len-1] - } + if (i - 1 >= 0) { + arr[i].left = arr[i - 1]; + } else { + arr[i].left = arr[len - 1]; } - return res -}; \ No newline at end of file + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" index 2eaddd22c955d..d13c9ddfd046a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" @@ -1,7 +1,9 @@ -# [面试题37. 序列化二叉树](https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof/) +# [面试题 37. 序列化二叉树](https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof/) ## 题目描述 + + 请实现两个函数,分别用来序列化和反序列化二叉树。 **示例:** @@ -21,12 +23,15 @@ 注意:本题与主站 297 题相同:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/ ## 解法 + + 层次遍历解决。 ### **Python3** + ```python @@ -41,7 +46,7 @@ class Codec: def serialize(self, root): """Encodes a tree to a single string. - + :type root: TreeNode :rtype: str """ @@ -59,11 +64,11 @@ class Codec: else: res.append('null') return f'[{",".join(res)}]' - + def deserialize(self, data): """Decodes your encoded data to tree. - + :type data: str :rtype: TreeNode """ @@ -93,6 +98,7 @@ class Codec: ``` ### **Java** + ```java @@ -162,6 +168,7 @@ public class Codec { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -177,21 +184,21 @@ public class Codec { * @param {TreeNode} root * @return {string} */ -var serialize = function(root) { - if(!root) return '[]' - let queue = [root] - let res = '' - while(queue.length) { - let node = queue.shift() - if(node) { - res += node.val + ',' - queue.push(node.left) - queue.push(node.right) - } else { - res += 'null' + ',' - } +var serialize = function (root) { + if (!root) return "[]"; + let queue = [root]; + let res = ""; + while (queue.length) { + let node = queue.shift(); + if (node) { + res += node.val + ","; + queue.push(node.left); + queue.push(node.right); + } else { + res += "null" + ","; } - return `[${res.substring(0,res.length-1)}]` + } + return `[${res.substring(0, res.length - 1)}]`; }; /** @@ -200,25 +207,25 @@ var serialize = function(root) { * @param {string} data * @return {TreeNode} */ -var deserialize = function(data) { - if(!data || data.length <= 2) return null - let arr = data.substring(1,data.length-1).split(',') - let root = new TreeNode(arr.shift()) - let queue = [root] - while(queue.length) { - let node = queue.shift() - let leftVal = arr.shift() - if(leftVal !== 'null') { - node.left = new TreeNode(leftVal) - queue.push(node.left) - } - let rightVal = arr.shift() - if(rightVal !== 'null') { - node.right = new TreeNode(rightVal) - queue.push(node.right) - } +var deserialize = function (data) { + if (!data || data.length <= 2) return null; + let arr = data.substring(1, data.length - 1).split(","); + let root = new TreeNode(arr.shift()); + let queue = [root]; + while (queue.length) { + let node = queue.shift(); + let leftVal = arr.shift(); + if (leftVal !== "null") { + node.left = new TreeNode(leftVal); + queue.push(node.left); + } + let rightVal = arr.shift(); + if (rightVal !== "null") { + node.right = new TreeNode(rightVal); + queue.push(node.right); } - return root + } + return root; }; /** @@ -228,8 +235,9 @@ var deserialize = function(data) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" index c20e0c3b3001b..367c42e87e8b1 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" @@ -12,21 +12,21 @@ * @param {TreeNode} root * @return {string} */ -var serialize = function(root) { - if(!root) return '[]' - let queue = [root] - let res = '' - while(queue.length) { - let node = queue.shift() - if(node) { - res += node.val + ',' - queue.push(node.left) - queue.push(node.right) - } else { - res += 'null' + ',' - } +var serialize = function (root) { + if (!root) return "[]"; + let queue = [root]; + let res = ""; + while (queue.length) { + let node = queue.shift(); + if (node) { + res += node.val + ","; + queue.push(node.left); + queue.push(node.right); + } else { + res += "null" + ","; } - return `[${res.substring(0,res.length-1)}]` + } + return `[${res.substring(0, res.length - 1)}]`; }; /** @@ -35,28 +35,28 @@ var serialize = function(root) { * @param {string} data * @return {TreeNode} */ -var deserialize = function(data) { - if(!data || data.length <= 2) return null - let arr = data.substring(1,data.length-1).split(',') - let root = new TreeNode(arr.shift()) - let queue = [root] - while(queue.length) { - let node = queue.shift() - let leftVal = arr.shift() - if(leftVal !== 'null') { - node.left = new TreeNode(leftVal) - queue.push(node.left) - } - let rightVal = arr.shift() - if(rightVal !== 'null') { - node.right = new TreeNode(rightVal) - queue.push(node.right) - } +var deserialize = function (data) { + if (!data || data.length <= 2) return null; + let arr = data.substring(1, data.length - 1).split(","); + let root = new TreeNode(arr.shift()); + let queue = [root]; + while (queue.length) { + let node = queue.shift(); + let leftVal = arr.shift(); + if (leftVal !== "null") { + node.left = new TreeNode(leftVal); + queue.push(node.left); } - return root + let rightVal = arr.shift(); + if (rightVal !== "null") { + node.right = new TreeNode(rightVal); + queue.push(node.right); + } + } + return root; }; /** * Your functions will be called as such: * deserialize(serialize(root)); - */ \ No newline at end of file + */ diff --git "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" index e9bd942bdc560..6c87232265bc2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" @@ -1,7 +1,9 @@ -# [面试题38. 字符串的排列](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) +# [面试题 38. 字符串的排列](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) ## 题目描述 + + 输入一个字符串,打印出该字符串中字符的所有排列。 你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。 @@ -18,12 +20,13 @@ - `1 <= s 的长度 <= 8` ## 解法 - + ### **Python3** + ```python @@ -47,6 +50,7 @@ class Solution: ``` ### **Java** + ```java @@ -87,34 +91,36 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @return {string[]} */ -var permutation = function(s) { - let len = s.length - let res = new Set() - function dfs(str, isRead) { - if(str.length === len) { - res.add(str) - return - } - for(let i=0;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/Solution.js" index 31c03adece6bd..4e0077b2b2dc6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/Solution.js" @@ -2,21 +2,21 @@ * @param {string} s * @return {string[]} */ -var permutation = function(s) { - let len = s.length - let res = new Set() - function dfs(str, isRead) { - if(str.length === len) { - res.add(str) - return - } - for(let i=0;i ### **Python3** + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -36,6 +39,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int majorityElement(int[] nums) { @@ -54,31 +58,33 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var majorityElement = function(nums) { - let cnt = 0 - let mode = -1 - for(let num of nums) { - if(!cnt) { - mode = num - cnt++ - } else { - if(mode === num) cnt++ - else cnt-- - } +var majorityElement = function (nums) { + let cnt = 0; + let mode = -1; + for (let num of nums) { + if (!cnt) { + mode = num; + cnt++; + } else { + if (mode === num) cnt++; + else cnt--; } - return mode - // return nums.sort((a,b)=>a-b)[~~(nums.length/2)] + } + return mode; + // return nums.sort((a,b)=>a-b)[~~(nums.length/2)] }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/Solution.js" index e36ecfcc4512c..62cac584d93ca 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/Solution.js" @@ -2,18 +2,18 @@ * @param {number[]} nums * @return {number} */ -var majorityElement = function(nums) { - let cnt = 0 - let mode = -1 - for(let num of nums) { - if(!cnt) { - mode = num - cnt++ - } else { - if(mode === num) cnt++ - else cnt-- - } +var majorityElement = function (nums) { + let cnt = 0; + let mode = -1; + for (let num of nums) { + if (!cnt) { + mode = num; + cnt++; + } else { + if (mode === num) cnt++; + else cnt--; } - return mode - // return nums.sort((a,b)=>a-b)[~~(nums.length/2)] -}; \ No newline at end of file + } + return mode; + // return nums.sort((a,b)=>a-b)[~~(nums.length/2)] +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" index 6f7af54e52345..6652f3e02c7b4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" @@ -1,6 +1,7 @@ -# [面试题40. 最小的k个数](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) +# [面试题 40. 最小的 k 个数](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) ## 题目描述 + 输入整数数组 `arr`,找出其中最小的 `k` 个数。例如,输入 4、5、1、6、2、7、3、8 这 8 个数字,则最小的 4 个数字是 1、2、3、4。 **示例 1:** @@ -20,12 +21,14 @@ **限制:** - `0 <= k <= arr.length <= 10000` -- `0 <= arr[i] <= 10000` +- `0 <= arr[i] <= 10000` ## 解法 + ### **Python3** + ```python import heapq @@ -40,6 +43,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int[] getLeastNumbers(int[] arr, int k) { @@ -67,50 +71,52 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} arr * @param {number} k * @return {number[]} */ -var getLeastNumbers = function(arr, k) { - // 排序 - // return arr.sort((a,b)=>a-b).slice(0,k) - // ========================================== - // 快排思想 - let left = 0 - let right = arr.length-1 - while(left < right) { - let i = partition(left, right) - if(i <= k) { - left = i+1 - } - if(i >= k){ - right = i-1 - } +var getLeastNumbers = function (arr, k) { + // 排序 + // return arr.sort((a,b)=>a-b).slice(0,k) + // ========================================== + // 快排思想 + let left = 0; + let right = arr.length - 1; + while (left < right) { + let i = partition(left, right); + if (i <= k) { + left = i + 1; } - function partition(left, right) { - let pivot = arr[left] - while(left < right) { - while(left < right && arr[right] >= pivot) { - right-- - } - arr[left] = arr[right] - while(left < right && arr[left] <= pivot) { - left++ - } - arr[right] = arr[left] - } - arr[left] = pivot - return left + if (i >= k) { + right = i - 1; + } + } + function partition(left, right) { + let pivot = arr[left]; + while (left < right) { + while (left < right && arr[right] >= pivot) { + right--; + } + arr[left] = arr[right]; + while (left < right && arr[left] <= pivot) { + left++; + } + arr[right] = arr[left]; } - return arr.slice(0, k) + arr[left] = pivot; + return left; + } + return arr.slice(0, k); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" index a38c36f60fc41..6635277b4c34e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" @@ -3,36 +3,36 @@ * @param {number} k * @return {number[]} */ -var getLeastNumbers = function(arr, k) { - // 排序 - // return arr.sort((a,b)=>a-b).slice(0,k) - // ========================================== - // 快排思想 - let left = 0 - let right = arr.length-1 - while(left < right) { - let i = partition(left, right) - if(i <= k) { - left = i+1 - } - if(i >= k){ - right = i-1 - } +var getLeastNumbers = function (arr, k) { + // 排序 + // return arr.sort((a,b)=>a-b).slice(0,k) + // ========================================== + // 快排思想 + let left = 0; + let right = arr.length - 1; + while (left < right) { + let i = partition(left, right); + if (i <= k) { + left = i + 1; } - function partition(left, right) { - let pivot = arr[left] - while(left < right) { - while(left < right && arr[right] >= pivot) { - right-- - } - arr[left] = arr[right] - while(left < right && arr[left] <= pivot) { - left++ - } - arr[right] = arr[left] - } - arr[left] = pivot - return left + if (i >= k) { + right = i - 1; } - return arr.slice(0, k) -}; \ No newline at end of file + } + function partition(left, right) { + let pivot = arr[left]; + while (left < right) { + while (left < right && arr[right] >= pivot) { + right--; + } + arr[left] = arr[right]; + while (left < right && arr[left] <= pivot) { + left++; + } + arr[right] = arr[left]; + } + arr[left] = pivot; + return left; + } + return arr.slice(0, k); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" index 27251a4da8bb0..02ff15cb14d25 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" @@ -1,12 +1,14 @@ -# [面试题41. 数据流中的中位数](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) +# [面试题 41. 数据流中的中位数](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) ## 题目描述 + + 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。 例如, -`[2,3,4]` 的中位数是 3 +`[2,3,4]`  的中位数是 3 `[2,3]` 的中位数是 (2 + 3) / 2 = 2.5 @@ -35,19 +37,22 @@ **限制:** -- 最多会对 addNum、findMedia进行 50000 次调用。 +- 最多会对  addNum、findMedia 进行  50000  次调用。 注意:本题与主站 295 题相同:https://leetcode-cn.com/problems/find-median-from-data-stream/ ## 解法 + + - 创建大根堆、小根堆,其中:大根堆存放较小的一半元素,小根堆存放较大的一半元素。 -- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多1);若不等,放入大根堆(使得大小根堆元素个数相等) +- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多 1);若不等,放入大根堆(使得大小根堆元素个数相等) - 取中位数时,若两堆元素个数相等,取两堆顶求平均值;若不等,取小根堆堆顶。 ### **Python3** + ```python @@ -78,6 +83,7 @@ class MedianFinder: ``` ### **Java** + ```java @@ -90,7 +96,7 @@ class MedianFinder { minHeap = new PriorityQueue<>(); maxHeap = new PriorityQueue<>((a, b) -> b - a); } - + public void addNum(int num) { if (maxHeap.size() == minHeap.size()) { maxHeap.offer(num); @@ -102,7 +108,7 @@ class MedianFinder { maxHeap.offer(minHeap.poll()); } } - + public double findMedian() { if (((maxHeap.size() + minHeap.size()) & 1) == 0) { // 偶数个,取两个堆顶平均值 @@ -121,46 +127,48 @@ class MedianFinder { ``` ### **JavaScript** + ```js /** * initialize your data structure here. */ -var MedianFinder = function() { - this.val = [] +var MedianFinder = function () { + this.val = []; }; -/** +/** * @param {number} num * @return {void} */ -MedianFinder.prototype.addNum = function(num) { - let left = 0; - let right = this.val.length; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (num > this.val[mid]) { - left = mid + 1; - } else { - right = mid; - } +MedianFinder.prototype.addNum = function (num) { + let left = 0; + let right = this.val.length; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (num > this.val[mid]) { + left = mid + 1; + } else { + right = mid; } - this.val.splice(left, 0, num); + } + this.val.splice(left, 0, num); }; /** * @return {number} */ -MedianFinder.prototype.findMedian = function() { - let mid = ~~(this.val.length / 2); - return this.val.length % 2 - ? this.val[mid] - : (this.val[mid - 1] + this.val[mid]) / 2; +MedianFinder.prototype.findMedian = function () { + let mid = ~~(this.val.length / 2); + return this.val.length % 2 + ? this.val[mid] + : (this.val[mid - 1] + this.val[mid]) / 2; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" index 82e4b9d14af4a..53a75740737e9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" @@ -1,34 +1,34 @@ /** * initialize your data structure here. */ -var MedianFinder = function() { - this.val = [] +var MedianFinder = function () { + this.val = []; }; -/** +/** * @param {number} num * @return {void} */ -MedianFinder.prototype.addNum = function(num) { - let left = 0; - let right = this.val.length; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (num > this.val[mid]) { - left = mid + 1; - } else { - right = mid; - } +MedianFinder.prototype.addNum = function (num) { + let left = 0; + let right = this.val.length; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (num > this.val[mid]) { + left = mid + 1; + } else { + right = mid; } - this.val.splice(left, 0, num); + } + this.val.splice(left, 0, num); }; /** * @return {number} */ -MedianFinder.prototype.findMedian = function() { - let mid = ~~(this.val.length / 2); - return this.val.length % 2 - ? this.val[mid] - : (this.val[mid - 1] + this.val[mid]) / 2; -}; \ No newline at end of file +MedianFinder.prototype.findMedian = function () { + let mid = ~~(this.val.length / 2); + return this.val.length % 2 + ? this.val[mid] + : (this.val[mid - 1] + this.val[mid]) / 2; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" index 4f10120365215..01d75a884f19d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" @@ -1,11 +1,12 @@ -# [面试题42. 连续子数组的最大和](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/) +# [面试题 42. 连续子数组的最大和](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/) ## 题目描述 + 输入一个整型数组,数组里有正数也有负数。数组中的一个或连续多个整数组成一个子数组。求所有子数组的和的最大值。 要求时间复杂度为 O(n)。 -**示例1:** +**示例 1:** ``` 输入: nums = [-2,1,-3,4,-1,2,1,-5,4] @@ -15,13 +16,15 @@ **提示:** -- `1 <= arr.length <= 10^5` +- `1 <= arr.length <= 10^5` - `-100 <= arr[i] <= 100` ## 解法 + ### **Python3** + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -34,6 +37,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int maxSubArray(int[] nums) { @@ -48,26 +52,28 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var maxSubArray = function(nums) { - if(!nums || !nums.length) return null - let len = nums.length - let dp = new Array(len) - dp[0] = nums[0] - for(let i=1;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/Solution.js" index 7633cbe18f535..34bfffa33d0b8 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/Solution.js" @@ -2,13 +2,13 @@ * @param {number[]} nums * @return {number} */ -var maxSubArray = function(nums) { - if(!nums || !nums.length) return null - let len = nums.length - let dp = new Array(len) - dp[0] = nums[0] - for(let i=1;i -输入一个整数 `n` ,求1~n这n个整数的十进制表示中1出现的次数。 -例如,输入12,1~12这些整数中包含1 的数字有1、10、11和12,1一共出现了5次。 +输入一个整数 `n` ,求 1 ~ n 这 n 个整数的十进制表示中 1 出现的次数。 + +例如,输入 12,1 ~ 12 这些整数中包含 1 的数字有 1、10、11 和 12,1 一共出现了 5 次。 **示例 1:** @@ -22,12 +24,14 @@ **限制:** -- `1 <= n < 2^31` +- `1 <= n < 2^31` 注意:本题与主站 233 题相同:https://leetcode-cn.com/problems/number-of-digit-one/ ## 解法 + + 将 n 拆为两部分:最高位 high 和低位 lows。按 high 是否为 1 分别递归求解结果 f(n)。 以 n=3356 举例说明。 @@ -46,6 +50,7 @@ high=3,lows=356,base=1000。此时 n 可拆分为 `0~999`,`1000~1999`,`2000~2999 ### **Python3** + ```python @@ -64,6 +69,7 @@ class Solution: ``` ### **Java** + ```java @@ -84,32 +90,39 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var countDigitOne = function(n) { - let res = 0 - let i=1 - while(i <= n) { - let high = ~~(n / i / 10) - let cur = ~~(n / i) % 10 - let low = n - ~~(n / i) * i - switch(cur) { - case 0: res += high * i;break - case 1: res += high * i + low + 1;break - default: res += (high + 1) * i - } - i *= 10 +var countDigitOne = function (n) { + let res = 0; + let i = 1; + while (i <= n) { + let high = ~~(n / i / 10); + let cur = ~~(n / i) % 10; + let low = n - ~~(n / i) * i; + switch (cur) { + case 0: + res += high * i; + break; + case 1: + res += high * i + low + 1; + break; + default: + res += (high + 1) * i; } - return res + i *= 10; + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" index ffd8885658009..ce8b7bb77f60a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" @@ -2,19 +2,24 @@ * @param {number} n * @return {number} */ -var countDigitOne = function(n) { - let res = 0 - let i=1 - while(i <= n) { - let high = ~~(n / i / 10) - let cur = ~~(n / i) % 10 - let low = n - ~~(n / i) * i - switch(cur) { - case 0: res += high * i;break - case 1: res += high * i + low + 1;break - default: res += (high + 1) * i - } - i *= 10 +var countDigitOne = function (n) { + let res = 0; + let i = 1; + while (i <= n) { + let high = ~~(n / i / 10); + let cur = ~~(n / i) % 10; + let low = n - ~~(n / i) * i; + switch (cur) { + case 0: + res += high * i; + break; + case 1: + res += high * i + low + 1; + break; + default: + res += (high + 1) * i; } - return res -}; \ No newline at end of file + i *= 10; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" index c5a968f52d67d..6ccb41021cdd9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" @@ -1,10 +1,12 @@ -# [面试题44. 数字序列中某一位的数字](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/) +# [面试题 44. 数字序列中某一位的数字](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/) ## 题目描述 + -数字以0123456789101112131415…的格式序列化到一个字符序列中。在这个序列中,第5位(从下标0开始计数)是5,第13位是1,第19位是4,等等。 -请写一个函数,求任意第n位对应的数字。 +数字以 0123456789101112131415…的格式序列化到一个字符序列中。在这个序列中,第 5 位(从下标 0 开始计数)是 5,第 13 位是 1,第 19 位是 4,等等。 + +请写一个函数,求任意第 n 位对应的数字。 **示例 1:** @@ -22,12 +24,14 @@ **限制:** -- `0 <= n < 2^31` +- `0 <= n < 2^31` 注意:本题与主站 400 题相同:https://leetcode-cn.com/problems/nth-digit/ ## 解法 + + - pow = 0:0~9 有 10 位 - pow = 1: 10~99 有 `90*2=180` 位 - pow = 2: 100~999 有 `900*3=2700` 位。 @@ -37,6 +41,7 @@ ### **Python3** + ```python @@ -61,6 +66,7 @@ class Solution: ``` ### **Java** + ```java @@ -88,33 +94,35 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var findNthDigit = function(n) { - let i = 9 - let a = 1 - let remain = n - while(i * a < remain) { - remain -= i * a - i *= 10 - a++ - } - let b = remain % a - let res = 10**(a-1) + ~~(remain / a) - if(b === 0) { - b = a - res-- - } - return res.toString()[b-1] +var findNthDigit = function (n) { + let i = 9; + let a = 1; + let remain = n; + while (i * a < remain) { + remain -= i * a; + i *= 10; + a++; + } + let b = remain % a; + let res = 10 ** (a - 1) + ~~(remain / a); + if (b === 0) { + b = a; + res--; + } + return res.toString()[b - 1]; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" index b77b4ad05df67..815d5889bb5a5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" @@ -2,20 +2,20 @@ * @param {number} n * @return {number} */ -var findNthDigit = function(n) { - let i = 9 - let a = 1 - let remain = n - while(i * a < remain) { - remain -= i * a - i *= 10 - a++ - } - let b = remain % a - let res = 10**(a-1) + ~~(remain / a) - if(b === 0) { - b = a - res-- - } - return res.toString()[b-1] -}; \ No newline at end of file +var findNthDigit = function (n) { + let i = 9; + let a = 1; + let remain = n; + while (i * a < remain) { + remain -= i * a; + i *= 10; + a++; + } + let b = remain % a; + let res = 10 ** (a - 1) + ~~(remain / a); + if (b === 0) { + b = a; + res--; + } + return res.toString()[b - 1]; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" index 3577173be5f87..17aceb34f8d7c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" @@ -1,7 +1,9 @@ -# [面试题45. 把数组排成最小的数](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) +# [面试题 45. 把数组排成最小的数](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) ## 题目描述 + + 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。 **示例 1:** @@ -11,7 +13,7 @@ 输出: "102" ``` -**示例 2:** +**示例  2:** ``` 输入: [3,30,34,5,9] @@ -28,12 +30,15 @@ - 拼接起来的数字可能会有前导 0,最后结果不需要去掉前导 0。 ## 解法 + + 自定义排序比较器。 ### **Python3** + ```python @@ -43,18 +48,19 @@ class Solution: def minNumber(self, nums: List[int]) -> str: if not nums: return '' - + def compare(s1, s2): if s1 + s2 < s2 + s1: return -1 if s1 + s2 > s2 + s1: return 1 return 0 - + return ''.join(sorted([str(x) for x in nums], key=functools.cmp_to_key(compare))) ``` ### **Java** + ```java @@ -69,26 +75,28 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {string} */ -var minNumber = function(nums) { - nums.sort((a,b) => { - let s1 = a + '' + b - let s2 = b + '' + a - if(s1 < s2) { - return -1 - } else return 1 - }) - return nums.join('') +var minNumber = function (nums) { + nums.sort((a, b) => { + let s1 = a + "" + b; + let s2 = b + "" + a; + if (s1 < s2) { + return -1; + } else return 1; + }); + return nums.join(""); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" index d40170dfb8233..4c67f3da78ec6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" @@ -2,13 +2,13 @@ * @param {number[]} nums * @return {string} */ -var minNumber = function(nums) { - nums.sort((a,b) => { - let s1 = a + '' + b - let s2 = b + '' + a - if(s1 < s2) { - return -1 - } else return 1 - }) - return nums.join('') -}; \ No newline at end of file +var minNumber = function (nums) { + nums.sort((a, b) => { + let s1 = a + "" + b; + let s2 = b + "" + a; + if (s1 < s2) { + return -1; + } else return 1; + }); + return nums.join(""); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" index a02132ee02ba9..2b5914a05a461 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" @@ -1,7 +1,9 @@ -# [面试题46. 把数字翻译成字符串](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) +# [面试题 46. 把数字翻译成字符串](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) ## 题目描述 + + 给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。 **示例 1:** @@ -17,12 +19,15 @@ - 0 <= num < 231 ## 解法 + + 递归求解。 ### **Python3** + ```python @@ -37,6 +42,7 @@ class Solution: ``` ### **Java** + ```java @@ -57,33 +63,35 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} num * @return {number} */ -var translateNum = function(num) { - let res = 0 - num = num.toString() - function dfs(i) { - if(i >= num.length) { - res++ - return - } - dfs(i+1) - let tmp = +(num[i] + num[i+1]) - if(num[i] !== '0' && tmp >= 0 && tmp < 26 ) { - dfs(i+2) - } +var translateNum = function (num) { + let res = 0; + num = num.toString(); + function dfs(i) { + if (i >= num.length) { + res++; + return; } - dfs(0) - return res + dfs(i + 1); + let tmp = +(num[i] + num[i + 1]); + if (num[i] !== "0" && tmp >= 0 && tmp < 26) { + dfs(i + 2); + } + } + dfs(0); + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" index 189758ba46639..efd6471e73989 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" @@ -2,20 +2,20 @@ * @param {number} num * @return {number} */ -var translateNum = function(num) { - let res = 0 - num = num.toString() - function dfs(i) { - if(i >= num.length) { - res++ - return - } - dfs(i+1) - let tmp = +(num[i] + num[i+1]) - if(num[i] !== '0' && tmp >= 0 && tmp < 26 ) { - dfs(i+2) - } +var translateNum = function (num) { + let res = 0; + num = num.toString(); + function dfs(i) { + if (i >= num.length) { + res++; + return; } - dfs(0) - return res -}; \ No newline at end of file + dfs(i + 1); + let tmp = +(num[i] + num[i + 1]); + if (num[i] !== "0" && tmp >= 0 && tmp < 26) { + dfs(i + 2); + } + } + dfs(0); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" index 176f82d1b9fb1..44eb15827f4d9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" @@ -1,12 +1,13 @@ -# [面试题47. 礼物的最大价值](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) +# [面试题 47. 礼物的最大价值](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) ## 题目描述 + 在一个 `m*n` 的棋盘的每一格都放有一个礼物,每个礼物都有一定的价值(价值大于 0)。你可以从棋盘的左上角开始拿格子里的礼物,并每次向右或者向下移动一格、直到到达棋盘的右下角。给定一个棋盘及其上面的礼物的价值,请计算你最多能拿到多少价值的礼物? **示例 1:** ``` -输入: +输入: [   [1,3,1],   [1,5,1], @@ -22,9 +23,11 @@ - `0 < grid[0].length <= 200` ## 解法 + ### **Python3** + ```python class Solution: def maxValue(self, grid: List[List[int]]) -> int: @@ -43,6 +46,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int maxValue(int[][] grid) { @@ -66,27 +70,29 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[][]} grid * @return {number} */ -var maxValue = function(grid) { - let row = grid.length - let col = grid[0].length - let dp = [...new Array(row+1)].map(() => Array(col+1).fill(0)) - for(let i=1;i<=row;i++) { - for(let j=1;j<=col;j++) { - dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]) + grid[i-1][j-1] - } +var maxValue = function (grid) { + let row = grid.length; + let col = grid[0].length; + let dp = [...new Array(row + 1)].map(() => Array(col + 1).fill(0)); + for (let i = 1; i <= row; i++) { + for (let j = 1; j <= col; j++) { + dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + grid[i - 1][j - 1]; } - return dp[row][col] + } + return dp[row][col]; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/Solution.js" index be0890f266179..d957d8d57866a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/Solution.js" @@ -2,14 +2,14 @@ * @param {number[][]} grid * @return {number} */ -var maxValue = function(grid) { - let row = grid.length - let col = grid[0].length - let dp = [...new Array(row+1)].map(() => Array(col+1).fill(0)) - for(let i=1;i<=row;i++) { - for(let j=1;j<=col;j++) { - dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]) + grid[i-1][j-1] - } +var maxValue = function (grid) { + let row = grid.length; + let col = grid[0].length; + let dp = [...new Array(row + 1)].map(() => Array(col + 1).fill(0)); + for (let i = 1; i <= row; i++) { + for (let j = 1; j <= col; j++) { + dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + grid[i - 1][j - 1]; } - return dp[row][col] -}; \ No newline at end of file + } + return dp[row][col]; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" index 9d859f3e06395..e64adb5e5ff31 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" @@ -1,13 +1,14 @@ -# [面试题48. 最长不含重复字符的子字符串](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) +# [面试题 48. 最长不含重复字符的子字符串](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) ## 题目描述 + 请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。 -**示例 1:** +**示例  1:** ``` 输入: "abcabcbb" -输出: 3 +输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 ``` @@ -33,9 +34,11 @@ - `s.length <= 40000` ## 解法 + ### **Python3** + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -59,6 +62,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -91,37 +95,39 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @return {number} */ -var lengthOfLongestSubstring = function(s) { - let left = 0 - let right = 0 - let res = 0 - let len = s.length - let rec = {} - while(right < len) { - let tmp = '*' - while(right < len) { - tmp = s[right] - if(!rec[tmp]) rec[tmp] = 0 - rec[tmp]++ - if(rec[tmp] > 1) break - right++ - } - res = Math.max(res, right - left) - while(rec[tmp] > 1) rec[s[left++]]-- - right++ +var lengthOfLongestSubstring = function (s) { + let left = 0; + let right = 0; + let res = 0; + let len = s.length; + let rec = {}; + while (right < len) { + let tmp = "*"; + while (right < len) { + tmp = s[right]; + if (!rec[tmp]) rec[tmp] = 0; + rec[tmp]++; + if (rec[tmp] > 1) break; + right++; } - return res + res = Math.max(res, right - left); + while (rec[tmp] > 1) rec[s[left++]]--; + right++; + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" index 680c338960bd4..32e3477f03cdc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" @@ -2,24 +2,24 @@ * @param {string} s * @return {number} */ -var lengthOfLongestSubstring = function(s) { - let left = 0 - let right = 0 - let res = 0 - let len = s.length - let rec = {} - while(right < len) { - let tmp = '*' - while(right < len) { - tmp = s[right] - if(!rec[tmp]) rec[tmp] = 0 - rec[tmp]++ - if(rec[tmp] > 1) break - right++ - } - res = Math.max(res, right - left) - while(rec[tmp] > 1) rec[s[left++]]-- - right++ +var lengthOfLongestSubstring = function (s) { + let left = 0; + let right = 0; + let res = 0; + let len = s.length; + let rec = {}; + while (right < len) { + let tmp = "*"; + while (right < len) { + tmp = s[right]; + if (!rec[tmp]) rec[tmp] = 0; + rec[tmp]++; + if (rec[tmp] > 1) break; + right++; } - return res -}; \ No newline at end of file + res = Math.max(res, right - left); + while (rec[tmp] > 1) rec[s[left++]]--; + right++; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" index 40e93ba1303e5..b369ea2a71654 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" @@ -1,7 +1,9 @@ -# [面试题49. 丑数](https://leetcode-cn.com/problems/chou-shu-lcof/) +# [面试题 49. 丑数](https://leetcode-cn.com/problems/chou-shu-lcof/) ## 题目描述 + + 我们把只包含因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。 **示例:** @@ -14,17 +16,17 @@ **说明:** -1. `1` 是丑数。 -2. `n` 不超过 1690。 - +1. `1`  是丑数。 +2. `n`  不超过 1690。 ## 解法 - + ### **Python3** + ```python @@ -48,6 +50,7 @@ class Solution: ``` ### **Java** + ```java @@ -73,41 +76,40 @@ class Solution { } } return dp[n - 1]; - + } } ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var nthUglyNumber = function(n) { - let res = [1]; - //三指针 - let a = 0;//2 - let b = 0;//3 - let c = 0;//5 - let min = 0; - for(let i=1;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" index 15c46e16772cf..d1da4ed68afcb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" @@ -2,22 +2,19 @@ * @param {number} n * @return {number} */ -var nthUglyNumber = function(n) { - let res = [1]; - //三指针 - let a = 0;//2 - let b = 0;//3 - let c = 0;//5 - let min = 0; - for(let i=1;i \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.js" index 14d0fbda9e8c3..380efd25434a0 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.js" @@ -2,14 +2,14 @@ * @param {string} s * @return {character} */ -var firstUniqChar = function(s) { - let t = new Array(26).fill(0) - let code = ('a').charCodeAt() - for(let i=0;i + 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 **示例 1:** @@ -16,12 +18,15 @@ - `0 <= 数组长度 <= 50000` ## 解法 + + 在归并中统计逆序对。 ### **Python3** + ```python @@ -65,6 +70,7 @@ class Solution: ``` ### **Java** + ```java @@ -115,44 +121,46 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var reversePairs = function(nums) { - if(!nums || nums.length < 2) return 0 - let res = 0 - function mergeSort(arr) { - if(arr.length === 1) { - return arr - } - let mid = ~~(arr.length/2) - return merge(mergeSort(arr.slice(0,mid)),mergeSort(arr.slice(mid))) +var reversePairs = function (nums) { + if (!nums || nums.length < 2) return 0; + let res = 0; + function mergeSort(arr) { + if (arr.length === 1) { + return arr; } - function merge(a,b) { - let r = [] - let cnt = 0 - while(a && b && a.length && b.length) { - if(a[0] <= b[0]) { - res += cnt - r.push(a.shift()) - } else { - r.push(b.shift()) - cnt++ - } - } - res += a.length * cnt - return r.concat(a,b) + let mid = ~~(arr.length / 2); + return merge(mergeSort(arr.slice(0, mid)), mergeSort(arr.slice(mid))); + } + function merge(a, b) { + let r = []; + let cnt = 0; + while (a && b && a.length && b.length) { + if (a[0] <= b[0]) { + res += cnt; + r.push(a.shift()); + } else { + r.push(b.shift()); + cnt++; + } } - mergeSort(nums) - return res + res += a.length * cnt; + return r.concat(a, b); + } + mergeSort(nums); + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" index 99bf5c71392ef..58d388811402f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" @@ -2,31 +2,31 @@ * @param {number[]} nums * @return {number} */ -var reversePairs = function(nums) { - if(!nums || nums.length < 2) return 0 - let res = 0 - function mergeSort(arr) { - if(arr.length === 1) { - return arr - } - let mid = ~~(arr.length/2) - return merge(mergeSort(arr.slice(0,mid)),mergeSort(arr.slice(mid))) +var reversePairs = function (nums) { + if (!nums || nums.length < 2) return 0; + let res = 0; + function mergeSort(arr) { + if (arr.length === 1) { + return arr; } - function merge(a,b) { - let r = [] - let cnt = 0 - while(a && b && a.length && b.length) { - if(a[0] <= b[0]) { - res += cnt - r.push(a.shift()) - } else { - r.push(b.shift()) - cnt++ - } - } - res += a.length * cnt - return r.concat(a,b) + let mid = ~~(arr.length / 2); + return merge(mergeSort(arr.slice(0, mid)), mergeSort(arr.slice(mid))); + } + function merge(a, b) { + let r = []; + let cnt = 0; + while (a && b && a.length && b.length) { + if (a[0] <= b[0]) { + res += cnt; + r.push(a.shift()); + } else { + r.push(b.shift()); + cnt++; + } } - mergeSort(nums) - return res -}; \ No newline at end of file + res += a.length * cnt; + return r.concat(a, b); + } + mergeSort(nums); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" index 2fa4007b49d7b..b728a1e9a29e9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" @@ -1,6 +1,7 @@ -# [面试题52. 两个链表的第一个公共节点](https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/) +# [面试题 52. 两个链表的第一个公共节点](https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/) ## 题目描述 + 输入两个链表,找出它们的第一个公共节点。 如下面的两个链表: @@ -19,7 +20,7 @@ 输入解释:相交节点的值为 8 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。 ``` -**示例 2:** +**示例  2:** ![](./images/160_example_2.png) @@ -29,7 +30,7 @@ 输入解释:相交节点的值为 2 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。 ``` -**示例 3:** +**示例  3:** ![](./images/160_example_3.png) @@ -56,6 +57,7 @@ ### **Python3** + ```python # Definition for singly-linked list. # class ListNode: @@ -85,10 +87,11 @@ class Solution: return p p = p.next q = q.next - + ``` ### **Java** + ```java /** * Definition for singly-linked list. @@ -140,6 +143,7 @@ public class Solution { ``` ### **JavaScript** + ```js /** * Definition for singly-linked list. @@ -154,20 +158,21 @@ public class Solution { * @param {ListNode} headB * @return {ListNode} */ -var getIntersectionNode = function(headA, headB) { - let h1 = headA - let h2 = headB - while(h1 !== h2) { - h1 = h1 === null ? headB : h1.next - h2 = h2 === null ? headA : h2.next - } - return h2 +var getIntersectionNode = function (headA, headB) { + let h1 = headA; + let h2 = headB; + while (h1 !== h2) { + h1 = h1 === null ? headB : h1.next; + h2 = h2 === null ? headA : h2.next; + } + return h2; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.js" index 25e09a1d3e1fc..af5703f7dfcdd 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.js" @@ -11,12 +11,12 @@ * @param {ListNode} headB * @return {ListNode} */ -var getIntersectionNode = function(headA, headB) { - let h1 = headA - let h2 = headB - while(h1 !== h2) { - h1 = h1 === null ? headB : h1.next - h2 = h2 === null ? headA : h2.next - } - return h2 -}; \ No newline at end of file +var getIntersectionNode = function (headA, headB) { + let h1 = headA; + let h2 = headB; + while (h1 !== h2) { + h1 = h1 === null ? headB : h1.next; + h2 = h2 === null ? headA : h2.next; + } + return h2; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" index 507550ee0673b..494ef07c09671 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" @@ -1,6 +1,7 @@ -# [面试题53 - I. 在排序数组中查找数字 I](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) +# [面试题 53 - I. 在排序数组中查找数字 I](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) ## 题目描述 + 统计一个数字在排序数组中出现的次数。 **示例 1:** @@ -10,7 +11,7 @@ 输出: 2 ``` -**示例 2:** +**示例  2:** ``` 输入: nums = [5,7,7,8,8,10], target = 6 @@ -22,9 +23,11 @@ - `0 <= 数组长度 <= 50000` ## 解法 + ### **Python3** + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -40,7 +43,7 @@ class Solution: else: r = m - 1 return 0 - + def _count(self, nums, l, r, m) -> int: cnt = 0 for i in range(m, l - 1, -1): @@ -48,7 +51,7 @@ class Solution: cnt += 1 elif nums[i] < nums[m]: break - + for i in range(m + 1, r + 1): if nums[i] == nums[m]: cnt += 1 @@ -58,6 +61,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int search(int[] nums, int target) { @@ -101,44 +105,45 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @param {number} target * @return {number} */ -var search = function(nums, target) { - if(!nums || !nums.length) return 0 - let left = 0 - let right = nums.length - 1 - let res = 0 - while(left < right) { - let mid = left + ~~((right-left)/2) - if(nums[mid] < target) { - left = mid + 1 - } else if(nums[mid] > target) { - right = mid - } else { - left = mid - right = mid - break - } - } - while(nums[left] === target) { - res++ - left-- +var search = function (nums, target) { + if (!nums || !nums.length) return 0; + let left = 0; + let right = nums.length - 1; + let res = 0; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (nums[mid] < target) { + left = mid + 1; + } else if (nums[mid] > target) { + right = mid; + } else { + left = mid; + right = mid; + break; } - while(nums[++right] === target) { - res++ - } - return res - + } + while (nums[left] === target) { + res++; + left--; + } + while (nums[++right] === target) { + res++; + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/Solution.js" index 2e5b814db3d75..3b20973993b19 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/Solution.js" @@ -3,30 +3,29 @@ * @param {number} target * @return {number} */ -var search = function(nums, target) { - if(!nums || !nums.length) return 0 - let left = 0 - let right = nums.length - 1 - let res = 0 - while(left < right) { - let mid = left + ~~((right-left)/2) - if(nums[mid] < target) { - left = mid + 1 - } else if(nums[mid] > target) { - right = mid - } else { - left = mid - right = mid - break - } +var search = function (nums, target) { + if (!nums || !nums.length) return 0; + let left = 0; + let right = nums.length - 1; + let res = 0; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (nums[mid] < target) { + left = mid + 1; + } else if (nums[mid] > target) { + right = mid; + } else { + left = mid; + right = mid; + break; } - while(nums[left] === target) { - res++ - left-- - } - while(nums[++right] === target) { - res++ - } - return res - -}; \ No newline at end of file + } + while (nums[left] === target) { + res++; + left--; + } + while (nums[++right] === target) { + res++; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" index 939c223f2ab0f..54cf567fe27a9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" @@ -1,7 +1,8 @@ -# [面试题53 - II. 0~n-1中缺失的数字](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) +# [面试题 53 - II. 0 ~ n-1 中缺失的数字](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) ## 题目描述 -一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围0~n-1之内。在范围0~n-1内的n个数字中有且只有一个数字不在该数组中,请找出这个数字。 + +一个长度为 n-1 的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围 0 ~ n-1 之内。在范围 0 ~ n-1 内的 n 个数字中有且只有一个数字不在该数组中,请找出这个数字。 **示例 1:** @@ -10,7 +11,7 @@ 输出: 2 ``` -**示例 2:** +**示例  2:** ``` 输入: [0,1,2,3,4,5,6,7,9] @@ -22,11 +23,13 @@ - `1 <= 数组长度 <= 10000` ## 解法 + 二分法。 ### **Python3** + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -45,6 +48,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int missingNumber(int[] nums) { @@ -69,30 +73,32 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var missingNumber = function(nums) { - if(!nums || !nums.length) return 0 - let left = 0 - let right = nums.length-1 - while(left < right) { - let mid = left + ~~((right - left)/2) - if(nums[mid] !== mid) { - right = mid - } else { - left = mid + 1 - } +var missingNumber = function (nums) { + if (!nums || !nums.length) return 0; + let left = 0; + let right = nums.length - 1; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (nums[mid] !== mid) { + right = mid; + } else { + left = mid + 1; } - return nums[left] === left ? nums.length : left + } + return nums[left] === left ? nums.length : left; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/Solution.js" index 08d2554a7f3dd..6a0336974fbcb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/Solution.js" @@ -2,17 +2,17 @@ * @param {number[]} nums * @return {number} */ -var missingNumber = function(nums) { - if(!nums || !nums.length) return 0 - let left = 0 - let right = nums.length-1 - while(left < right) { - let mid = left + ~~((right - left)/2) - if(nums[mid] !== mid) { - right = mid - } else { - left = mid + 1 - } +var missingNumber = function (nums) { + if (!nums || !nums.length) return 0; + let left = 0; + let right = nums.length - 1; + while (left < right) { + let mid = left + ~~((right - left) / 2); + if (nums[mid] !== mid) { + right = mid; + } else { + left = mid + 1; } - return nums[left] === left ? nums.length : left -}; \ No newline at end of file + } + return nums[left] === left ? nums.length : left; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" index ba35cd80b0484..bded8d61d63bd 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" @@ -1,7 +1,8 @@ -# [面试题54. 二叉搜索树的第k大节点](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) +# [面试题 54. 二叉搜索树的第 k 大节点](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) ## 题目描述 -给定一棵二叉搜索树,请找出其中第k大的节点。 + +给定一棵二叉搜索树,请找出其中第 k 大的节点。 **示例 1:** @@ -34,12 +35,13 @@ - `1 ≤ k ≤ 二叉搜索树元素个数` ## 解法 -先遍历右子树,访问根节点,再遍历左子树。遍历到第 k 个结点时,存储结果。 +先遍历右子树,访问根节点,再遍历左子树。遍历到第 k 个结点时,存储结果。 ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -66,6 +68,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -100,6 +103,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -113,23 +117,24 @@ class Solution { * @param {number} k * @return {number} */ -var kthLargest = function(root, k) { - let res - let t = 0 - function traversal(node) { - if(!node) return - traversal(node.right) - if(++t === k) res = node.val - traversal(node.left) - } - traversal(root) - return res +var kthLargest = function (root, k) { + let res; + let t = 0; + function traversal(node) { + if (!node) return; + traversal(node.right); + if (++t === k) res = node.val; + traversal(node.left); + } + traversal(root); + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.js" index 7a36bfe0f8682..55cf9716ef94d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.js" @@ -10,15 +10,15 @@ * @param {number} k * @return {number} */ -var kthLargest = function(root, k) { - let res - let t = 0 - function traversal(node) { - if(!node) return - traversal(node.right) - if(++t === k) res = node.val - traversal(node.left) - } - traversal(root) - return res -}; \ No newline at end of file +var kthLargest = function (root, k) { + let res; + let t = 0; + function traversal(node) { + if (!node) return; + traversal(node.right); + if (++t === k) res = node.val; + traversal(node.left); + } + traversal(root); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" index 7d169a6ed5be9..aa50ea644964f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" @@ -1,6 +1,7 @@ -# [面试题55 - I. 二叉树的深度](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) +# [面试题 55 - I. 二叉树的深度](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) ## 题目描述 + 输入一棵二叉树的根节点,求该树的深度。从根节点到叶节点依次经过的节点(含根、叶节点)形成树的一条路径,最长路径的长度为树的深度。 例如: @@ -15,16 +16,18 @@ 15 7 ``` -返回它的最大深度 3 。 +返回它的最大深度  3 。 **提示:** - `节点总数 <= 10000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -41,6 +44,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -62,6 +66,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -74,24 +79,25 @@ class Solution { * @param {TreeNode} root * @return {number} */ -var maxDepth = function(root) { - let res = 0 - function traversal(node, depth) { - if(!node){ - res = Math.max(res, depth) - return - } - traversal(node.left,depth+1) - traversal(node.right,depth+1) +var maxDepth = function (root) { + let res = 0; + function traversal(node, depth) { + if (!node) { + res = Math.max(res, depth); + return; } - traversal(root,0) - return res + traversal(node.left, depth + 1); + traversal(node.right, depth + 1); + } + traversal(root, 0); + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.js" index 998c527f08bae..5d4a90fa9efcc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.js" @@ -9,16 +9,16 @@ * @param {TreeNode} root * @return {number} */ -var maxDepth = function(root) { - let res = 0 - function traversal(node, depth) { - if(!node){ - res = Math.max(res, depth) - return - } - traversal(node.left,depth+1) - traversal(node.right,depth+1) +var maxDepth = function (root) { + let res = 0; + function traversal(node, depth) { + if (!node) { + res = Math.max(res, depth); + return; } - traversal(root,0) - return res -}; \ No newline at end of file + traversal(node.left, depth + 1); + traversal(node.right, depth + 1); + } + traversal(root, 0); + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" index 8a4d45638467f..2451ccffacd19 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" @@ -1,6 +1,7 @@ -# [面试题55 - II. 平衡二叉树](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) +# [面试题 55 - II. 平衡二叉树](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) ## 题目描述 + 输入一棵二叉树的根节点,判断该树是不是平衡二叉树。如果某二叉树中任意节点的左右子树的深度相差不超过 1,那么它就是一棵平衡二叉树。 **示例 1:** @@ -31,16 +32,18 @@ 4 4 ``` -返回 `false`。 +返回  `false`。 **限制:** - `1 <= 树的结点个数 <= 10000` ## 解法 + ### **Python3** + ```python # Definition for a binary tree node. # class TreeNode: @@ -62,6 +65,7 @@ class Solution: ``` ### **Java** + ```java /** * Definition for a binary tree node. @@ -90,6 +94,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -102,22 +107,23 @@ class Solution { * @param {TreeNode} root * @return {boolean} */ -var isBalanced = function(root) { - if(!root) return true - if(!isBalanced(root.left) || !isBalanced(root.right)) return false - if(Math.abs(getDepth(root.left)-getDepth(root.right)) > 1) return false - return true +var isBalanced = function (root) { + if (!root) return true; + if (!isBalanced(root.left) || !isBalanced(root.right)) return false; + if (Math.abs(getDepth(root.left) - getDepth(root.right)) > 1) return false; + return true; }; function getDepth(node) { - if(!node) return 0 - return Math.max(getDepth(node.left),getDepth(node.right)) + 1 + if (!node) return 0; + return Math.max(getDepth(node.left), getDepth(node.right)) + 1; } ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" index abf20759e1956..05db6eafc01a4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" @@ -9,14 +9,14 @@ * @param {TreeNode} root * @return {boolean} */ -var isBalanced = function(root) { - if(!root) return true - if(!isBalanced(root.left) || !isBalanced(root.right)) return false - if(Math.abs(getDepth(root.left)-getDepth(root.right)) > 1) return false - return true +var isBalanced = function (root) { + if (!root) return true; + if (!isBalanced(root.left) || !isBalanced(root.right)) return false; + if (Math.abs(getDepth(root.left) - getDepth(root.right)) > 1) return false; + return true; }; function getDepth(node) { - if(!node) return 0 - return Math.max(getDepth(node.left),getDepth(node.right)) + 1 -} \ No newline at end of file + if (!node) return 0; + return Math.max(getDepth(node.left), getDepth(node.right)) + 1; +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" index b2cba4a3fef90..073bf8f0ebc5c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" @@ -1,7 +1,8 @@ -# [面试题56 - I. 数组中数字出现的次数](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) +# [面试题 56 - I. 数组中数字出现的次数](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) ## 题目描述 -一个整型数组 nums 里除两个数字之外,其他数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度是O(n),空间复杂度是O(1)。 + +一个整型数组 nums 里除两个数字之外,其他数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度是 O(n),空间复杂度是 O(1)。 **示例 1:** @@ -22,14 +23,15 @@ - `2 <= nums <= 10000` ## 解法 + 异或运算求解。 首先明确,两个相同的数异或之后的结果为 0。对该数组所有元素进行异或运算,结果就是**两个只出现一次的数字异或的结果**。找出这个结果中某个二进制位为 1 的位置,之后对数组所有元素进行分类,二进制位为 0 的异或到 a,二进制位为 1 的异或到 b,结果就是 a,b。 - ### **Python3** + ```python class Solution: def singleNumbers(self, nums: List[int]) -> List[int]: @@ -40,7 +42,7 @@ class Solution: while (xor_res & 1) == 0: pos += 1 xor_res >>= 1 - + a = b = 0 for num in nums: t = num >> pos @@ -52,6 +54,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int[] singleNumbers(int[] nums) { @@ -79,36 +82,38 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number[]} */ -var singleNumbers = function(nums) { - let xor = 0 - let bit = 1 - let res = [0,0] - for(let num of nums) { - xor ^= num - } - while((xor & 1) === 0) { - xor >>= 1 - bit <<= 1 +var singleNumbers = function (nums) { + let xor = 0; + let bit = 1; + let res = [0, 0]; + for (let num of nums) { + xor ^= num; + } + while ((xor & 1) === 0) { + xor >>= 1; + bit <<= 1; + } + for (let num of nums) { + if ((num & bit) === 0) { + res[0] ^= num; + } else { + res[1] ^= num; } - for(let num of nums) { - if((num & bit) === 0) { - res[0] ^= num - } else { - res[1] ^= num - } - } - return res + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" index f978b6f6fa9bf..edc9f367e86d6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" @@ -2,23 +2,23 @@ * @param {number[]} nums * @return {number[]} */ -var singleNumbers = function(nums) { - let xor = 0 - let bit = 1 - let res = [0,0] - for(let num of nums) { - xor ^= num +var singleNumbers = function (nums) { + let xor = 0; + let bit = 1; + let res = [0, 0]; + for (let num of nums) { + xor ^= num; + } + while ((xor & 1) === 0) { + xor >>= 1; + bit <<= 1; + } + for (let num of nums) { + if ((num & bit) === 0) { + res[0] ^= num; + } else { + res[1] ^= num; } - while((xor & 1) === 0) { - xor >>= 1 - bit <<= 1 - } - for(let num of nums) { - if((num & bit) === 0) { - res[0] ^= num - } else { - res[1] ^= num - } - } - return res -}; \ No newline at end of file + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" index 831953df02266..c27ec70fee5dc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" @@ -1,6 +1,7 @@ -# [面试题56 - II. 数组中数字出现的次数 II](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) +# [面试题 56 - II. 数组中数字出现的次数 II](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) ## 题目描述 + 在一个数组 `nums` 中除一个数字只出现一次之外,其他数字都出现了三次。请找出那个只出现一次的数字。 **示例 1:** @@ -26,10 +27,10 @@ 统计所有数字每个位中 1 出现的次数,对于某个位,1 出现的次数一定是 3 的倍数 +1 或 0。对这个数 %3 得到的结果就是那个出现一次的数字在该位上的值。 - ### **Python3** + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -46,6 +47,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int singleNumber(int[] nums) { @@ -68,25 +70,27 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {number} */ -var singleNumber = function(nums) { - let a = 0 - let b = 0 - for(let num of nums) { - a = (a ^ num) & ~b - b = (b ^ num) & ~a - } - return a +var singleNumber = function (nums) { + let a = 0; + let b = 0; + for (let num of nums) { + a = (a ^ num) & ~b; + b = (b ^ num) & ~a; + } + return a; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" index 54ae19d5437e5..104282b48a0e7 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" @@ -2,12 +2,12 @@ * @param {number[]} nums * @return {number} */ -var singleNumber = function(nums) { - let a = 0 - let b = 0 - for(let num of nums) { - a = (a ^ num) & ~b - b = (b ^ num) & ~a - } - return a -}; \ No newline at end of file +var singleNumber = function (nums) { + let a = 0; + let b = 0; + for (let num of nums) { + a = (a ^ num) & ~b; + b = (b ^ num) & ~a; + } + return a; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" index 7ce9a737185a2..9a13f2fbcac15 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" @@ -1,6 +1,7 @@ -# [面试题57 - II. 和为s的连续正数序列](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) +# [面试题 57 - II. 和为 s 的连续正数序列](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) ## 题目描述 + 输入一个正整数 `target` ,输出所有和为 `target` 的连续正整数序列(至少含有两个数)。 序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。 @@ -24,11 +25,13 @@ - `1 <= target <= 10^5` ## 解法 + 双指针:`p = 1`,`q = 2`。 ### **Python3** + ```python class Solution: def findContinuousSequence(self, target: int) -> List[List[int]]: @@ -43,10 +46,11 @@ class Solution: q += 1 else: p += 1 - return res + return res ``` ### **Java** + ```java class Solution { public int[][] findContinuousSequence(int target) { @@ -77,40 +81,42 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} target * @return {number[][]} */ -var findContinuousSequence = function(target) { - let res = [] - let window = [] - let i = 1 - let sum = 0 - while(1) { - if(sum < target) { - window.push(i) - sum += i - i++ - } else if(sum > target) { - let a = window.shift() - if(window.length < 2) break - sum -= a - } else { - res.push([...window]) - window.push(i) - sum += i - i++ - if(window.length === 2) break - } +var findContinuousSequence = function (target) { + let res = []; + let window = []; + let i = 1; + let sum = 0; + while (1) { + if (sum < target) { + window.push(i); + sum += i; + i++; + } else if (sum > target) { + let a = window.shift(); + if (window.length < 2) break; + sum -= a; + } else { + res.push([...window]); + window.push(i); + sum += i; + i++; + if (window.length === 2) break; } - return res + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/Solution.js" index 10047a40453e4..83491c4e9994a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/Solution.js" @@ -2,27 +2,27 @@ * @param {number} target * @return {number[][]} */ -var findContinuousSequence = function(target) { - let res = [] - let window = [] - let i = 1 - let sum = 0 - while(1) { - if(sum < target) { - window.push(i) - sum += i - i++ - } else if(sum > target) { - let a = window.shift() - if(window.length < 2) break - sum -= a - } else { - res.push([...window]) - window.push(i) - sum += i - i++ - if(window.length === 2) break - } +var findContinuousSequence = function (target) { + let res = []; + let window = []; + let i = 1; + let sum = 0; + while (1) { + if (sum < target) { + window.push(i); + sum += i; + i++; + } else if (sum > target) { + let a = window.shift(); + if (window.length < 2) break; + sum -= a; + } else { + res.push([...window]); + window.push(i); + sum += i; + i++; + if (window.length === 2) break; } - return res -}; \ No newline at end of file + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" index 0479247e98466..395eb4ec43fed 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" @@ -1,6 +1,7 @@ -# [面试题57. 和为s的两个数字](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) +# [面试题 57. 和为 s 的两个数字](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) ## 题目描述 + 输入一个递增排序的数组和一个数字 s,在数组中查找两个数,使得它们的和正好是 s。如果有多对数字的和等于 s,则输出任意一对即可。 **示例 1:** @@ -20,12 +21,14 @@ **限制:** - `1 <= nums.length <= 10^5` -- `1 <= nums[i] <= 10^6` +- `1 <= nums[i] <= 10^6` ## 解法 + ### **Python3** + ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: @@ -34,14 +37,15 @@ class Solution: s = nums[p] + nums[q] if s == target: return [nums[p], nums[q]] - if s < target: + if s < target: p += 1 - else: + else: q -= 1 ``` ### **Java** + ```java class Solution { public int[] twoSum(int[] nums, int target) { @@ -63,32 +67,33 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @param {number} target * @return {number[]} */ -var twoSum = function(nums, target) { - let left = 0 - let right = nums.length - 1 - while(left < right) { - let sum = nums[left] + nums[right] - if(sum === target) { - return [nums[left],nums[right]] - } else if(sum > target) { - right-- - } else { - left++ - } +var twoSum = function (nums, target) { + let left = 0; + let right = nums.length - 1; + while (left < right) { + let sum = nums[left] + nums[right]; + if (sum === target) { + return [nums[left], nums[right]]; + } else if (sum > target) { + right--; + } else { + left++; } - + } }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/Solution.js" index 5c1f4f6bff38e..9964e4dca2588 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/Solution.js" @@ -3,18 +3,17 @@ * @param {number} target * @return {number[]} */ -var twoSum = function(nums, target) { - let left = 0 - let right = nums.length - 1 - while(left < right) { - let sum = nums[left] + nums[right] - if(sum === target) { - return [nums[left],nums[right]] - } else if(sum > target) { - right-- - } else { - left++ - } +var twoSum = function (nums, target) { + let left = 0; + let right = nums.length - 1; + while (left < right) { + let sum = nums[left] + nums[right]; + if (sum === target) { + return [nums[left], nums[right]]; + } else if (sum > target) { + right--; + } else { + left++; } - -}; \ No newline at end of file + } +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" index 3dbb81d8c0b5b..9c286c7eeed18 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" @@ -1,6 +1,7 @@ -# [面试题58 - I. 翻转单词顺序](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/) +# [面试题 58 - I. 翻转单词顺序](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/) ## 题目描述 + 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。为简单起见,标点符号和普通字母一样处理。例如输入字符串"I am a student. ",则输出"student. a am I"。 **示例 1:** @@ -37,11 +38,13 @@ **注意:** 此题对比原题有改动 ## 解法 + 按空格分割字符串后逆序。 ### **Python3** + ```python class Solution: def reverseWords(self, s: str) -> str: @@ -51,6 +54,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public String reverseWords(String s) { @@ -73,19 +77,25 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @return {string} */ -var reverseWords = function(s) { - return s.split(' ').reduce((acc,cur)=>cur !== '' ? acc.concat(cur) : acc,[]).reverse().join(' ') +var reverseWords = function (s) { + return s + .split(" ") + .reduce((acc, cur) => (cur !== "" ? acc.concat(cur) : acc), []) + .reverse() + .join(" "); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" index 97c9f7b79c8cf..5b6b16a3fdb2a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" @@ -2,6 +2,10 @@ * @param {string} s * @return {string} */ -var reverseWords = function(s) { - return s.split(' ').reduce((acc,cur)=>cur !== '' ? acc.concat(cur) : acc,[]).reverse().join(' ') -}; \ No newline at end of file +var reverseWords = function (s) { + return s + .split(" ") + .reduce((acc, cur) => (cur !== "" ? acc.concat(cur) : acc), []) + .reverse() + .join(" "); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" index 16d6b3660f90f..df721e120a2e1 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" @@ -1,7 +1,8 @@ -# [面试题58 - II. 左旋转字符串](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) +# [面试题 58 - II. 左旋转字符串](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) ## 题目描述 -字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。 + +字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字 2,该函数将返回左旋转两位得到的结果"cdefgab"。 **示例 1:** @@ -22,9 +23,11 @@ - `1 <= k < s.length <= 10000` ## 解法 + ### **Python3** + ```python class Solution: def reverseLeftWords(self, s: str, n: int) -> str: @@ -33,6 +36,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public String reverseLeftWords(String s, int n) { @@ -44,20 +48,22 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} s * @param {number} n * @return {string} */ -var reverseLeftWords = function(s, n) { - return s.substring(n) + s.substr(0,n) +var reverseLeftWords = function (s, n) { + return s.substring(n) + s.substr(0, n); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/Solution.js" index f281cdf5dd656..c6f9f5293266b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/Solution.js" @@ -3,6 +3,6 @@ * @param {number} n * @return {string} */ -var reverseLeftWords = function(s, n) { - return s.substring(n) + s.substr(0,n) -}; \ No newline at end of file +var reverseLeftWords = function (s, n) { + return s.substring(n) + s.substr(0, n); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index a3627edfb3cc0..84884323b73de 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -1,15 +1,17 @@ -# [面试题59 - I. 滑动窗口的最大值](https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) +# [面试题 59 - I. 滑动窗口的最大值](https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) ## 题目描述 + + 给定一个数组 `nums` 和滑动窗口的大小 `k`,请找出所有滑动窗口里的最大值。 **示例:** ``` 输入: nums = [1,3,-1,-3,5,3,6,7], 和 k = 3 -输出: [3,3,5,5,6,7] -解释: +输出: [3,3,5,5,6,7] +解释: 滑动窗口的位置 最大值 --------------- ----- @@ -23,17 +25,20 @@ **提示:** -- 你可以假设 k 总是有效的,在输入数组不为空的情况下,`1 ≤ k ≤ 输入数组的大小`。 +- 你可以假设 k 总是有效的,在输入数组不为空的情况下,`1 ≤ k ≤ 输入数组的大小`。 注意:本题与主站 239 题相同:https://leetcode-cn.com/problems/sliding-window-maximum/ ## 解法 + + 双端队列实现。 ### **Python3** + ```python @@ -54,6 +59,7 @@ class Solution: ``` ### **Java** + ```java @@ -83,41 +89,43 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @param {number} k * @return {number[]} */ -var maxSlidingWindow = function(nums, k) { - if(!nums.length || !k) return [] - if(k === 1) return nums - let res = [] - let tmpMax = -Infinity - let len = nums.length - let window = [] - for(let i=0;i tmpMax) { + tmpMax = nums[i]; + } else if (tmpMax === a) { + tmpMax = Math.max(...window); } - res.push(tmpMax) - for(let i=k;i tmpMax) { - tmpMax = nums[i] - } else if(tmpMax === a) { - tmpMax = Math.max(...window) - } - res.push(tmpMax) - } - return res + res.push(tmpMax); + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" index ee423b6aab269..9e45e78c35ec6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" @@ -3,27 +3,27 @@ * @param {number} k * @return {number[]} */ -var maxSlidingWindow = function(nums, k) { - if(!nums.length || !k) return [] - if(k === 1) return nums - let res = [] - let tmpMax = -Infinity - let len = nums.length - let window = [] - for(let i=0;i tmpMax) { + tmpMax = nums[i]; + } else if (tmpMax === a) { + tmpMax = Math.max(...window); } - res.push(tmpMax) - for(let i=k;i tmpMax) { - tmpMax = nums[i] - } else if(tmpMax === a) { - tmpMax = Math.max(...window) - } - res.push(tmpMax) - } - return res -}; \ No newline at end of file + res.push(tmpMax); + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index 577c5227739c2..c29b486d173cb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -1,15 +1,17 @@ -# [面试题59 - II. 队列的最大值](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) +# [面试题 59 - II. 队列的最大值](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) ## 题目描述 + -请定义一个队列并实现函数 `max_value` 得到队列里的最大值,要求函数`max_value`、`push_back` 和 `pop_front` 的**均摊**时间复杂度都是O(1)。 -若队列为空,`pop_front` 和 `max_value` 需要返回 -1 +请定义一个队列并实现函数 `max_value` 得到队列里的最大值,要求函数`max_value`、`push_back` 和 `pop_front` 的**均摊**时间复杂度都是 O(1)。 + +若队列为空,`pop_front` 和 `max_value`  需要返回 -1 **示例 1:** ``` -输入: +输入: ["MaxQueue","push_back","push_back","max_value","pop_front","max_value"] [[],[1],[2],[],[],[]] 输出: [null,null,null,2,1,2] @@ -18,7 +20,7 @@ **示例 2:** ``` -输入: +输入: ["MaxQueue","pop_front","max_value"] [[],[],[]] 输出: [null,-1,-1] @@ -30,15 +32,17 @@ - `1 <= value <= 10^5` ## 解法 + 利用一个辅助队列按单调顺序存储当前队列的最大值。 - ### **Python3** + + ```python class MaxQueue: @@ -54,7 +58,7 @@ class MaxQueue: self.q.pop(-1) self.q.append(value) self.p.append(value) - + def pop_front(self) -> int: if not self.p: return -1 @@ -65,7 +69,9 @@ class MaxQueue: ``` ### **Java** + + ```java class MaxQueue { @@ -75,11 +81,11 @@ class MaxQueue { public MaxQueue() { } - + public int max_value() { return q.isEmpty() ? -1 : q.peekFirst(); } - + public void push_back(int value) { while (!q.isEmpty() && q.peekLast() < value) { q.pollLast(); @@ -87,7 +93,7 @@ class MaxQueue { q.addLast(value); p.add(value); } - + public int pop_front() { if (p.isEmpty()) { return -1; @@ -110,59 +116,61 @@ class MaxQueue { ``` ### **JavaScript** + ```js -var MaxQueue = function() { - this.queue = [] - this.maxValue = -Infinity - this.maxIdx = -1 +var MaxQueue = function () { + this.queue = []; + this.maxValue = -Infinity; + this.maxIdx = -1; }; /** * @return {number} */ -MaxQueue.prototype.max_value = function() { - if(!this.queue.length) return -1 - return this.maxValue +MaxQueue.prototype.max_value = function () { + if (!this.queue.length) return -1; + return this.maxValue; }; -/** +/** * @param {number} value * @return {void} */ -MaxQueue.prototype.push_back = function(value) { - this.queue.push(value) - if(value >= this.maxValue) { - this.maxIdx = this.queue.length-1 - this.maxValue = value - } +MaxQueue.prototype.push_back = function (value) { + this.queue.push(value); + if (value >= this.maxValue) { + this.maxIdx = this.queue.length - 1; + this.maxValue = value; + } }; /** * @return {number} */ -MaxQueue.prototype.pop_front = function() { - if(!this.queue.length) return -1 - let a = this.queue.shift() - this.maxIdx-- - if(this.maxIdx < 0) { - let tmp = -Infinity - let id = -1 - for(let i=0;i tmp) { - tmp = this.queue[i] - id = i - } - } - this.maxIdx = id - this.maxValue = tmp +MaxQueue.prototype.pop_front = function () { + if (!this.queue.length) return -1; + let a = this.queue.shift(); + this.maxIdx--; + if (this.maxIdx < 0) { + let tmp = -Infinity; + let id = -1; + for (let i = 0; i < this.queue.length; i++) { + if (this.queue[i] > tmp) { + tmp = this.queue[i]; + id = i; + } } - return a + this.maxIdx = id; + this.maxValue = tmp; + } + return a; }; ``` - ### **...** + ``` ``` - \ No newline at end of file + + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" index 953dd6196945c..bdedb1b8133cc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" @@ -1,47 +1,47 @@ -var MaxQueue = function() { - this.queue = [] - this.maxValue = -Infinity - this.maxIdx = -1 +var MaxQueue = function () { + this.queue = []; + this.maxValue = -Infinity; + this.maxIdx = -1; }; /** * @return {number} */ -MaxQueue.prototype.max_value = function() { - if(!this.queue.length) return -1 - return this.maxValue +MaxQueue.prototype.max_value = function () { + if (!this.queue.length) return -1; + return this.maxValue; }; -/** +/** * @param {number} value * @return {void} */ -MaxQueue.prototype.push_back = function(value) { - this.queue.push(value) - if(value >= this.maxValue) { - this.maxIdx = this.queue.length-1 - this.maxValue = value - } +MaxQueue.prototype.push_back = function (value) { + this.queue.push(value); + if (value >= this.maxValue) { + this.maxIdx = this.queue.length - 1; + this.maxValue = value; + } }; /** * @return {number} */ -MaxQueue.prototype.pop_front = function() { - if(!this.queue.length) return -1 - let a = this.queue.shift() - this.maxIdx-- - if(this.maxIdx < 0) { - let tmp = -Infinity - let id = -1 - for(let i=0;i tmp) { - tmp = this.queue[i] - id = i - } - } - this.maxIdx = id - this.maxValue = tmp +MaxQueue.prototype.pop_front = function () { + if (!this.queue.length) return -1; + let a = this.queue.shift(); + this.maxIdx--; + if (this.maxIdx < 0) { + let tmp = -Infinity; + let id = -1; + for (let i = 0; i < this.queue.length; i++) { + if (this.queue[i] > tmp) { + tmp = this.queue[i]; + id = i; + } } - return a -}; \ No newline at end of file + this.maxIdx = id; + this.maxValue = tmp; + } + return a; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" index e77352ce93b18..11bed5d7e434e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" @@ -1,8 +1,10 @@ -# [面试题60. n个骰子的点数](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) +# [面试题 60. n 个骰子的点数](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) ## 题目描述 + -把n个骰子扔在地上,所有骰子朝上一面的点数之和为s。输入n,打印出s的所有可能的值出现的概率。 + +把 n 个骰子扔在地上,所有骰子朝上一面的点数之和为 s。输入 n,打印出 s 的所有可能的值出现的概率。 你需要用一个浮点数数组返回答案,其中第 i 个元素代表这 n 个骰子所能掷出的点数集合中第 i 小的那个的概率。 @@ -13,7 +15,7 @@ 输出: [0.16667,0.16667,0.16667,0.16667,0.16667,0.16667] ``` -**示例 2:** +**示例  2:** ``` 输入: 2 @@ -25,7 +27,9 @@ - `1 <= n <= 11` ## 解法 + + 动态规划求解。 扔 n 个骰子,点数之和的范围在 `[n, 6n]` 之间,总共有 `5n+1` 种,即为最后结果数组的长度。 @@ -51,6 +55,7 @@ for (int j = 1; j <= 6; ++j) { ### **Python3** + ```python @@ -72,6 +77,7 @@ class Solution: ``` ### **Java** + ```java @@ -99,32 +105,34 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number[]} */ -var twoSum = function(n) { - function backtrack(sum,time) { - if(time === n) { - res[sum]++ - return - } - for(let i=1;i<=6;i++) { - backtrack(sum+i,time+1) - } +var twoSum = function (n) { + function backtrack(sum, time) { + if (time === n) { + res[sum]++; + return; } - let len = n*6 - let t = 6**n - let res = new Array(len+1).fill(0) - backtrack(0,0) - return res.slice(n).map(e=> e/t) + for (let i = 1; i <= 6; i++) { + backtrack(sum + i, time + 1); + } + } + let len = n * 6; + let t = 6 ** n; + let res = new Array(len + 1).fill(0); + backtrack(0, 0); + return res.slice(n).map((e) => e / t); }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" index 7c923bcd542b2..e742a32dd868f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" @@ -2,19 +2,19 @@ * @param {number} n * @return {number[]} */ -var twoSum = function(n) { - function backtrack(sum,time) { - if(time === n) { - res[sum]++ - return - } - for(let i=1;i<=6;i++) { - backtrack(sum+i,time+1) - } +var twoSum = function (n) { + function backtrack(sum, time) { + if (time === n) { + res[sum]++; + return; } - let len = n*6 - let t = 6**n - let res = new Array(len+1).fill(0) - backtrack(0,0) - return res.slice(n).map(e=> e/t) -}; \ No newline at end of file + for (let i = 1; i <= 6; i++) { + backtrack(sum + i, time + 1); + } + } + let len = n * 6; + let t = 6 ** n; + let res = new Array(len + 1).fill(0); + backtrack(0, 0); + return res.slice(n).map((e) => e / t); +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" index 7c0e4b5446f5e..03e8b9b5f6574 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" @@ -1,17 +1,19 @@ -# [面试题61. 扑克牌中的顺子](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) +# [面试题 61. 扑克牌中的顺子](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) ## 题目描述 + -从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的。2~10为数字本身,A为1,J为11,Q为12,K为13,而大、小王为 0 ,可以看成任意数字。A 不能视为 14。 -**示例 1:** +从扑克牌中随机抽 5 张牌,判断是不是一个顺子,即这 5 张牌是不是连续的。2 ~ 10 为数字本身,A 为 1,J 为 11,Q 为 12,K 为 13,而大、小王为 0 ,可以看成任意数字。A 不能视为 14。 + +**示例  1:** ``` 输入: [1,2,3,4,5] 输出: True ``` -**示例 2:** +**示例  2:** ``` 输入: [0,0,1,2,5] @@ -20,10 +22,11 @@ **限制:** -- 数组长度为 5  +- 数组长度为 5 - 数组的数取值为 `[0, 13]` ## 解法 + 用数组 t 记录是否存在重复的数,存在则直接返回 false。 @@ -33,6 +36,7 @@ ### **Python3** + ```python @@ -54,6 +58,7 @@ class Solution: ``` ### **Java** + ```java @@ -78,35 +83,37 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} nums * @return {boolean} */ -var isStraight = function(nums) { - let zeroCnt = 0 - nums.sort((a,b)=>a-b) - for(let i=0;i= nums[i+1] - zeroCnt - 1) { - zeroCnt-- - } else { - return false - } - } - if(zeroCnt < 0) return false +var isStraight = function (nums) { + let zeroCnt = 0; + nums.sort((a, b) => a - b); + for (let i = 0; i < nums.length - 1; i++) { + if (nums[i] === 0) zeroCnt++; + else { + if (nums[i] === nums[i + 1]) return false; + else if (nums[i] === nums[i + 1] - 1) { + continue; + } else if (nums[i] >= nums[i + 1] - zeroCnt - 1) { + zeroCnt--; + } else { + return false; + } } - return true + if (zeroCnt < 0) return false; + } + return true; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" index 537fcd3807ecc..1fe7185d4bc44 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" @@ -2,22 +2,22 @@ * @param {number[]} nums * @return {boolean} */ -var isStraight = function(nums) { - let zeroCnt = 0 - nums.sort((a,b)=>a-b) - for(let i=0;i= nums[i+1] - zeroCnt - 1) { - zeroCnt-- - } else { - return false - } - } - if(zeroCnt < 0) return false +var isStraight = function (nums) { + let zeroCnt = 0; + nums.sort((a, b) => a - b); + for (let i = 0; i < nums.length - 1; i++) { + if (nums[i] === 0) zeroCnt++; + else { + if (nums[i] === nums[i + 1]) return false; + else if (nums[i] === nums[i + 1] - 1) { + continue; + } else if (nums[i] >= nums[i + 1] - zeroCnt - 1) { + zeroCnt--; + } else { + return false; + } } - return true -}; \ No newline at end of file + if (zeroCnt < 0) return false; + } + return true; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" index 72e4338f4faa3..805cc999d80c2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" @@ -1,10 +1,12 @@ -# [面试题62. 圆圈中最后剩下的数字](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) +# [面试题 62. 圆圈中最后剩下的数字](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) ## 题目描述 + -0,1,,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字。求出这个圆圈里剩下的最后一个数字。 -例如,0、1、2、3、4这5个数字组成一个圆圈,从数字0开始每次删除第3个数字,则删除的前4个数字依次是2、0、4、1,因此最后剩下的数字是3。 +0,1,,n-1 这 n 个数字排成一个圆圈,从数字 0 开始,每次从这个圆圈里删除第 m 个数字。求出这个圆圈里剩下的最后一个数字。 + +例如,0、1、2、3、4 这 5 个数字组成一个圆圈,从数字 0 开始每次删除第 3 个数字,则删除的前 4 个数字依次是 2、0、4、1,因此最后剩下的数字是 3。 **示例 1:** @@ -22,12 +24,13 @@ **限制:** -- `1 <= n <= 10^5` +- `1 <= n <= 10^5` - `1 <= m <= 10^6` - ## 解法 + + 设 `f(n, m)` 表示从 n 个数中每次删除第 m 个,最后剩下的数字。 第一次删除第 m 个,剩下 `n-1` 个数,那么 `x = f(n - 1, m)` 就表示从 n-1 个数中每次删除第 m 个,最后剩下的数字。 @@ -41,6 +44,7 @@ ### **Python3** + 递归版本: @@ -68,6 +72,7 @@ class Solution: ``` ### **Java** + ```java @@ -83,25 +88,27 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @param {number} m * @return {number} */ -var lastRemaining = function(n, m) { - // 约瑟夫环 - let res = 0 - for(let i=1;i<=n;i++) { - res = (res + m) % i - } - return res +var lastRemaining = function (n, m) { + // 约瑟夫环 + let res = 0; + for (let i = 1; i <= n; i++) { + res = (res + m) % i; + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/Solution.js" index 293807d8adcbb..87dfa53d23625 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/Solution.js" @@ -3,11 +3,11 @@ * @param {number} m * @return {number} */ -var lastRemaining = function(n, m) { - // 约瑟夫环 - let res = 0 - for(let i=1;i<=n;i++) { - res = (res + m) % i - } - return res -}; \ No newline at end of file +var lastRemaining = function (n, m) { + // 约瑟夫环 + let res = 0; + for (let i = 1; i <= n; i++) { + res = (res + m) % i; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" index 9a9b21cf24339..ee472b4d7141a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" @@ -1,6 +1,7 @@ -# [面试题63. 股票的最大利润](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) +# [面试题 63. 股票的最大利润](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) ## 题目描述 + 假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖该股票一次可能获得的最大利润是多少? **示例 1:** @@ -25,9 +26,11 @@ - `0 <= 数组长度 <= 10^5` ## 解法 + ### **Python3** + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -42,6 +45,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int maxProfit(int[] prices) { @@ -61,25 +65,27 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} prices * @return {number} */ -var maxProfit = function(prices) { - let a = 0 - let b = Infinity - for(let p of prices) { - a = Math.max(a, p - b) - b = Math.min(b, p) - } - return a +var maxProfit = function (prices) { + let a = 0; + let b = Infinity; + for (let p of prices) { + a = Math.max(a, p - b); + b = Math.min(b, p); + } + return a; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/Solution.js" index ccbb22d26615e..924c98e3b7718 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/Solution.js" @@ -2,12 +2,12 @@ * @param {number[]} prices * @return {number} */ -var maxProfit = function(prices) { - let a = 0 - let b = Infinity - for(let p of prices) { - a = Math.max(a, p - b) - b = Math.min(b, p) - } - return a -}; \ No newline at end of file +var maxProfit = function (prices) { + let a = 0; + let b = Infinity; + for (let p of prices) { + a = Math.max(a, p - b); + b = Math.min(b, p); + } + return a; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" index 8143922b17c34..13dbcfcf7fd41 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" @@ -1,7 +1,8 @@ -# [面试题64. 求1+2+…+n](https://leetcode-cn.com/problems/qiu-12n-lcof/) +# [面试题 64. 求 1+2+…+n](https://leetcode-cn.com/problems/qiu-12n-lcof/) ## 题目描述 -求 `1+2+...+n`,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 + +求 `1+2+...+n`,要求不能使用乘除法、for、while、if、else、switch、case 等关键字及条件判断语句(A?B:C)。 **示例 1:** @@ -19,14 +20,16 @@ **限制:** -- `1 <= n <= 10000` +- `1 <= n <= 10000` ## 解法 + 递归,结合**逻辑与**短路运算符求解。 ### **Python3** + ```python class Solution: def sumNums(self, n: int) -> int: @@ -34,6 +37,7 @@ class Solution: ``` ### **Java** + ```java class Solution { public int sumNums(int n) { @@ -45,19 +49,21 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} n * @return {number} */ -var sumNums = function(n) { - return (n**2 + n) >> 1 +var sumNums = function (n) { + return (n ** 2 + n) >> 1; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" index e8809a3fed041..d3d371ffd7bdb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" @@ -2,6 +2,6 @@ * @param {number} n * @return {number} */ -var sumNums = function(n) { - return (n**2 + n) >> 1 -}; \ No newline at end of file +var sumNums = function (n) { + return (n ** 2 + n) >> 1; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" index 37dc674e724f2..80a92cccc3de0 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" @@ -1,8 +1,10 @@ -# [面试题65. 不用加减乘除做加法](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) +# [面试题 65. 不用加减乘除做加法](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) ## 题目描述 + -写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“*”、“/” 四则运算符号。 + +写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“\*”、“/” 四则运算符号。 **示例:** @@ -13,11 +15,13 @@ **提示:** -- `a`, `b` 均可能是负数或 0 +- `a`, `b`  均可能是负数或 0 - 结果不会溢出 32 位整数 ## 解法 + + - 对两数进行按位 `^` 异或运算,得到不进位的和; - 对两数进行按位 `&` 与运算,然后左移一位,得到进位; - 循环,直至进位为 0。 @@ -25,7 +29,9 @@ ### **Python3** + + 由于 python `int` 是无限长整型,左移不会自动溢出,因此需要特殊处理。 ```python @@ -41,6 +47,7 @@ class Solution: ``` ### **Java** + ```java @@ -59,15 +66,16 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number} a * @param {number} b * @return {number} */ -var add = function(a, b) { - if(a === 0) return b - return add((a&b) << 1, a^b) +var add = function (a, b) { + if (a === 0) return b; + return add((a & b) << 1, a ^ b); }; // (a & b) << 1 是 进位和 // a ^ b 是不进位和 @@ -75,8 +83,9 @@ var add = function(a, b) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.js" index 020dd80397a86..2b3b036b4b687 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.js" @@ -3,10 +3,10 @@ * @param {number} b * @return {number} */ -var add = function(a, b) { - if(a === 0) return b - return add((a&b) << 1, a^b) +var add = function (a, b) { + if (a === 0) return b; + return add((a & b) << 1, a ^ b); }; // (a & b) << 1 是 进位和 // a ^ b 是不进位和 -// 两者相加得结果,由于本题禁止 + 号,所以递归 \ No newline at end of file +// 两者相加得结果,由于本题禁止 + 号,所以递归 diff --git "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" index ac038509b2208..f827a84fda3e1 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" @@ -1,6 +1,7 @@ -# [面试题66. 构建乘积数组](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) +# [面试题 66. 构建乘积数组](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) ## 题目描述 + 给定一个数组 `A[0,1,…,n-1]`,请构建一个数组 `B[0,1,…,n-1]`,其中 B 中的元素 `B[i]=A[0]×A[1]×…×A[i-1]×A[i+1]×…×A[n-1]`。不能使用除法。 @@ -17,14 +18,16 @@ - 所有元素乘积之和不会溢出 32 位整数 - `a.length <= 100000` - ## 解法 + + `B[i] = (A[0] * A[1] * ... * A[i-1]) * (A[i+1] * ... * A[n-1])` ### **Python3** + ```python @@ -44,6 +47,7 @@ class Solution: ``` ### **Java** + ```java @@ -73,30 +77,32 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {number[]} a * @return {number[]} */ -var constructArr = function(a) { - let pre = new Array(a.length+1).fill(1) - pre[0] = 1 - let res = new Array(a.length).fill(1) - for(let i = 1;i <= a.length;i++) { - pre[i] = a[i-1] * pre[i-1] - } - let cur = 1 - for(let i = a.length - 1;i >= 0;i--) { - res[i] = pre[i] * cur - cur *= a[i] - } - return res +var constructArr = function (a) { + let pre = new Array(a.length + 1).fill(1); + pre[0] = 1; + let res = new Array(a.length).fill(1); + for (let i = 1; i <= a.length; i++) { + pre[i] = a[i - 1] * pre[i - 1]; + } + let cur = 1; + for (let i = a.length - 1; i >= 0; i--) { + res[i] = pre[i] * cur; + cur *= a[i]; + } + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/Solution.js" index 764d9d407c4f6..8667dbfec22b3 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/Solution.js" @@ -2,17 +2,17 @@ * @param {number[]} a * @return {number[]} */ -var constructArr = function(a) { - let pre = new Array(a.length+1).fill(1) - pre[0] = 1 - let res = new Array(a.length).fill(1) - for(let i = 1;i <= a.length;i++) { - pre[i] = a[i-1] * pre[i-1] - } - let cur = 1 - for(let i = a.length - 1;i >= 0;i--) { - res[i] = pre[i] * cur - cur *= a[i] - } - return res -}; \ No newline at end of file +var constructArr = function (a) { + let pre = new Array(a.length + 1).fill(1); + pre[0] = 1; + let res = new Array(a.length).fill(1); + for (let i = 1; i <= a.length; i++) { + pre[i] = a[i - 1] * pre[i - 1]; + } + let cur = 1; + for (let i = a.length - 1; i >= 0; i--) { + res[i] = pre[i] * cur; + cur *= a[i]; + } + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" index ecf07da3fde51..46b47e7367eb6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" @@ -1,7 +1,9 @@ -# [面试题67. 把字符串转换成整数](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) +# [面试题 67. 把字符串转换成整数](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) ## 题目描述 + + 写一个函数 StrToInt,实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。 @@ -16,16 +18,16 @@ 说明: -假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为 `[−2^31,  2^31 − 1]`。如果数值超过这个范围,请返回  `INT_MAX (2^31 − 1)` 或 `INT_MIN (−2^31)` 。 +假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为  `[−2^31, 2^31 − 1]`。如果数值超过这个范围,请返回  `INT_MAX (2^31 − 1)` 或  `INT_MIN (−2^31)` 。 -**示例 1:** +**示例  1:** ``` 输入: "42" 输出: 42 ``` -**示例 2:** +**示例  2:** ``` 输入: " -42" @@ -34,7 +36,7 @@   我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。 ``` -**示例 3:** +**示例  3:** ``` 输入: "4193 with words" @@ -42,7 +44,7 @@ 解释: 转换截止于数字 '3' ,因为它的下一个字符不为数字。 ``` -**示例 4:** +**示例  4:** ``` 输入: "words and 987" @@ -51,23 +53,25 @@ 因此无法执行有效的转换。 ``` -**示例 5:** +**示例  5:** ``` 输入: "-91283472332" 输出: -2147483648 -解释: 数字 "-91283472332" 超过 32 位有符号整数范围。 +解释: 数字 "-91283472332" 超过 32 位有符号整数范围。   因此返回 INT_MIN (−2^31) 。 ``` ## 解法 + -遍历字符串,注意做溢出处理。 +遍历字符串,注意做溢出处理。 ### **Python3** + ```python @@ -89,6 +93,7 @@ class Solution: ``` ### **Java** + ```java @@ -122,37 +127,38 @@ class Solution { ``` ### **JavaScript** + ```js /** * @param {string} str * @return {number} */ -var strToInt = function(str) { - let res = '' - let l = 1 - for(let i=0;i 2147483647) return 2147483647 - if(res < -2147483648) return -2147483648 - return res + if (str[i].match(/[0-9]/)) { + l = 0; + res += str[i]; + } else break; + } + res = isNaN(+res) ? 0 : +res; + if (res > 2147483647) return 2147483647; + if (res < -2147483648) return -2147483648; + return res; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" index dea43b5ec53d7..f6b2f8ac5ac4c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" @@ -2,24 +2,23 @@ * @param {string} str * @return {number} */ -var strToInt = function(str) { - let res = '' - let l = 1 - for(let i=0;i 2147483647) return 2147483647 - if(res < -2147483648) return -2147483648 - return res -}; \ No newline at end of file + if (str[i].match(/[0-9]/)) { + l = 0; + res += str[i]; + } else break; + } + res = isNaN(+res) ? 0 : +res; + if (res > 2147483647) return 2147483647; + if (res < -2147483648) return -2147483648; + return res; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" index 1c227e01bb4ca..1fbca701c89fe 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" @@ -1,7 +1,9 @@ -# [面试题68 - I. 二叉搜索树的最近公共祖先](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof/) +# [面试题 68 - I. 二叉搜索树的最近公共祖先](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof/) ## 题目描述 + + 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。 [百度百科](https://baike.baidu.com/item/%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/8918834?fr=aladdin)中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(**一个节点也可以是它自己的祖先**)。” @@ -14,7 +16,7 @@ ``` 输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8 -输出: 6 +输出: 6 解释: 节点 2 和节点 8 的最近公共祖先是 6。 ``` @@ -32,6 +34,7 @@ - p、q 为不同节点且均存在于给定的二叉搜索树中。 ## 解法 + 从上到下搜索,找到第一个值位于 `[p, q]` 之间的结点即可。既可以用迭代实现,也可以用递归实现。 @@ -39,6 +42,7 @@ ### **Python3** + #### 迭代法 @@ -84,6 +88,7 @@ class Solution: ``` ### **Java** + ```java @@ -116,6 +121,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -130,21 +136,22 @@ class Solution { * @param {TreeNode} q * @return {TreeNode} */ -var lowestCommonAncestor = function(root, p, q) { - // 递归 - if(!root) return null - if(root.val < p.val && root.val < q.val) { - return lowestCommonAncestor(root.right, p,q) - } else if(root.val > p.val && root.val > q.val) { - return lowestCommonAncestor(root.left, p,q) - } - return root +var lowestCommonAncestor = function (root, p, q) { + // 递归 + if (!root) return null; + if (root.val < p.val && root.val < q.val) { + return lowestCommonAncestor(root.right, p, q); + } else if (root.val > p.val && root.val > q.val) { + return lowestCommonAncestor(root.left, p, q); + } + return root; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" index aa30bd7cb9469..860f057f4ab44 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" @@ -11,13 +11,13 @@ * @param {TreeNode} q * @return {TreeNode} */ -var lowestCommonAncestor = function(root, p, q) { - // 递归 - if(!root) return null - if(root.val < p.val && root.val < q.val) { - return lowestCommonAncestor(root.right, p,q) - } else if(root.val > p.val && root.val > q.val) { - return lowestCommonAncestor(root.left, p,q) - } - return root -}; \ No newline at end of file +var lowestCommonAncestor = function (root, p, q) { + // 递归 + if (!root) return null; + if (root.val < p.val && root.val < q.val) { + return lowestCommonAncestor(root.right, p, q); + } else if (root.val > p.val && root.val > q.val) { + return lowestCommonAncestor(root.left, p, q); + } + return root; +}; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" index 170c28b55cbd5..299ab5f292302 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" @@ -1,7 +1,9 @@ -# [面试题68 - II. 二叉树的最近公共祖先](https://leetcode-cn.com/problems/er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof/) +# [面试题 68 - II. 二叉树的最近公共祖先](https://leetcode-cn.com/problems/er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof/) ## 题目描述 + + 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 [百度百科](https://baike.baidu.com/item/%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/8918834?fr=aladdin)中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(**一个节点也可以是它自己的祖先**)。” @@ -18,7 +20,7 @@ 解释: 节点 5 和节点 1 的最近公共祖先是节点 3。 ``` -**示例 2:** +**示例  2:** ``` 输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4 @@ -32,6 +34,7 @@ - p、q 为不同节点且均存在于给定的二叉树中。 ## 解法 + 根据“**最近公共祖先**”的定义,若 root 是 p, q 的最近公共祖先 ,则只可能为以下情况之一: @@ -50,6 +53,7 @@ ### **Python3** + ```python @@ -70,6 +74,7 @@ class Solution: ``` ### **Java** + ```java @@ -95,6 +100,7 @@ class Solution { ``` ### **JavaScript** + ```js /** * Definition for a binary tree node. @@ -109,21 +115,22 @@ class Solution { * @param {TreeNode} q * @return {TreeNode} */ -var lowestCommonAncestor = function(root, p, q) { - if(!root) return null - if(root === p || root === q) return root - let left = lowestCommonAncestor(root.left,p,q) - let right = lowestCommonAncestor(root.right,p,q) - if(left && right) return root - if(left) return left - if(right) return right - return null +var lowestCommonAncestor = function (root, p, q) { + if (!root) return null; + if (root === p || root === q) return root; + let left = lowestCommonAncestor(root.left, p, q); + let right = lowestCommonAncestor(root.right, p, q); + if (left && right) return root; + if (left) return left; + if (right) return right; + return null; }; ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" index 03e3aa2aa956b..164cbe2717e07 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.js" @@ -11,13 +11,13 @@ * @param {TreeNode} q * @return {TreeNode} */ -var lowestCommonAncestor = function(root, p, q) { - if(!root) return null - if(root === p || root === q) return root - let left = lowestCommonAncestor(root.left,p,q) - let right = lowestCommonAncestor(root.right,p,q) - if(left && right) return root - if(left) return left - if(right) return right - return null -}; \ No newline at end of file +var lowestCommonAncestor = function (root, p, q) { + if (!root) return null; + if (root === p || root === q) return root; + let left = lowestCommonAncestor(root.left, p, q); + let right = lowestCommonAncestor(root.right, p, q); + if (left && right) return root; + if (left) return left; + if (right) return right; + return null; +}; diff --git a/solution/0000-0099/0001.Two Sum/README.md b/solution/0000-0099/0001.Two Sum/README.md index 0e280211b3587..84489b48a6da3 100644 --- a/solution/0000-0099/0001.Two Sum/README.md +++ b/solution/0000-0099/0001.Two Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0001.Two%20Sum/README_EN.md) ## 题目描述 +

    给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。

    @@ -16,15 +17,14 @@ 所以返回 [0, 1] - - ## 解法 - + ### **Python3** + ```python @@ -32,6 +32,7 @@ ``` ### **Java** + ```java @@ -39,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0001.Two Sum/README_EN.md b/solution/0000-0099/0001.Two Sum/README_EN.md index 8d23996b11136..9a9fbef1672c9 100644 --- a/solution/0000-0099/0001.Two Sum/README_EN.md +++ b/solution/0000-0099/0001.Two Sum/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0001.Two%20Sum/README.md) ## Description -

    Given an array of integers, return indices of the two numbers such that they add up to a specific target.

    - +

    Given an array of integers, return indices of the two numbers such that they add up to a specific target.

    You may assume that each input would have exactly one solution, and you may not use the same element twice.

    - -

    Example:

    - -
     
     Given nums = [2, 7, 11, 15], target = 9,
    @@ -27,12 +22,8 @@ return [0, 1].
     
     
    - - - ## Solutions - ### **Python3** @@ -48,8 +39,9 @@ return [0, 1]. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0001.Two Sum/Solution.js b/solution/0000-0099/0001.Two Sum/Solution.js index b0bd22cd58491..65dce780ea093 100644 --- a/solution/0000-0099/0001.Two Sum/Solution.js +++ b/solution/0000-0099/0001.Two Sum/Solution.js @@ -2,22 +2,22 @@ * Author: limbowandering */ -const twoSum = function(nums, target) { +const twoSum = function (nums, target) { const map = {}; for (let i = 0; i < nums.length; i++) { if (map[nums[i]] !== undefined) { - return [map[nums[i]], i] + return [map[nums[i]], i]; } else { - map[target - nums[i]] = i + map[target - nums[i]] = i; } - } + } }; -/** +/** * Author: Mcnwork2018 */ -var twoSum = function(nums, target) { +var twoSum = function (nums, target) { let len = nums.length; let n = {}; for (let i = 0; i < len; i++) { @@ -32,12 +32,12 @@ var twoSum = function(nums, target) { * Author: rookie */ -var twoSum = function(nums, target) { +var twoSum = function (nums, target) { const map = new Map(); for (let i = 0; i < nums.length; i++) { if (map.has(target - nums[i])) { - return [ map.get(target - nums[i]), i ] + return [map.get(target - nums[i]), i]; } map.set(nums[i], i); } -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0002.Add Two Numbers/README.md b/solution/0000-0099/0002.Add Two Numbers/README.md index 70f6c30985c53..b4bed47b9e5da 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README.md +++ b/solution/0000-0099/0002.Add Two Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) ## 题目描述 +

    给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。

    @@ -17,15 +18,14 @@ 原因:342 + 465 = 807 - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0002.Add Two Numbers/README_EN.md b/solution/0000-0099/0002.Add Two Numbers/README_EN.md index 09a5852db512b..d960ea5ba7b69 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README_EN.md +++ b/solution/0000-0099/0002.Add Two Numbers/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md) ## Description -

    You are given two non-empty linked lists representing two non-negative integers. 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 linked list.

    - +

    You are given two non-empty linked lists representing two non-negative integers. 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 linked list.

    You may assume the two numbers do not contain any leading zero, except the number 0 itself.

    - -

    Example:

    - -
     
     Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
    @@ -25,12 +20,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0002.Add Two Numbers/Solution.js b/solution/0000-0099/0002.Add Two Numbers/Solution.js index c9fc0b9898542..e2122af2190c9 100644 --- a/solution/0000-0099/0002.Add Two Numbers/Solution.js +++ b/solution/0000-0099/0002.Add Two Numbers/Solution.js @@ -12,29 +12,34 @@ */ /** - * Author: Mcnwork2018 + * Author: Mcnwork2018 */ var addTwoNumbers = function (l1, l2) { - let c1 = l1, c2 = l2, c3 = 0, l3 = 0, carry = 0; - while (c1 || c2 || carry) { - var v1 = 0, v2 = 0; - if (c1) { - v1 = c1.val; - c1 = c1.next; - } - if (c2) { - v2 = c2.val; - c2 = c2.next; - } - var sum = v1 + v2 + carry; - carry = (sum - sum % 10) / 10; - if (!c3) { - l3 = new ListNode(sum % 10); - c3 = l3; - } else { - c3.next = new ListNode(sum % 10); - c3 = c3.next; - } - } - return l3; -} \ No newline at end of file + let c1 = l1, + c2 = l2, + c3 = 0, + l3 = 0, + carry = 0; + while (c1 || c2 || carry) { + var v1 = 0, + v2 = 0; + if (c1) { + v1 = c1.val; + c1 = c1.next; + } + if (c2) { + v2 = c2.val; + c2 = c2.next; + } + var sum = v1 + v2 + carry; + carry = (sum - (sum % 10)) / 10; + if (!c3) { + l3 = new ListNode(sum % 10); + c3 = l3; + } else { + c3.next = new ListNode(sum % 10); + c3 = c3.next; + } + } + return l3; +}; diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md index 7027001bc5d8f..e16c92e411535 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md) ## 题目描述 +

    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。

    @@ -28,15 +29,14 @@   请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md index 0ceea987a2322..6ef858c2964dc 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md) ## Description -

    Given a string, find the length of the longest substring without repeating characters.

    - +

    Given a string, find the length of the longest substring without repeating characters.

    Example 1:

    - -
     
     Input: "abcabcbb"
    @@ -23,14 +20,10 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "bbbbb"
    @@ -41,14 +34,10 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "pwwkew"
    @@ -67,12 +56,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -88,8 +73,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js index d63cafcb8e123..7e9cd0a4d0a30 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js @@ -2,21 +2,24 @@ * @param {string} s * @return {number} */ -var lengthOfLongestSubstring = function(s) { - var start = 0; // 非重复字符串开始索引 - var max = 0; // 最长字符串长度 - var visitedCharByPosition = {}; - for (var position = 0; position < s.length; position++) { - var nextChar = s[position]; - if (nextChar in visitedCharByPosition && visitedCharByPosition[nextChar] >= start) { - // 有重复,非重复字符串索引从下一个 index 开始 - start = visitedCharByPosition[nextChar] + 1; - visitedCharByPosition[nextChar] = position; - } else { - visitedCharByPosition[nextChar] = position; - // 非重复,求非重复值 - max = Math.max(max, position + 1 - start); - } +var lengthOfLongestSubstring = function (s) { + var start = 0; // 非重复字符串开始索引 + var max = 0; // 最长字符串长度 + var visitedCharByPosition = {}; + for (var position = 0; position < s.length; position++) { + var nextChar = s[position]; + if ( + nextChar in visitedCharByPosition && + visitedCharByPosition[nextChar] >= start + ) { + // 有重复,非重复字符串索引从下一个 index 开始 + start = visitedCharByPosition[nextChar] + 1; + visitedCharByPosition[nextChar] = position; + } else { + visitedCharByPosition[nextChar] = position; + // 非重复,求非重复值 + max = Math.max(max, position + 1 - start); } - return max; -}; \ No newline at end of file + } + return max; +}; diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md b/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md index 74f30e643f9f4..bc089c6545158 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md) ## 题目描述 +

    给定两个大小为 m 和 n 的有序数组 nums1 和 nums2

    @@ -26,15 +27,14 @@ nums2 = [3, 4] 则中位数是 (2 + 3)/2 = 2.5 - - ## 解法 - + ### **Python3** + ```python @@ -42,6 +42,7 @@ nums2 = [3, 4] ``` ### **Java** + ```java @@ -49,8 +50,9 @@ nums2 = [3, 4] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md b/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md index 6f6a10cc58866..33c3adba5deb4 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md) ## Description -

    There are two sorted arrays nums1 and nums2 of size m and n respectively.

    - +

    There are two sorted arrays nums1 and nums2 of size m and n respectively.

    Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

    - -

    You may assume nums1 and nums2 cannot be both empty.

    - -

    Example 1:

    - -
     
     nums1 = [1, 3]
    @@ -31,12 +24,8 @@ The median is 2.0
     
     
    - -

    Example 2:

    - -
     
     nums1 = [1, 2]
    @@ -49,12 +38,8 @@ The median is (2 + 3)/2 = 2.5
     
     
    - - - ## Solutions - ### **Python3** @@ -70,8 +55,9 @@ The median is (2 + 3)/2 = 2.5 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js b/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js index 82afa8c8fa27e..929b6e5dbe7c1 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js @@ -4,64 +4,67 @@ * @return {number} 012345 */ var findMedianSortedArrays = function (nums1, nums2) { - if (nums1.length == 0 || nums2.length == 0) { - if ((nums1.length + nums2.length) % 2 == 1) { - const index = parseInt((nums1.length + nums2.length) / 2) - return nums2.length == 0 ? nums1[index] : nums2[index] - } else { - let nums = nums2.length == 0 ? nums1 : nums2 - const index = nums.length / 2 - return (nums[index - 1] + nums[index]) / 2 - } + if (nums1.length == 0 || nums2.length == 0) { + if ((nums1.length + nums2.length) % 2 == 1) { + const index = parseInt((nums1.length + nums2.length) / 2); + return nums2.length == 0 ? nums1[index] : nums2[index]; + } else { + let nums = nums2.length == 0 ? nums1 : nums2; + const index = nums.length / 2; + return (nums[index - 1] + nums[index]) / 2; } + } - if (nums1.length > nums2.length) { - swap(nums1, nums2) + if (nums1.length > nums2.length) { + swap(nums1, nums2); + } + const M = nums1.length, + N = nums2.length; + let min = 0, + max = M, + half = parseInt((M + N + 1) / 2); // 连个数组合并的中间值 + while (min <= max) { + let i = parseInt((min + max) / 2); // nums1 的索引值 + let j = half - i; // num2 的索引值 + if (i < max && nums2[j - 1] > nums1[i]) { + min++; + } else if (i > min && nums1[i - 1] > nums2[j]) { + max--; + } else { + let maxLeft = 0; + if (i == 0) { + maxLeft = nums2[j - 1]; + } else if (j == 0) { + maxLeft = nums1[i - 1]; + } else { + maxLeft = Math.max(nums1[i - 1], nums2[j - 1]); + } + if ((M + N) % 2 == 1) { + return maxLeft; + } + let minRight = 0; + if (i == M) { + minRight = nums2[j]; + } else if (j == N) { + minRight = nums1[i]; + } else { + minRight = Math.min(nums1[i], nums2[j]); + } + return (maxLeft + minRight) / 2; } - const M = nums1.length, N = nums2.length - let min = 0, max = M, half = parseInt((M + N + 1) / 2) // 连个数组合并的中间值 - while (min <= max) { - let i = parseInt((min + max) / 2) // nums1 的索引值 - let j = half - i // num2 的索引值 - if (i < max && nums2[j - 1] > nums1[i]) { - min++ - } else if (i > min && nums1[i - 1] > nums2[j]) { - max-- - } else { - let maxLeft = 0 - if (i == 0) { - maxLeft = nums2[j - 1] - } else if (j == 0) { - maxLeft = nums1[i - 1] - } else { - maxLeft = Math.max(nums1[i - 1], nums2[j - 1]) - } - if ((M + N) % 2 == 1) { - return maxLeft - } - let minRight = 0 - if (i == M) { - minRight = nums2[j] - } else if (j == N) { - minRight = nums1[i] - } else { - minRight = Math.min(nums1[i], nums2[j]) - } - return (maxLeft + minRight) / 2 - } - } - return 0 + } + return 0; }; function swap(a, b) { - let tmp = a - a = b - b = tmp + let tmp = a; + a = b; + b = tmp; } -const nums1 = [4, 5] -const nums2 = [1, 2, 3] -findMedianSortedArrays(nums1, nums2) +const nums1 = [4, 5]; +const nums2 = [1, 2, 3]; +findMedianSortedArrays(nums1, nums2); /** * 实现思路 @@ -71,4 +74,4 @@ findMedianSortedArrays(nums1, nums2) * 取大数组的索引 = 总中间值-小数组中间值 * 循环直到符合条件 * 如果都不符合条件,那么说明中间值在两个数组的左边或者右边 - */ \ No newline at end of file + */ diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/README.md b/solution/0000-0099/0005.Longest Palindromic Substring/README.md index 2494e18204624..033dfe0def4cb 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/README.md +++ b/solution/0000-0099/0005.Longest Palindromic Substring/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md) ## 题目描述 +

    给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。

    @@ -19,15 +20,14 @@ 输出: "bb" - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md b/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md index 5b9946636e22a..b2783c48175bb 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md +++ b/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md) ## Description -

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

    - +

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

    Example 1:

    - -
     
     Input: "babad"
    @@ -21,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "cbbd"
    @@ -35,12 +28,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js b/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js index 3371f06d57ebf..9a77a2833d1a0 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js +++ b/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js @@ -3,34 +3,36 @@ * @return {string} */ var longestPalindrome = function (s) { - let maxLength = 0, left = 0, right = 0 - for (let i = 0; i < s.length; i++) { - let singleCharLength = getPalLenByCenterChar(s, i, i) - let doubleCharLength = getPalLenByCenterChar(s, i, i + 1) - let max = Math.max(singleCharLength, doubleCharLength) - if (max > maxLength) { - maxLength = max - left = i - parseInt((max - 1) / 2) - right = i + parseInt(max / 2) - } + let maxLength = 0, + left = 0, + right = 0; + for (let i = 0; i < s.length; i++) { + let singleCharLength = getPalLenByCenterChar(s, i, i); + let doubleCharLength = getPalLenByCenterChar(s, i, i + 1); + let max = Math.max(singleCharLength, doubleCharLength); + if (max > maxLength) { + maxLength = max; + left = i - parseInt((max - 1) / 2); + right = i + parseInt(max / 2); } - return s.slice(left, right + 1) + } + return s.slice(left, right + 1); }; function getPalLenByCenterChar(s, left, right) { - // 中间值为两个字符,确保两个字符相等 - if (s[left] != s[right]){ - return right - left // 不相等返回为1个字符串 + // 中间值为两个字符,确保两个字符相等 + if (s[left] != s[right]) { + return right - left; // 不相等返回为1个字符串 + } + while (left > 0 && right < s.length - 1) { + // 先加减再判断 + left--; + right++; + if (s[left] != s[right]) { + return right - left - 1; } - while (left > 0 && right < s.length - 1) { - // 先加减再判断 - left-- - right++ - if (s[left] != s[right]){ - return right - left - 1 - } - } - return right - left + 1 + } + return right - left + 1; } -console.log(longestPalindrome("cbbd")) \ No newline at end of file +console.log(longestPalindrome("cbbd")); diff --git a/solution/0000-0099/0006.ZigZag Conversion/README.md b/solution/0000-0099/0006.ZigZag Conversion/README.md index 245ce933c43a9..1e27e07aee5c3 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/README.md +++ b/solution/0000-0099/0006.ZigZag Conversion/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md) ## 题目描述 +

    将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。

    @@ -36,15 +37,14 @@ E O E I I E C I H N T S G - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ T S G ``` ### **Java** + ```java @@ -59,8 +60,9 @@ T S G ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0006.ZigZag Conversion/README_EN.md b/solution/0000-0099/0006.ZigZag Conversion/README_EN.md index f32fb59e184d9..3a10fcad6038d 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/README_EN.md +++ b/solution/0000-0099/0006.ZigZag Conversion/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0006.ZigZag%20Conversion/README.md) ## Description -

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

    - +

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

     
    @@ -17,26 +16,16 @@ Y   I   R
     
     
    - -

    And then read line by line: "PAHNAPLSIIGYIR"

    - -

    Write the code that will take a string and make this conversion given a number of rows:

    - -
     
     string convert(string s, int numRows);
    - -

    Example 1:

    - -
     
     Input: s = "PAYPALISHIRING", numRows = 3
    @@ -45,12 +34,8 @@ string convert(string s, int numRows);
    - -

    Example 2:

    - -
     
     Input: s = "PAYPALISHIRING", numRows = 4
    @@ -69,12 +54,8 @@ Y A   H R
     
     P     I
    - - - ## Solutions - ### **Python3** @@ -90,8 +71,9 @@ P I ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0006.ZigZag Conversion/Solution.js b/solution/0000-0099/0006.ZigZag Conversion/Solution.js index 68ea0f89c2a72..62f9913c534f0 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/Solution.js +++ b/solution/0000-0099/0006.ZigZag Conversion/Solution.js @@ -4,29 +4,31 @@ * @return {string} */ var convert = function (s, numRows) { - if (numRows == 1) return s - let arr = new Array(numRows) - for (let i = 0; i < numRows; i++) arr[i] = [] - let index = 0, len = s.length, mi = 0, isDown = true - while (index < len) { - arr[mi].push(s[index]) - index++ + if (numRows == 1) return s; + let arr = new Array(numRows); + for (let i = 0; i < numRows; i++) arr[i] = []; + let index = 0, + len = s.length, + mi = 0, + isDown = true; + while (index < len) { + arr[mi].push(s[index]); + index++; - if (mi >= numRows - 1) - isDown = false - else if (mi <= 0) - isDown = true + if (mi >= numRows - 1) isDown = false; + else if (mi <= 0) isDown = true; - if (isDown) mi++ - else mi-- - } - let ans = [] - for (let item of arr) { - ans = ans.concat(item) - } - return ans.join("") + if (isDown) mi++; + else mi--; + } + let ans = []; + for (let item of arr) { + ans = ans.concat(item); + } + return ans.join(""); }; -const s = "AB", numRows = 1 +const s = "AB", + numRows = 1; -console.log(convert(s, numRows)) \ No newline at end of file +console.log(convert(s, numRows)); diff --git a/solution/0000-0099/0007.Reverse Integer/README.md b/solution/0000-0099/0007.Reverse Integer/README.md index 06091abaf2e54..e585e3b42039c 100644 --- a/solution/0000-0099/0007.Reverse Integer/README.md +++ b/solution/0000-0099/0007.Reverse Integer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0007.Reverse%20Integer/README_EN.md) ## 题目描述 +

    给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。

    @@ -28,15 +29,14 @@

    假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231,  231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。

    - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0007.Reverse Integer/README_EN.md b/solution/0000-0099/0007.Reverse Integer/README_EN.md index da7bfd8b4cf44..77cefc2b6a03a 100644 --- a/solution/0000-0099/0007.Reverse Integer/README_EN.md +++ b/solution/0000-0099/0007.Reverse Integer/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0007.Reverse%20Integer/README.md) ## Description -

    Given a 32-bit signed integer, reverse digits of an integer.

    - +

    Given a 32-bit signed integer, reverse digits of an integer.

    Example 1:

    - -
     
     Input: 123
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: -123
    @@ -33,12 +26,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: 120
    @@ -47,18 +36,12 @@
     
     
    - -

    Note:
    Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

    - - - ## Solutions - ### **Python3** @@ -74,8 +57,9 @@ Assume we are dealing with an environment which could only store integers within ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0007.Reverse Integer/Solution.js b/solution/0000-0099/0007.Reverse Integer/Solution.js index 4edeb7ff76deb..0812a5704aef1 100644 --- a/solution/0000-0099/0007.Reverse Integer/Solution.js +++ b/solution/0000-0099/0007.Reverse Integer/Solution.js @@ -3,12 +3,13 @@ * @return {number} */ -/** +/** * Author: mcnwork2018 */ -var reverse = function(x) { - let min = -Math.pow(2,31), max = Math.pow(2,31) - 1; +var reverse = function (x) { + let min = -Math.pow(2, 31), + max = Math.pow(2, 31) - 1; let rev = 0; while (x != 0) { let pop = x % 10; @@ -20,32 +21,32 @@ var reverse = function(x) { return rev; }; -/** +/** * Author: rookie */ var reverse = function (x) { - const s = x + "" - let i = 0 - let sign = 1 + const s = x + ""; + let i = 0; + let sign = 1; if (s[i] == "-") { - i++ - sign = -1 + i++; + sign = -1; } if (s[i] == "+") { - i++ + i++; } - let num = 0 + let num = 0; for (let j = s.length - 1; j >= i; j--) { - num = num * 10 + parseInt(s[j]) + num = num * 10 + parseInt(s[j]); } - num *= sign - let max = 2 + num *= sign; + let max = 2; for (let n = 0; n < 30; n++) { - max *= 2 + max *= 2; } if (num > max || num < -max) { - return 0 + return 0; } - return num -}; \ No newline at end of file + return num; +}; diff --git a/solution/0000-0099/0008.String to Integer (atoi)/README.md b/solution/0000-0099/0008.String to Integer (atoi)/README.md index bd29bd8c93021..aae221d2edddb 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/README.md +++ b/solution/0000-0099/0008.String to Integer (atoi)/README.md @@ -1,8 +1,9 @@ # [8. 字符串转换整数 (atoi)](https://leetcode-cn.com/problems/string-to-integer-atoi) -[English Version](/solution/0000-0099/0008.String%20to%20Integer%20(atoi)/README_EN.md) +[English Version]() ## 题目描述 +

    请你来实现一个 atoi 函数,使其能将字符串转换成整数。

    @@ -56,15 +57,14 @@   因此返回 INT_MIN (−231) 。 - - ## 解法 - + ### **Python3** + ```python @@ -72,6 +72,7 @@ ``` ### **Java** + ```java @@ -79,8 +80,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md b/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md index 1f16a5e14f5b7..e8611d2a24a7d 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md +++ b/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md @@ -1,46 +1,31 @@ # [8. String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) -[中文文档](/solution/0000-0099/0008.String%20to%20Integer%20(atoi)/README.md) +[中文文档]() ## Description -

    Implement atoi which converts a string to an integer.

    - +

    Implement atoi which converts 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 this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

    - -

    The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

    - -

    If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

    - -

    If no valid conversion could be performed, a zero value is returned.

    - -

    Note:

    - -
      -
    • Only the space character ' ' is considered as whitespace character.
    • +
    • Only the space character ' ' is considered as whitespace character.
    • -
    • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
    • +
    • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
    - -

    Example 1:

    - -
     
     Input: "42"
    @@ -49,12 +34,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "   -42"
    @@ -67,12 +48,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "4193 with words"
    @@ -83,12 +60,8 @@
     
     
    - -

    Example 4:

    - -
     
     Input: "words and 987"
    @@ -99,12 +72,8 @@
     
                  digit or a +/- sign. Therefore no valid conversion could be performed.
    - -

    Example 5:

    - -
     
     Input: "-91283472332"
    @@ -115,12 +84,8 @@
     
                  Thefore INT_MIN (−231) is returned.
    - - - ## Solutions - ### **Python3** @@ -136,8 +101,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0008.String to Integer (atoi)/Solution.js b/solution/0000-0099/0008.String to Integer (atoi)/Solution.js index 9878df64efea7..e73b6cd728ee1 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/Solution.js +++ b/solution/0000-0099/0008.String to Integer (atoi)/Solution.js @@ -1,23 +1,24 @@ -const myAtoi = function(str){ +const myAtoi = function (str) { str = str.trim(); - if(!str) return 0; + if (!str) return 0; let isPositive = 1; - let i = 0, ans = 0; - if(str[i] === '+'){ + let i = 0, + ans = 0; + if (str[i] === "+") { isPositive = 1; i++; - }else if(str[i] === '-'){ + } else if (str[i] === "-") { isPositive = 0; i++; } - for(; i < str.length; i++){ + for (; i < str.length; i++) { let t = str.charCodeAt(i) - 48; - if(t > 9 || t < 0) break; - if(ans > 2147483647/10 || ans > (2147483647-t)/10){ + if (t > 9 || t < 0) break; + if (ans > 2147483647 / 10 || ans > (2147483647 - t) / 10) { return isPositive ? 2147483647 : -2147483648; - }else{ - ans = ans*10 + t; + } else { + ans = ans * 10 + t; } } - return isPositive? ans : -ans; -} + return isPositive ? ans : -ans; +}; diff --git a/solution/0000-0099/0009.Palindrome Number/README.md b/solution/0000-0099/0009.Palindrome Number/README.md index dd05c3bf9ae9e..18718a5865682 100644 --- a/solution/0000-0099/0009.Palindrome Number/README.md +++ b/solution/0000-0099/0009.Palindrome Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0009.Palindrome%20Number/README_EN.md) ## 题目描述 +

    判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

    @@ -30,15 +31,14 @@

    你能不将整数转为字符串来解决这个问题吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -46,6 +46,7 @@ ``` ### **Java** + ```java @@ -53,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0009.Palindrome Number/README_EN.md b/solution/0000-0099/0009.Palindrome Number/README_EN.md index 3df96110092cb..040213519aa04 100644 --- a/solution/0000-0099/0009.Palindrome Number/README_EN.md +++ b/solution/0000-0099/0009.Palindrome Number/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0009.Palindrome%20Number/README.md) ## Description -

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

    - +

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

    Example 1:

    - -
     
     Input: 121
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: -121
    @@ -35,12 +28,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: 10
    @@ -51,20 +40,12 @@
     
     
    - -

    Follow up:

    - -

    Coud you solve it without converting the integer to a string?

    - - - ## Solutions - ### **Python3** @@ -80,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0009.Palindrome Number/Solution.js b/solution/0000-0099/0009.Palindrome Number/Solution.js index 9876d699cc70d..355cce7972fe3 100644 --- a/solution/0000-0099/0009.Palindrome Number/Solution.js +++ b/solution/0000-0099/0009.Palindrome Number/Solution.js @@ -2,13 +2,14 @@ * @param {number} x * @return {boolean} */ -var isPalindrome = function(x) { - let str = x + "" - let left = 0,right = str.length - 1 - while(left < right){ - if (str[left] != str[right]) return false - left++ - right-- - } - return true -}; \ No newline at end of file +var isPalindrome = function (x) { + let str = x + ""; + let left = 0, + right = str.length - 1; + while (left < right) { + if (str[left] != str[right]) return false; + left++; + right--; + } + return true; +}; diff --git a/solution/0000-0099/0010.Regular Expression Matching/README.md b/solution/0000-0099/0010.Regular Expression Matching/README.md index 66bb2efc1fe86..e4db4a3991ff2 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/README.md +++ b/solution/0000-0099/0010.Regular Expression Matching/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md) ## 题目描述 +

    给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配。

    @@ -62,15 +63,14 @@ s = "mississippi" p = "mis*is*p*." 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -78,6 +78,7 @@ p = "mis*is*p*." ``` ### **Java** + ```java @@ -85,8 +86,9 @@ p = "mis*is*p*." ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0010.Regular Expression Matching/README_EN.md b/solution/0000-0099/0010.Regular Expression Matching/README_EN.md index 3372431f10082..ee5191b442863 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/README_EN.md +++ b/solution/0000-0099/0010.Regular Expression Matching/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md) ## Description +

    Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.

    @@ -68,11 +69,8 @@ p = "mis*is*p*."
     Output: false
     
    - - ## Solutions - ### **Python3** @@ -88,8 +86,9 @@ p = "mis*is*p*." ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/README.md b/solution/0000-0099/0011.Container With Most Water/README.md index 02ae5d9168cc9..7dc7d0c447516 100644 --- a/solution/0000-0099/0011.Container With Most Water/README.md +++ b/solution/0000-0099/0011.Container With Most Water/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md) ## 题目描述 +

    给你 n 个非负整数 a1a2,...,an,每个数代表坐标中的一个点 (iai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (iai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。

    @@ -21,15 +22,14 @@
    输入:[1,8,6,2,5,4,8,3,7]
     输出:49
    - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/README_EN.md b/solution/0000-0099/0011.Container With Most Water/README_EN.md index 4db660afa34a6..c7fc7a6f6b698 100644 --- a/solution/0000-0099/0011.Container With Most Water/README_EN.md +++ b/solution/0000-0099/0011.Container With Most Water/README_EN.md @@ -3,41 +3,29 @@ [中文文档](/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md) ## Description -

    Given n non-negative integers a1, a2, ..., a, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

    - +

    Given n non-negative integers a1, a2, ..., a, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

    Note: You may not slant the container and n is at least 2.

    - -

     

    ![](./images/question_11.jpg) -

    The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.

    - -

     

    - -

    Example:

    - -
     
     Input: [1,8,6,2,5,4,8,3,7]
     
     Output: 49
    - ## Solutions - ### **Python3** @@ -53,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/Solution.js b/solution/0000-0099/0011.Container With Most Water/Solution.js index 5fe55494d506d..3728062a6223f 100644 --- a/solution/0000-0099/0011.Container With Most Water/Solution.js +++ b/solution/0000-0099/0011.Container With Most Water/Solution.js @@ -1,18 +1,20 @@ -const maxArea2 = function(height){ +const maxArea2 = function (height) { let result = 0; - for(let i = 0; i < height.length; i++){ - for(let j = i + 1; j < height.length; j++){ - result = Math.max(result, Math.min(height[i],height[j])*(j-i)); + for (let i = 0; i < height.length; i++) { + for (let j = i + 1; j < height.length; j++) { + result = Math.max(result, Math.min(height[i], height[j]) * (j - i)); } } return result; }; -const maxArea = function(height){ - let result = 0, l = 0, r = height.length - 1; - while(l < r){ - result = Math.max(result, Math.min(height[l],height[r])*(r-l)); +const maxArea = function (height) { + let result = 0, + l = 0, + r = height.length - 1; + while (l < r) { + result = Math.max(result, Math.min(height[l], height[r]) * (r - l)); height[l] < height[r] ? l++ : r--; } return result; -} +}; diff --git a/solution/0000-0099/0012.Integer to Roman/README.md b/solution/0000-0099/0012.Integer to Roman/README.md index a213e903e950c..9a224432548f5 100644 --- a/solution/0000-0099/0012.Integer to Roman/README.md +++ b/solution/0000-0099/0012.Integer to Roman/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md) ## 题目描述 +

    罗马数字包含以下七种字符: I, V, X, LCD 和 M

    @@ -55,15 +56,14 @@ M 1000 输出: "MCMXCIV" 解释: M = 1000, CM = 900, XC = 90, IV = 4. - - ## 解法 - + ### **Python3** + ```python @@ -71,6 +71,7 @@ M 1000 ``` ### **Java** + ```java @@ -78,8 +79,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0012.Integer to Roman/README_EN.md b/solution/0000-0099/0012.Integer to Roman/README_EN.md index c240afc6ba4e8..81cc9376eba5c 100644 --- a/solution/0000-0099/0012.Integer to Roman/README_EN.md +++ b/solution/0000-0099/0012.Integer to Roman/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0012.Integer%20to%20Roman/README.md) ## Description -

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    - +

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

     
    @@ -25,72 +24,48 @@ D             500
     
     M             1000
    - -

    For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

    - -

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    - -
      -
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • +
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • -
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • +
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • -
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • +
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    - -

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.

    - -

    Example 1:

    - -
     
     Input: 3
     
     Output: "III"
    - -

    Example 2:

    - -
     
     Input: 4
     
     Output: "IV"
    - -

    Example 3:

    - -
     
     Input: 9
     
     Output: "IX"
    - -

    Example 4:

    - -
     
     Input: 58
    @@ -101,12 +76,8 @@ M             1000
    - -

    Example 5:

    - -
     
     Input: 1994
    @@ -115,12 +86,8 @@ M             1000
    Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. - - - ## Solutions - ### **Python3** @@ -136,8 +103,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0013.Roman to Integer/README.md b/solution/0000-0099/0013.Roman to Integer/README.md index d396d85b0298a..fa8caf35e74ff 100644 --- a/solution/0000-0099/0013.Roman to Integer/README.md +++ b/solution/0000-0099/0013.Roman to Integer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md) ## 题目描述 +

    罗马数字包含以下七种字符: I, V, X, LCD 和 M

    @@ -55,15 +56,14 @@ M 1000 输出: 1994 解释: M = 1000, CM = 900, XC = 90, IV = 4. - - ## 解法 - + ### **Python3** + ```python @@ -71,6 +71,7 @@ M 1000 ``` ### **Java** + ```java @@ -78,8 +79,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0013.Roman to Integer/README_EN.md b/solution/0000-0099/0013.Roman to Integer/README_EN.md index 052fb1d345b72..f7abb973e9628 100644 --- a/solution/0000-0099/0013.Roman to Integer/README_EN.md +++ b/solution/0000-0099/0013.Roman to Integer/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0013.Roman%20to%20Integer/README.md) ## Description -

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    - +

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

     
    @@ -25,72 +24,48 @@ D             500
     
     M             1000
    - -

    For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

    - -

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    - -
      -
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • +
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • -
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • +
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • -
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • +
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    - -

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.

    - -

    Example 1:

    - -
     
     Input: "III"
     
     Output: 3
    - -

    Example 2:

    - -
     
     Input: "IV"
     
     Output: 4
    - -

    Example 3:

    - -
     
     Input: "IX"
     
     Output: 9
    - -

    Example 4:

    - -
     
     Input: "LVIII"
    @@ -101,12 +76,8 @@ M             1000
    - -

    Example 5:

    - -
     
     Input: "MCMXCIV"
    @@ -115,12 +86,8 @@ M             1000
    Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. - - - ## Solutions - ### **Python3** @@ -136,8 +103,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0013.Roman to Integer/Solution.js b/solution/0000-0099/0013.Roman to Integer/Solution.js index 4ef4037aefe6c..570564b764a8e 100644 --- a/solution/0000-0099/0013.Roman to Integer/Solution.js +++ b/solution/0000-0099/0013.Roman to Integer/Solution.js @@ -1,19 +1,19 @@ -const romanToInt = function(s){ +const romanToInt = function (s) { const map = { - 'I' : 1, - 'V' : 5, - 'X' : 10, - 'L' : 50, - 'C' : 100, - 'D' : 500, - 'M' : 1000 + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000, }; let sum = 0; - for(let i = 0; i < s.length;i++){ - if(map[s[i]] < map[s[i+1]]){ - sum-=map[s[i]]; - }else{ - sum+=map[s[i]]; + for (let i = 0; i < s.length; i++) { + if (map[s[i]] < map[s[i + 1]]) { + sum -= map[s[i]]; + } else { + sum += map[s[i]]; } } return sum; diff --git a/solution/0000-0099/0014.Longest Common Prefix/README.md b/solution/0000-0099/0014.Longest Common Prefix/README.md index d48f4c5931e71..81fd1fd12ceb4 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/README.md +++ b/solution/0000-0099/0014.Longest Common Prefix/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md) ## 题目描述 +

    编写一个函数来查找字符串数组中的最长公共前缀。

    @@ -25,15 +26,14 @@

    所有输入只包含小写字母 a-z 。

    - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0014.Longest Common Prefix/README_EN.md b/solution/0000-0099/0014.Longest Common Prefix/README_EN.md index 31b10d1a75cd0..bacab3e1f46dc 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/README_EN.md +++ b/solution/0000-0099/0014.Longest Common Prefix/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md) ## Description -

    Write a function to find the longest common prefix string amongst an array of strings.

    - +

    Write a function to find the longest common prefix string amongst an array of strings.

    If there is no common prefix, return an empty string "".

    - -

    Example 1:

    - -
     
     Input: ["flower","flow","flight"]
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: ["dog","racecar","car"]
    @@ -39,20 +30,12 @@
     
     
    - -

    Note:

    - -

    All given inputs are in lowercase letters a-z.

    - - - ## Solutions - ### **Python3** @@ -68,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0014.Longest Common Prefix/Solution.js b/solution/0000-0099/0014.Longest Common Prefix/Solution.js index 12b315f04fb8a..ef7ba23b82855 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/Solution.js +++ b/solution/0000-0099/0014.Longest Common Prefix/Solution.js @@ -1,11 +1,11 @@ -const longestCommonPrefix = function(strs){ - if(strs.length === 0) return ''; - for(let j = 0; j < strs[0].length; j++){ - for(let i = 0; i < strs.length; i++){ - if(strs[0][j] !== strs[i][j]){ - return strs[0].substring(0,j); +const longestCommonPrefix = function (strs) { + if (strs.length === 0) return ""; + for (let j = 0; j < strs[0].length; j++) { + for (let i = 0; i < strs.length; i++) { + if (strs[0][j] !== strs[i][j]) { + return strs[0].substring(0, j); } } } return strs[0]; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0015.3Sum/README.md b/solution/0000-0099/0015.3Sum/README.md index 0a7d4edc5cadf..4ba195d9a804e 100644 --- a/solution/0000-0099/0015.3Sum/README.md +++ b/solution/0000-0099/0015.3Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0015.3Sum/README_EN.md) ## 题目描述 +

    给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有满足条件且不重复的三元组。

    @@ -21,15 +22,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0015.3Sum/README_EN.md b/solution/0000-0099/0015.3Sum/README_EN.md index c96feb3e074a4..abd2651422ff6 100644 --- a/solution/0000-0099/0015.3Sum/README_EN.md +++ b/solution/0000-0099/0015.3Sum/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0015.3Sum/README.md) ## Description -

    Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

    - +

    Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

    Note:

    - -

    The solution set must not contain duplicate triplets.

    - -

    Example:

    - -
     
     Given array nums = [-1, 0, 1, 2, -1, -4],
    @@ -37,10 +30,8 @@ A solution set is:
     
     
    - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ A solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0016.3Sum Closest/README.md b/solution/0000-0099/0016.3Sum Closest/README.md index ae636f948a890..3a659676428c1 100644 --- a/solution/0000-0099/0016.3Sum Closest/README.md +++ b/solution/0000-0099/0016.3Sum Closest/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md) ## 题目描述 +

    给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。

    @@ -11,15 +12,14 @@ 与 target 最接近的三个数的和为 2. (-1 + 2 + 1 = 2). - - ## 解法 - + ### **Python3** + ```python @@ -27,6 +27,7 @@ ``` ### **Java** + ```java @@ -34,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0016.3Sum Closest/README_EN.md b/solution/0000-0099/0016.3Sum Closest/README_EN.md index b89f1871b95ae..8a3aaa2484ffa 100644 --- a/solution/0000-0099/0016.3Sum Closest/README_EN.md +++ b/solution/0000-0099/0016.3Sum Closest/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0016.3Sum%20Closest/README.md) ## Description -

    Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

    - +

    Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

    Example:

    - -
     
     Given array nums = [-1, 2, 1, -4], and target = 1.
    @@ -21,12 +18,8 @@ The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
     
     
    - - - ## Solutions - ### **Python3** @@ -42,8 +35,9 @@ The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md index 966e9c5b0ef9f..0634cfc3756fe 100644 --- a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md +++ b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md) ## 题目描述 +

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。

    @@ -19,15 +20,14 @@

    说明:
    尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。

    - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md index 39c84df2e7cc7..ff94318cc7ea0 100644 --- a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md +++ b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md @@ -3,19 +3,15 @@ [中文文档](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md) ## Description -

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

    - +

    Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.

    ![](./images/17_telephone_keypad.png) -

    Example:

    - -
     
     Input: "23"
    @@ -24,20 +20,12 @@
     
     
    - -

    Note:

    - -

    Although the above answer is in lexicographical order, your answer could be in any order you want.

    - - - ## Solutions - ### **Python3** @@ -53,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0018.4Sum/README.md b/solution/0000-0099/0018.4Sum/README.md index c399d858c1d33..7de062388b543 100644 --- a/solution/0000-0099/0018.4Sum/README.md +++ b/solution/0000-0099/0018.4Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0018.4Sum/README_EN.md) ## 题目描述 +

    给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。

    @@ -22,15 +23,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0018.4Sum/README_EN.md b/solution/0000-0099/0018.4Sum/README_EN.md index 1860ed1afc8bb..adfc4c910cdab 100644 --- a/solution/0000-0099/0018.4Sum/README_EN.md +++ b/solution/0000-0099/0018.4Sum/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0018.4Sum/README.md) ## Description -

    Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

    - +

    Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

    Note:

    - -

    The solution set must not contain duplicate quadruplets.

    - -

    Example:

    - -
     
     Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.
    @@ -39,12 +32,8 @@ A solution set is:
     
     
    - - - ## Solutions - ### **Python3** @@ -60,8 +49,9 @@ A solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md index 137d0793eed70..e439b292ff9f6 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md @@ -1,8 +1,9 @@ -# [19. 删除链表的倒数第N个节点](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) +# [19. 删除链表的倒数第 N 个节点](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) [English Version](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md) ## 题目描述 +

    给定一个链表,删除链表的倒数第 个节点,并且返回链表的头结点。

    @@ -21,15 +22,14 @@

    你能尝试使用一趟扫描实现吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md index 3bfa09a67c17f..82bd63a4851ff 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md) ## Description -

    Given a linked list, remove the n-th node from the end of list and return its head.

    - +

    Given a linked list, remove the n-th node from the end of list and return its head.

    Example:

    - -
     
     Given linked list: 1->2->3->4->5, and n = 2.
    @@ -21,28 +18,16 @@ After removing the second node from the end, the linked list becomes 1-&
     
     
    - -

    Note:

    - -

    Given n will always be valid.

    - -

    Follow up:

    - -

    Could you do this in one pass?

    - - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ After removing the second node from the end, the linked list becomes 1-& ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js b/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js index ab98a2c7e26f0..cca2368bc21f7 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js @@ -1,13 +1,15 @@ -const removeNthFromEnd = function(head, n){ - let left, before, right = head; - left = before = {next: head}; - while(n--){ - right = right.next; +const removeNthFromEnd = function (head, n) { + let left, + before, + right = head; + left = before = { next: head }; + while (n--) { + right = right.next; } - while(right){ - right =right.next; - left = left.next; + while (right) { + right = right.next; + left = left.next; } left.next = left.next.next; return before.next; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0020.Valid Parentheses/README.md b/solution/0000-0099/0020.Valid Parentheses/README.md index 63ed2d53957df..7e93f38b9493a 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README.md +++ b/solution/0000-0099/0020.Valid Parentheses/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) ## 题目描述 +

    给定一个只包括 '('')''{''}''['']' 的字符串,判断字符串是否有效。

    @@ -44,15 +45,14 @@
    输入: "{[]}"
     输出: true
    - - ## 解法 - + ### **Python3** + ```python @@ -60,6 +60,7 @@ ``` ### **Java** + ```java @@ -67,8 +68,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/solution/0000-0099/0020.Valid Parentheses/README_EN.md index dda56fa473a6c..d466b4bbe96fb 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0020.Valid Parentheses/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0000-0099/0020.Valid%20Parentheses/README.md) ## Description -

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

    - +

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

    An input string is valid if:

    - -
      -
    1. Open brackets must be closed by the same type of brackets.
    2. +
    3. Open brackets must be closed by the same type of brackets.
    4. -
    5. Open brackets must be closed in the correct order.
    6. +
    7. Open brackets must be closed in the correct order.
    - -

    Note that an empty string is also considered valid.

    - -

    Example 1:

    - -
     
     Input: "()"
    @@ -37,12 +28,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "()[]{}"
    @@ -51,12 +38,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "(]"
    @@ -65,12 +48,8 @@
     
     
    - -

    Example 4:

    - -
     
     Input: "([)]"
    @@ -79,12 +58,8 @@
     
     
    - -

    Example 5:

    - -
     
     Input: "{[]}"
    @@ -93,12 +68,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -114,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0020.Valid Parentheses/Solution.js b/solution/0000-0099/0020.Valid Parentheses/Solution.js index dc59c7cf0600a..1762946b7e25b 100644 --- a/solution/0000-0099/0020.Valid Parentheses/Solution.js +++ b/solution/0000-0099/0020.Valid Parentheses/Solution.js @@ -1,14 +1,14 @@ -const isValid = function(s){ +const isValid = function (s) { let arr = []; - for(let i = 0; i < s.length; i++){ - if(s[i] === '{' || s[i] === '[' || s[i] === '('){ + for (let i = 0; i < s.length; i++) { + if (s[i] === "{" || s[i] === "[" || s[i] === "(") { arr.push(s[i]); - }else{ - if(s[i] === ')' && arr[arr.length-1] === '(') arr.pop(); - else if(s[i] === ']' && arr[arr.length-1] === '[') arr.pop(); - else if(s[i] === '}' && arr[arr.length-1] === '{') arr.pop(); + } else { + if (s[i] === ")" && arr[arr.length - 1] === "(") arr.pop(); + else if (s[i] === "]" && arr[arr.length - 1] === "[") arr.pop(); + else if (s[i] === "}" && arr[arr.length - 1] === "{") arr.pop(); else return false; } } return arr.length === 0; -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md index 712b78f6d9648..10c56d22b7174 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) ## 题目描述 +

    将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 

    @@ -12,15 +13,14 @@ 输出:1->1->2->3->4->4 - - ## 解法 - + ### **Python3** + ```python @@ -28,6 +28,7 @@ ``` ### **Java** + ```java @@ -35,8 +36,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md index 322145cd8e57e..d422acfa17dc1 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md) ## Description -

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

    - +

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

    Example: @@ -19,10 +18,8 @@

    - ## Solutions - ### **Python3** @@ -38,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js index b1ee023fcb56f..83553675d9e20 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js @@ -9,7 +9,8 @@ const mergeTwoLists2 = function (l1, l2) { return l2; } if (l1 !== null && l2 !== null) { - let t = null, h = null; + let t = null, + h = null; if (l1.val > l2.val) { t = l2; h = l2; @@ -42,7 +43,7 @@ const mergeTwoLists2 = function (l1, l2) { } return h; } -} +}; const mergeTwoLists = function (l1, l2) { if (l1 === null) return l2; @@ -54,4 +55,4 @@ const mergeTwoLists = function (l1, l2) { l2.next = mergeTwoLists(l1, l2.next); return l2; } -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0022.Generate Parentheses/README.md b/solution/0000-0099/0022.Generate Parentheses/README.md index 566acdf11f96d..94c9825c523e9 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README.md +++ b/solution/0000-0099/0022.Generate Parentheses/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md) ## 题目描述 +

    给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。

    @@ -17,15 +18,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0022.Generate Parentheses/README_EN.md b/solution/0000-0099/0022.Generate Parentheses/README_EN.md index 7948ecd7201be..73ca9e10e526e 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README_EN.md +++ b/solution/0000-0099/0022.Generate Parentheses/README_EN.md @@ -3,14 +3,13 @@ [中文文档](/solution/0000-0099/0022.Generate%20Parentheses/README.md) ## Description +

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

    - -

    For example, given n = 3, a solution set is: @@ -35,10 +34,8 @@ For example, given n = 3, a solution set is: - ## Solutions - ### **Python3** @@ -54,8 +51,9 @@ For example, given n = 3, a solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README.md b/solution/0000-0099/0023.Merge k Sorted Lists/README.md index 1094cbb2de152..bc606577a3100 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README.md @@ -1,8 +1,9 @@ -# [23. 合并K个排序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists) +# [23. 合并 K 个排序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists) [English Version](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) ## 题目描述 +

    合并 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。

    @@ -16,15 +17,14 @@ ] 输出: 1->1->2->3->4->4->5->6 - - ## 解法 - + ### **Python3** + ```python @@ -32,6 +32,7 @@ ``` ### **Java** + ```java @@ -39,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md index 72fb7318c0fd2..4a3fc04bafa72 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md) ## Description -

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

    - +

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

    Example:

    - -
     
     Input:
    @@ -29,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -50,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md index 71facf4262a32..09f9daee9e468 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) ## 题目描述 +

    给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。

    @@ -15,15 +16,14 @@
    给定 1->2->3->4, 你应该返回 2->1->4->3.
     
    - - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md index d52d51b2528e9..33a3b8d870d50 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md) ## Description -

    Given a linked list, swap every two adjacent nodes and return its head.

    - +

    Given a linked list, swap every two adjacent nodes and return its head.

    You may not modify the values in the list's nodes, only nodes itself may be changed.

    - -

     

    - -

    Example:

    - -
     
     Given 1->2->3->4, you should return the list as 2->1->4->3.
     
     
    - - - ## Solutions - ### **Python3** @@ -46,8 +35,9 @@ Given 1->2->3->4, you should return the list as 2-&g ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md index ed214a9af07e4..a8022cce23fe2 100644 --- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md +++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md) ## 题目描述 +

    给你一个链表,每 个节点一组进行翻转,请你返回翻转后的链表。

    @@ -29,15 +30,14 @@
  • 你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。
  • - - ## 解法 - + ### **Python3** + ```python @@ -45,6 +45,7 @@ ``` ### **Java** + ```java @@ -52,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md index 90d54bf622fb7..bf45103174702 100644 --- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md +++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md @@ -3,54 +3,35 @@ [中文文档](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md) ## Description -

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

    - +

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

    k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

    - -
    - -

    Example:

    - -

    Given this linked list: 1->2->3->4->5

    - -

    For k = 2, you should return: 2->1->4->3->5

    - -

    For k = 3, you should return: 3->2->1->4->5

    - -

    Note:

    - -
      -
    • Only constant extra memory is allowed.
    • +
    • Only constant extra memory is allowed.
    • -
    • You may not alter the values in the list's nodes, only nodes itself may be changed.
    • +
    • You may not alter the values in the list's nodes, only nodes itself may be changed.
    - - - ## Solutions - ### **Python3** @@ -66,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md index 96052c625e537..dc51dfb669135 100644 --- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md +++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md) ## 题目描述 +

    给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。

    @@ -47,15 +48,14 @@ for (int i = 0; i < len; i++) { } - - ## 解法 - + ### **Python3** + ```python @@ -63,6 +63,7 @@ for (int i = 0; i < len; i++) { ``` ### **Java** + ```java @@ -70,8 +71,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md index 638e44384f5fd..2d88f4811e087 100644 --- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md +++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md) ## Description -

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.

    - +

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    - -

    Example 1:

    - -
     
     Given nums = [1,1,2],
    @@ -27,12 +22,8 @@ Your function should return length = 2, with the f
     
     It doesn't matter what you leave beyond the returned length.
    - -

    Example 2:

    - -
     
     Given nums = [0,0,1,1,1,2,2,3,3,4],
    @@ -47,24 +38,14 @@ It doesn't matter what values are set beyond the returned length.
     
     
    - -

    Clarification:

    - -

    Confused why the returned value is an integer but your answer is an array?

    - -

    Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.

    - -

    Internally you can think of this:

    - -
     
     // nums is passed in by reference. (i.e., without making a copy)
    @@ -83,10 +64,8 @@ for (int i = 0; i < len; i++) {
     
     }
    - ## Solutions - ### **Python3** @@ -102,8 +81,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js index 8b0bac0adc70a..02084311a426c 100644 --- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js +++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js @@ -1,11 +1,11 @@ -const removeDuplicates = function(nums){ +const removeDuplicates = function (nums) { let i = 1; let t = 0; let t2 = nums[0]; let res = 1; let length = nums.length; - for(let k = 1; k < length; k++){ - if(nums[k] - nums[k-1] !== 0 && nums[k] !== t2){ + for (let k = 1; k < length; k++) { + if (nums[k] - nums[k - 1] !== 0 && nums[k] !== t2) { t2 = nums[k]; t = nums[i]; nums[i] = nums[k]; @@ -15,4 +15,4 @@ const removeDuplicates = function(nums){ } } return res; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0027.Remove Element/README.md b/solution/0000-0099/0027.Remove Element/README.md index e3c044400ac68..c50b5f4509341 100644 --- a/solution/0000-0099/0027.Remove Element/README.md +++ b/solution/0000-0099/0027.Remove Element/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0027.Remove%20Element/README_EN.md) ## 题目描述 +

    给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。

    @@ -52,15 +53,14 @@ for (int i = 0; i < len; i++) { } - - ## 解法 - + ### **Python3** + ```python @@ -68,6 +68,7 @@ for (int i = 0; i < len; i++) { ``` ### **Java** + ```java @@ -75,8 +76,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0027.Remove Element/README_EN.md b/solution/0000-0099/0027.Remove Element/README_EN.md index 767530f246cd3..1774515cc6b33 100644 --- a/solution/0000-0099/0027.Remove Element/README_EN.md +++ b/solution/0000-0099/0027.Remove Element/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0027.Remove%20Element/README.md) ## Description -

    Given an array nums and a value val, remove all instances of that value in-place and return the new length.

    - +

    Given an array nums and a value val, remove all instances of that value in-place and return the new length.

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    - -

    The order of elements can be changed. It doesn't matter what you leave beyond the new length.

    - -

    Example 1:

    - -
     
     Given nums = [3,2,2,3], val = 3,
    @@ -33,12 +26,8 @@ It doesn't matter what you leave beyond the returned length.
     
     
    - -

    Example 2:

    - -
     
     Given nums = [0,1,2,2,3,0,4,2], val = 2,
    @@ -55,24 +44,14 @@ Note that the order of those five elements can be arbitrary.
     
     It doesn't matter what values are set beyond the returned length.
    - -

    Clarification:

    - -

    Confused why the returned value is an integer but your answer is an array?

    - -

    Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.

    - -

    Internally you can think of this:

    - -
     
     // nums is passed in by reference. (i.e., without making a copy)
    @@ -91,10 +70,8 @@ for (int i = 0; i < len; i++) {
     
     }
    - ## Solutions - ### **Python3** @@ -110,8 +87,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0027.Remove Element/Solution.js b/solution/0000-0099/0027.Remove Element/Solution.js index b4d8bcc06deca..9a6bc0c76db12 100644 --- a/solution/0000-0099/0027.Remove Element/Solution.js +++ b/solution/0000-0099/0027.Remove Element/Solution.js @@ -1,31 +1,31 @@ var removeElement3 = function (nums, val) { - let len = nums.length + let len = nums.length; if (len < 1) { - return 0 + return 0; } - let i = 0 + let i = 0; while (i < len) { if (nums[i] === val) { - nums[i] = nums[len - 1] - len-- + nums[i] = nums[len - 1]; + len--; } else { - i++ + i++; } } - return len + return len; }; var removeElement2 = function (nums, val) { - let i = 0 + let i = 0; for (let j = 0; j < nums.length; j++) { if (nums[j] !== val) { - nums[i] = nums[j] - i++ + nums[i] = nums[j]; + i++; } } - return i -} + return i; +}; var removeElement = function (nums, val) { let len = nums.length; @@ -36,4 +36,4 @@ var removeElement = function (nums, val) { } } return len; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0028.Implement strStr()/README.md b/solution/0000-0099/0028.Implement strStr()/README.md index e3b5a09c1020e..2add41571221e 100644 --- a/solution/0000-0099/0028.Implement strStr()/README.md +++ b/solution/0000-0099/0028.Implement strStr()/README.md @@ -1,8 +1,9 @@ # [28. 实现 strStr()](https://leetcode-cn.com/problems/implement-strstr) -[English Version](/solution/0000-0099/0028.Implement%20strStr()/README_EN.md) +[English Version]() ## 题目描述 +

    实现 strStr() 函数。

    @@ -26,15 +27,14 @@

    对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。

    - - ## 解法 - + ### **Python3** + ```python @@ -42,6 +42,7 @@ ``` ### **Java** + ```java @@ -49,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0028.Implement strStr()/README_EN.md b/solution/0000-0099/0028.Implement strStr()/README_EN.md index d7c32e3e00626..b6929028eb663 100644 --- a/solution/0000-0099/0028.Implement strStr()/README_EN.md +++ b/solution/0000-0099/0028.Implement strStr()/README_EN.md @@ -1,20 +1,15 @@ # [28. Implement strStr()](https://leetcode.com/problems/implement-strstr) -[中文文档](/solution/0000-0099/0028.Implement%20strStr()/README.md) +[中文文档]() ## Description -

    Implement strStr().

    - +

    Implement strStr().

    Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

    - -

    Example 1:

    - -
     
     Input: haystack = "hello", needle = "ll"
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: haystack = "aaaaa", needle = "bba"
    @@ -37,24 +28,14 @@
     
     
    - -

    Clarification:

    - -

    What should we return when needle is an empty string? This is a great question to ask during an interview.

    - -

    For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().

    - - - ## Solutions - ### **Python3** @@ -70,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0028.Implement strStr()/Solution.js b/solution/0000-0099/0028.Implement strStr()/Solution.js index 54dd21355df5d..76e29daee2181 100644 --- a/solution/0000-0099/0028.Implement strStr()/Solution.js +++ b/solution/0000-0099/0028.Implement strStr()/Solution.js @@ -4,19 +4,19 @@ * @return {number} */ var strStr = function (haystack, needle) { - const slen = haystack.length - const plen = needle.length - if (slen == plen) { - return haystack == needle ? 0 : -1 + const slen = haystack.length; + const plen = needle.length; + if (slen == plen) { + return haystack == needle ? 0 : -1; + } + for (let i = 0; i <= slen - plen; i++) { + let j; + for (j = 0; j < plen; j++) { + if (haystack[i + j] != needle[j]) { + break; + } } - for (let i = 0; i <= slen - plen; i++) { - let j - for (j = 0; j < plen; j++) { - if (haystack[i + j] != needle[j]) { - break - } - } - if (j == plen) return i - } - return -1 + if (j == plen) return i; + } + return -1; }; diff --git a/solution/0000-0099/0029.Divide Two Integers/README.md b/solution/0000-0099/0029.Divide Two Integers/README.md index 3aec5adbe0599..a0d4110f34972 100644 --- a/solution/0000-0099/0029.Divide Two Integers/README.md +++ b/solution/0000-0099/0029.Divide Two Integers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md) ## 题目描述 +

    给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。

    @@ -34,15 +35,14 @@
  • 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231,  231 − 1]。本题中,如果除法结果溢出,则返回 231 − 1。
  • - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0029.Divide Two Integers/README_EN.md b/solution/0000-0099/0029.Divide Two Integers/README_EN.md index a806a328ab9d6..41687328f3a76 100644 --- a/solution/0000-0099/0029.Divide Two Integers/README_EN.md +++ b/solution/0000-0099/0029.Divide Two Integers/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0029.Divide%20Two%20Integers/README.md) ## Description +

    Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.

    Return the quotient after dividing dividend by divisor.

    @@ -33,11 +34,8 @@
  • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
  • - - ## Solutions - ### **Python3** @@ -53,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md index 304f4a3eff3ca..f609581f9f8d2 100644 --- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md +++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md) ## 题目描述 +

    给定一个字符串 和一些长度相同的单词 words。找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置。

    @@ -29,15 +30,14 @@ 输出:[] - - ## 解法 - + ### **Python3** + ```python @@ -45,6 +45,7 @@ ``` ### **Java** + ```java @@ -52,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md index 1172d9f0ac0c2..aea840fe735cc 100644 --- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md +++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md) ## Description +

    You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.

     

    @@ -27,11 +28,8 @@ The output order does not matter, returning [9,0] is fine too. Output: [] - - ## Solutions - ### **Python3** @@ -47,8 +45,9 @@ The output order does not matter, returning [9,0] is fine too. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0031.Next Permutation/README.md b/solution/0000-0099/0031.Next Permutation/README.md index c66b99afa2c7d..f5db1fe7e7c5f 100644 --- a/solution/0000-0099/0031.Next Permutation/README.md +++ b/solution/0000-0099/0031.Next Permutation/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0031.Next%20Permutation/README_EN.md) ## 题目描述 +

    实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。

    @@ -15,15 +16,14 @@ 3,2,11,2,3
    1,1,51,5,1

    - - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0031.Next Permutation/README_EN.md b/solution/0000-0099/0031.Next Permutation/README_EN.md index 8381cade5ecf9..46c660f584437 100644 --- a/solution/0000-0099/0031.Next Permutation/README_EN.md +++ b/solution/0000-0099/0031.Next Permutation/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/solution/0000-0099/0031.Next%20Permutation/README.md) ## Description -

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

    - +

    Implement next 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 order (ie, sorted in ascending order).

    - -

    The replacement must be in-place and use only constant extra memory.

    - -

    Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.

    - -

    1,2,31,3,2
    3,2,11,2,3
    1,1,51,5,1

    - - - ## Solutions - ### **Python3** @@ -46,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README.md b/solution/0000-0099/0032.Longest Valid Parentheses/README.md index 00c203e45e961..cf52c62fa8557 100644 --- a/solution/0000-0099/0032.Longest Valid Parentheses/README.md +++ b/solution/0000-0099/0032.Longest Valid Parentheses/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md) ## 题目描述 +

    给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。

    @@ -20,15 +21,14 @@ 解释: 最长有效括号子串为 "()()" - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md index 0ff90ff98bec8..f6f2412681c4a 100644 --- a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md) ## Description -

    Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

    - +

    Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

    Example 1:

    - -
     
     Input: "(()"
    @@ -21,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: ")()())"
    @@ -37,12 +30,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -58,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md index dfe56d7946626..bbc59c10bb224 100644 --- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md +++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md) ## 题目描述 +

    假设按照升序排序的数组在预先未知的某个点上进行了旋转。

    @@ -25,15 +26,14 @@
    输入: nums = [4,5,6,7,0,1,2], target = 3
     输出: -1
    - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md index 2242c164c026c..5769ad8add2c1 100644 --- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md +++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md @@ -3,30 +3,19 @@ [中文文档](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md) ## Description -

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    - +

    Suppose an array sorted in ascending order 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 return its index, otherwise return -1.

    - -

    You may assume no duplicate exists in the array.

    - -

    Your algorithm's runtime complexity must be in the order of O(log n).

    - -

    Example 1:

    - -
     
     Input: nums = [4,5,6,7,0,1,2], target = 0
    @@ -35,24 +24,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: nums = [4,5,6,7,0,1,2], target = 3
     
     Output: -1
    - - - ## Solutions - ### **Python3** @@ -68,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js b/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js index 21c2bccae9806..700b830e84cf7 100644 --- a/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js +++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js @@ -4,10 +4,10 @@ * @return {number} */ var search = function (nums, target) { - for (let i = 0; i < nums.length; i++) { - if (nums[i] == target) { - return i - } + for (let i = 0; i < nums.length; i++) { + if (nums[i] == target) { + return i; } - return -1 -}; \ No newline at end of file + } + return -1; +}; diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md index 88b2744f457d5..f323fcc1cf6cf 100644 --- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md +++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md) ## 题目描述 +

    给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。

    @@ -20,15 +21,14 @@
    输入: nums = [5,7,7,8,8,10], target = 6
     输出: [-1,-1]
    - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md index f1b20977890d9..570c6d605f3b6 100644 --- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md +++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md @@ -3,46 +3,31 @@ [中文文档](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md) ## Description -

    Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

    - +

    Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

    Your algorithm's runtime complexity must be in the order of O(log n).

    - -

    If the target is not found in the array, return [-1, -1].

    - -

    Example 1:

    - -
     
     Input: nums = [5,7,7,8,8,10], target = 8
     
     Output: [3,4]
    - -

    Example 2:

    - -
     
     Input: nums = [5,7,7,8,8,10], target = 6
     
     Output: [-1,-1]
    - - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0035.Search Insert Position/README.md b/solution/0000-0099/0035.Search Insert Position/README.md index 1ae86d8f2e162..31f70eca0bda8 100644 --- a/solution/0000-0099/0035.Search Insert Position/README.md +++ b/solution/0000-0099/0035.Search Insert Position/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md) ## 题目描述 +

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

    @@ -32,15 +33,14 @@ 输出: 0 - - ## 解法 - + ### **Python3** + ```python @@ -48,6 +48,7 @@ ``` ### **Java** + ```java @@ -55,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0035.Search Insert Position/README_EN.md b/solution/0000-0099/0035.Search Insert Position/README_EN.md index 8d3786f7fa664..780fa28dd26c2 100644 --- a/solution/0000-0099/0035.Search Insert Position/README_EN.md +++ b/solution/0000-0099/0035.Search Insert Position/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0035.Search%20Insert%20Position/README.md) ## Description -

    Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

    - +

    Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

    You may assume no duplicates in the array.

    - -

    Example 1:

    - -
     
     Input: [1,3,5,6], 5
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [1,3,5,6], 2
    @@ -37,12 +28,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: [1,3,5,6], 7
    @@ -51,12 +38,8 @@
     
     
    - -

    Example 4:

    - -
     
     Input: [1,3,5,6], 0
    @@ -65,12 +48,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -86,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0035.Search Insert Position/Solution.js b/solution/0000-0099/0035.Search Insert Position/Solution.js index 5d00ff46ede2c..6c844fd643c10 100644 --- a/solution/0000-0099/0035.Search Insert Position/Solution.js +++ b/solution/0000-0099/0035.Search Insert Position/Solution.js @@ -5,7 +5,7 @@ var searchInsert2 = function (nums, target) { } } return nums.length; -} +}; var searchInsert = function (nums, target) { let left = 0; @@ -39,4 +39,4 @@ var searchInsert = function (nums, target) { } return left; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0036.Valid Sudoku/README.md b/solution/0000-0099/0036.Valid Sudoku/README.md index 6b4f19c849fcd..fbfba55c374fe 100644 --- a/solution/0000-0099/0036.Valid Sudoku/README.md +++ b/solution/0000-0099/0036.Valid Sudoku/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md) ## 题目描述 +

    判断一个 9x9 的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可。

    @@ -62,15 +63,14 @@
  • 给定数独永远是 9x9 形式的。
  • - - ## 解法 - + ### **Python3** + ```python @@ -78,6 +78,7 @@ ``` ### **Java** + ```java @@ -85,8 +86,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0036.Valid Sudoku/README_EN.md b/solution/0000-0099/0036.Valid Sudoku/README_EN.md index fe61a40292a75..0c466b501b984 100644 --- a/solution/0000-0099/0036.Valid Sudoku/README_EN.md +++ b/solution/0000-0099/0036.Valid Sudoku/README_EN.md @@ -3,36 +3,27 @@ [中文文档](/solution/0000-0099/0036.Valid%20Sudoku/README.md) ## Description -

    Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

    - +

    Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

      -
    1. Each row must contain the digits 1-9 without repetition.
    2. +
    3. Each row must contain the digits 1-9 without repetition.
    4. -
    5. Each column must contain the digits 1-9 without repetition.
    6. +
    7. Each column must contain the digits 1-9 without repetition.
    8. -
    9. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
    10. +
    11. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
    - -


    A partially filled sudoku which is valid.

    - -

    The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

    - -

    Example 1:

    - -
     
     Input:
    @@ -63,12 +54,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -103,30 +90,22 @@
     
     
    - -

    Note:

    - -
      -
    • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
    • +
    • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
    • -
    • Only the filled cells need to be validated according to the mentioned rules.
    • +
    • Only the filled cells need to be validated according to the mentioned rules.
    • -
    • The given board contain only digits 1-9 and the character '.'.
    • +
    • The given board contain only digits 1-9 and the character '.'.
    • -
    • The given board size is always 9x9.
    • +
    • The given board size is always 9x9.
    - - - ## Solutions - ### **Python3** @@ -142,8 +121,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0036.Valid Sudoku/Solution.js b/solution/0000-0099/0036.Valid Sudoku/Solution.js index 01e22e2ffb93f..a58a823d06f89 100644 --- a/solution/0000-0099/0036.Valid Sudoku/Solution.js +++ b/solution/0000-0099/0036.Valid Sudoku/Solution.js @@ -1,35 +1,40 @@ -const isValidSudoku = function(board){ +const isValidSudoku = function (board) { let existed = new Set(); - for(let i = 0; i < 9; i++){ - for(let j = 0; j < 9; j++){ + for (let i = 0; i < 9; i++) { + for (let j = 0; j < 9; j++) { let number = board[i][j]; - if(board[i][j] !== '.'){ - if(existed.has(number + " in row " + i )|| - existed.has(number + ' in column ' + j) || - existed.has(number + 'in block ' + parseInt(i/3) + '-' + parseInt(j/3))){ - return false; - }else{ - existed.add(number + " in row " + i ); - existed.add(number + ' in column ' + j); - existed.add(number + 'in block ' + parseInt(i/3) + '-' + parseInt(j/3)); - } + if (board[i][j] !== ".") { + if ( + existed.has(number + " in row " + i) || + existed.has(number + " in column " + j) || + existed.has( + number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3) + ) + ) { + return false; + } else { + existed.add(number + " in row " + i); + existed.add(number + " in column " + j); + existed.add( + number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3) + ); + } } } } return true; }; - /** * @param {character[][]} board * @return {boolean} */ -const isValidSudoku2 = function(board){ - function lineTest(arr){ - for(let i = 0; i < 9; i++){ - for(let j = 0; j < 9; j++){ - for(let k = j+1; k < 9; k++){ - if(arr[i][j] === arr[i][k] && arr[i][j] !== '.'){ +const isValidSudoku2 = function (board) { + function lineTest(arr) { + for (let i = 0; i < 9; i++) { + for (let j = 0; j < 9; j++) { + for (let k = j + 1; k < 9; k++) { + if (arr[i][j] === arr[i][k] && arr[i][j] !== ".") { return false; } } @@ -37,12 +42,11 @@ const isValidSudoku2 = function(board){ } return true; } - function columnTest(arr){ - for(let i = 0; i < 9; i++){ - for(let j = 0; j < 9;j++){ - for(let k = j+1; k < 9; k++){ - if(arr[j][i] === arr[k][i] && arr[j][i] !== '.'){ - + function columnTest(arr) { + for (let i = 0; i < 9; i++) { + for (let j = 0; j < 9; j++) { + for (let k = j + 1; k < 9; k++) { + if (arr[j][i] === arr[k][i] && arr[j][i] !== ".") { return false; } } @@ -50,27 +54,35 @@ const isValidSudoku2 = function(board){ } return true; } - function squareTest(arr){ - let p = [[1,1],[1,4],[1,7], - [4,1],[4,4],[4,7], - [7,1],[7,4],[7,7]]; - - for(let i = 0; i < p.length; i++){ + function squareTest(arr) { + let p = [ + [1, 1], + [1, 4], + [1, 7], + [4, 1], + [4, 4], + [4, 7], + [7, 1], + [7, 4], + [7, 7], + ]; + + for (let i = 0; i < p.length; i++) { let a = []; let x = p[i][0]; let y = p[i][1]; - a.push(arr[x-1][y-1]); - a.push(arr[x-1][y]); - a.push(arr[x-1][y+1]); - a.push(arr[x][y-1]); + a.push(arr[x - 1][y - 1]); + a.push(arr[x - 1][y]); + a.push(arr[x - 1][y + 1]); + a.push(arr[x][y - 1]); a.push(arr[x][y]); - a.push(arr[x][y+1]); - a.push(arr[x+1][y-1]); - a.push(arr[x+1][y]); - a.push(arr[x+1][y+1]); - for(let j = 0; j < a.length; j++){ - for(let k = j+1; k < a.length; k++){ - if(a[j] === a[k] && a[j] !== '.'){ + a.push(arr[x][y + 1]); + a.push(arr[x + 1][y - 1]); + a.push(arr[x + 1][y]); + a.push(arr[x + 1][y + 1]); + for (let j = 0; j < a.length; j++) { + for (let k = j + 1; k < a.length; k++) { + if (a[j] === a[k] && a[j] !== ".") { return false; } } @@ -78,5 +90,5 @@ const isValidSudoku2 = function(board){ } return true; } - return lineTest(board)&&columnTest(board)&&squareTest(board); + return lineTest(board) && columnTest(board) && squareTest(board); }; diff --git a/solution/0000-0099/0037.Sudoku Solver/README.md b/solution/0000-0099/0037.Sudoku Solver/README.md index 980e8751c8e92..7550445cbc3e6 100644 --- a/solution/0000-0099/0037.Sudoku Solver/README.md +++ b/solution/0000-0099/0037.Sudoku Solver/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md) ## 题目描述 +

    编写一个程序,通过已填充的空格来解决数独问题。

    @@ -32,15 +33,14 @@
  • 给定数独永远是 9x9 形式的。
  • - - ## 解法 - + ### **Python3** + ```python @@ -48,6 +48,7 @@ ``` ### **Java** + ```java @@ -55,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0037.Sudoku Solver/README_EN.md b/solution/0000-0099/0037.Sudoku Solver/README_EN.md index 4088a6d7bd70e..df04bec6cf58d 100644 --- a/solution/0000-0099/0037.Sudoku Solver/README_EN.md +++ b/solution/0000-0099/0037.Sudoku Solver/README_EN.md @@ -3,62 +3,45 @@ [中文文档](/solution/0000-0099/0037.Sudoku%20Solver/README.md) ## Description -

    Write a program to solve a Sudoku puzzle by filling the empty cells.

    - +

    Write a program to solve a Sudoku puzzle by filling the empty cells.

    A sudoku solution must satisfy all of the following rules:

    - -
      -
    1. Each of the digits 1-9 must occur exactly once in each row.
    2. +
    3. Each of the digits 1-9 must occur exactly once in each row.
    4. -
    5. Each of the digits 1-9 must occur exactly once in each column.
    6. +
    7. Each of the digits 1-9 must occur exactly once in each column.
    8. -
    9. Each of the the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    10. +
    11. Each of the the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    - -

    Empty cells are indicated by the character '.'.

    - -


    A sudoku puzzle...

    - -


    ...and its solution numbers marked in red.

    - -

    Note:

    - -
      -
    • The given board contain only digits 1-9 and the character '.'.
    • +
    • The given board contain only digits 1-9 and the character '.'.
    • -
    • You may assume that the given Sudoku puzzle will have a single unique solution.
    • +
    • You may assume that the given Sudoku puzzle will have a single unique solution.
    • -
    • The given board size is always 9x9.
    • +
    • The given board size is always 9x9.
    - - - ## Solutions - ### **Python3** @@ -74,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0038.Count and Say/README.md b/solution/0000-0099/0038.Count and Say/README.md index 58129268458d7..3ff853b17300e 100644 --- a/solution/0000-0099/0038.Count and Say/README.md +++ b/solution/0000-0099/0038.Count and Say/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0038.Count%20and%20Say/README_EN.md) ## 题目描述 +

    「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。前五项如下:

    @@ -35,15 +36,14 @@ 输出: "1211" 解释:当 n = 3 时,序列是 "21",其中我们有 "2" 和 "1" 两组,"2" 可以读作 "12",也就是出现频次 = 1 而 值 = 2;类似 "1" 可以读作 "11"。所以答案是 "12" 和 "11" 组合在一起,也就是 "1211"。 - - ## 解法 - + ### **Python3** + ```python @@ -51,6 +51,7 @@ ``` ### **Java** + ```java @@ -58,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0038.Count and Say/README_EN.md b/solution/0000-0099/0038.Count and Say/README_EN.md index c0a84ccd753c2..51154c70db164 100644 --- a/solution/0000-0099/0038.Count and Say/README_EN.md +++ b/solution/0000-0099/0038.Count and Say/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0038.Count%20and%20Say/README.md) ## Description +

    The count-and-say sequence is the sequence of integers with the first five terms as following:

    @@ -39,11 +40,8 @@
     Explanation: For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211".
     
    - - ## Solutions - ### **Python3** @@ -59,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0038.Count and Say/Solution.js b/solution/0000-0099/0038.Count and Say/Solution.js index e01af9d715166..972b40d35ff49 100644 --- a/solution/0000-0099/0038.Count and Say/Solution.js +++ b/solution/0000-0099/0038.Count and Say/Solution.js @@ -1,13 +1,15 @@ -const countAndSay = function(n){ - let s = '1'; +const countAndSay = function (n) { + let s = "1"; - for(let i = 2; i <= n; i++){ - let count = 1, str = '', len = s.length; + for (let i = 2; i <= n; i++) { + let count = 1, + str = "", + len = s.length; - for(let j = 0 ; j < len; j++){ - if(j < len - 1 && s[j] === s[j + 1]){ + for (let j = 0; j < len; j++) { + if (j < len - 1 && s[j] === s[j + 1]) { count++; - }else{ + } else { str += `${count}${s[j]}`; count = 1; } @@ -15,4 +17,4 @@ const countAndSay = function(n){ s = str; } return s; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0039.Combination Sum/README.md b/solution/0000-0099/0039.Combination Sum/README.md index 1444579abe360..e1544424647a4 100644 --- a/solution/0000-0099/0039.Combination Sum/README.md +++ b/solution/0000-0099/0039.Combination Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0039.Combination%20Sum/README_EN.md) ## 题目描述 +

    给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。

    @@ -35,15 +36,14 @@   [3,5] ] - - ## 解法 - + ### **Python3** + ```python @@ -51,6 +51,7 @@ ``` ### **Java** + ```java @@ -58,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0039.Combination Sum/README_EN.md b/solution/0000-0099/0039.Combination Sum/README_EN.md index 544e68dc081f7..b4e940f3e77c5 100644 --- a/solution/0000-0099/0039.Combination Sum/README_EN.md +++ b/solution/0000-0099/0039.Combination Sum/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0000-0099/0039.Combination%20Sum/README.md) ## Description -

    Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

    - +

    Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

    The same repeated number may be chosen from candidates unlimited number of times.

    - -

    Note:

    - -
      -
    • All numbers (including target) will be positive integers.
    • +
    • All numbers (including target) will be positive integers.
    • -
    • The solution set must not contain duplicate combinations.
    • +
    • The solution set must not contain duplicate combinations.
    - -

    Example 1:

    - -
     
     Input: candidates = [2,3,6,7], target = 7,
    @@ -45,12 +36,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: candidates = [2,3,5], target = 8,
    @@ -69,12 +56,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -90,8 +73,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0040.Combination Sum II/README.md b/solution/0000-0099/0040.Combination Sum II/README.md index b6010b3eaed33..d3186a978c4f1 100644 --- a/solution/0000-0099/0040.Combination Sum II/README.md +++ b/solution/0000-0099/0040.Combination Sum II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md) ## 题目描述 +

    给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。

    @@ -36,15 +37,14 @@   [5] ] - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ ``` ### **Java** + ```java @@ -59,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0040.Combination Sum II/README_EN.md b/solution/0000-0099/0040.Combination Sum II/README_EN.md index 0c158cbe7be34..78c36fcaf4e8f 100644 --- a/solution/0000-0099/0040.Combination Sum II/README_EN.md +++ b/solution/0000-0099/0040.Combination Sum II/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0000-0099/0040.Combination%20Sum%20II/README.md) ## Description -

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

    - +

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

    Each number in candidates may only be used once in the combination.

    - -

    Note:

    - -
      -
    • All numbers (including target) will be positive integers.
    • +
    • All numbers (including target) will be positive integers.
    • -
    • The solution set must not contain duplicate combinations.
    • +
    • The solution set must not contain duplicate combinations.
    - -

    Example 1:

    - -
     
     Input: candidates = [10,1,2,7,6,1,5], target = 8,
    @@ -49,12 +40,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: candidates = [2,5,2,1,2], target = 5,
    @@ -71,12 +58,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -92,8 +75,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0041.First Missing Positive/README.md b/solution/0000-0099/0041.First Missing Positive/README.md index 227250188afcf..7cf4514b677eb 100644 --- a/solution/0000-0099/0041.First Missing Positive/README.md +++ b/solution/0000-0099/0041.First Missing Positive/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md) ## 题目描述 +

    给定一个未排序的整数数组,找出其中没有出现的最小的正整数。

    @@ -28,15 +29,14 @@

    你的算法的时间复杂度应为O(n),并且只能使用常数级别的空间。

    - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0041.First Missing Positive/README_EN.md b/solution/0000-0099/0041.First Missing Positive/README_EN.md index 84cc4d17b5359..6ea33b831084d 100644 --- a/solution/0000-0099/0041.First Missing Positive/README_EN.md +++ b/solution/0000-0099/0041.First Missing Positive/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0041.First%20Missing%20Positive/README.md) ## Description -

    Given an unsorted integer array, find the smallest missing positive integer.

    - +

    Given an unsorted integer array, find the smallest missing positive integer.

    Example 1:

    - -
     
     Input: [1,2,0]
    @@ -19,12 +16,8 @@ Output: 3
     
     
    - -

    Example 2:

    - -
     
     Input: [3,4,-1,1]
    @@ -33,12 +26,8 @@ Output: 2
     
     
    - -

    Example 3:

    - -
     
     Input: [7,8,9,11,12]
    @@ -47,20 +36,12 @@ Output: 1
     
     
    - -

    Note:

    - -

    Your algorithm should run in O(n) time and uses constant extra space.

    - - - ## Solutions - ### **Python3** @@ -76,8 +57,9 @@ Output: 1 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0042.Trapping Rain Water/README.md b/solution/0000-0099/0042.Trapping Rain Water/README.md index ec7346b1ae40a..472aae905fae1 100644 --- a/solution/0000-0099/0042.Trapping Rain Water/README.md +++ b/solution/0000-0099/0042.Trapping Rain Water/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md) ## 题目描述 +

    给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。

    @@ -15,15 +16,14 @@
    输入: [0,1,0,2,1,0,1,3,2,1,2,1]
     输出: 6
    - - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md index fa4db84224ef2..3dede449e9a6d 100644 --- a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md +++ b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md @@ -3,31 +3,23 @@ [中文文档](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md) ## Description -

    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.

    +

    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.

    ![](./images/rainwatertrap.png) The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!

    - -

    Example:

    - -
     
     Input: [0,1,0,2,1,0,1,3,2,1,2,1]
     
     Output: 6
    - - - ## Solutions - ### **Python3** @@ -43,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0043.Multiply Strings/README.md b/solution/0000-0099/0043.Multiply Strings/README.md index 8335a9204a20b..57cc3dcaef206 100644 --- a/solution/0000-0099/0043.Multiply Strings/README.md +++ b/solution/0000-0099/0043.Multiply Strings/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0043.Multiply%20Strings/README_EN.md) ## 题目描述 +

    给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。

    @@ -25,15 +26,14 @@
  • 不能使用任何标准库的大数类型(比如 BigInteger)直接将输入转换为整数来处理
  • - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0043.Multiply Strings/README_EN.md b/solution/0000-0099/0043.Multiply Strings/README_EN.md index e8d76e0bb89d9..eab55338c3bcb 100644 --- a/solution/0000-0099/0043.Multiply Strings/README_EN.md +++ b/solution/0000-0099/0043.Multiply Strings/README_EN.md @@ -3,26 +3,19 @@ [中文文档](/solution/0000-0099/0043.Multiply%20Strings/README.md) ## Description -

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

    - +

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

    Example 1:

    - -
     
     Input: num1 = "2", num2 = "3"
     
     Output: "6"
    - -

    Example 2:

    - -
     
     Input: num1 = "123", num2 = "456"
    @@ -31,30 +24,22 @@
     
     
    - -

    Note:

    - -
      -
    1. The length of both num1 and num2 is < 110.
    2. +
    3. The length of both num1 and num2 is < 110.
    4. -
    5. Both num1 and num2 contain only digits 0-9.
    6. +
    7. Both num1 and num2 contain only digits 0-9.
    8. -
    9. Both num1 and num2 do not contain any leading zero, except the number 0 itself.
    10. +
    11. Both num1 and num2 do not contain any leading zero, except the number 0 itself.
    12. -
    13. You must not use any built-in BigInteger library or convert the inputs to integer directly.
    14. +
    15. You must not use any built-in BigInteger library or convert the inputs to integer directly.
    - - - ## Solutions - ### **Python3** @@ -70,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0044.Wildcard Matching/README.md b/solution/0000-0099/0044.Wildcard Matching/README.md index 862c23b5ea5e8..4e5dec28ab1f7 100644 --- a/solution/0000-0099/0044.Wildcard Matching/README.md +++ b/solution/0000-0099/0044.Wildcard Matching/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md) ## 题目描述 +

    给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配。

    @@ -61,15 +62,14 @@ s = "acdcb" p = "a*c?b" 输入: false - - ## 解法 - + ### **Python3** + ```python @@ -77,6 +77,7 @@ p = "a*c?b" ``` ### **Java** + ```java @@ -84,8 +85,9 @@ p = "a*c?b" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0044.Wildcard Matching/README_EN.md b/solution/0000-0099/0044.Wildcard Matching/README_EN.md index 2112e311a5b55..d5cda96354545 100644 --- a/solution/0000-0099/0044.Wildcard Matching/README_EN.md +++ b/solution/0000-0099/0044.Wildcard Matching/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0044.Wildcard%20Matching/README.md) ## Description -

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

    - +

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

     
    @@ -15,30 +14,20 @@
     
     
    - -

    The matching should cover the entire input string (not partial).

    - -

    Note:

    - -
      -
    • s could be empty and contains only lowercase letters a-z.
    • +
    • s could be empty and contains only lowercase letters a-z.
    • -
    • p could be empty and contains only lowercase letters a-z, and characters like ? or *.
    • +
    • p could be empty and contains only lowercase letters a-z, and characters like ? or *.
    - -

    Example 1:

    - -
     
     Input:
    @@ -53,12 +42,8 @@ p = "a"
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -73,12 +58,8 @@ p = "*"
     
     
    - -

    Example 3:

    - -
     
     Input:
    @@ -93,12 +74,8 @@ p = "?a"
     
     
    - -

    Example 4:

    - -
     
     Input:
    @@ -113,12 +90,8 @@ p = "*a*b"
     
     
    - -

    Example 5:

    - -
     
     Input:
    @@ -131,12 +104,8 @@ p = "a*c?b"
     
     
    - - - ## Solutions - ### **Python3** @@ -152,8 +121,9 @@ p = "a*c?b" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0045.Jump Game II/README.md b/solution/0000-0099/0045.Jump Game II/README.md index 127ded5416fba..061d1535cb267 100644 --- a/solution/0000-0099/0045.Jump Game II/README.md +++ b/solution/0000-0099/0045.Jump Game II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md) ## 题目描述 +

    给定一个非负整数数组,你最初位于数组的第一个位置。

    @@ -22,15 +23,14 @@

    假设你总是可以到达数组的最后一个位置。

    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0045.Jump Game II/README_EN.md b/solution/0000-0099/0045.Jump Game II/README_EN.md index 1933cf0a72b26..66a240733e3c7 100644 --- a/solution/0000-0099/0045.Jump Game II/README_EN.md +++ b/solution/0000-0099/0045.Jump Game II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0045.Jump%20Game%20II/README.md) ## Description -

    Given an array of non-negative integers, you are initially positioned at the first index of the array.

    - +

    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 is to reach the last index in the minimum number of jumps.

    - -

    Example:

    - -
     
     Input: [2,3,1,1,4]
    @@ -29,20 +22,12 @@
     
         Jump 1 step from index 0 to 1, then 3 steps to the last index.
    - -

    Note:

    - -

    You can assume that you can always reach the last index.

    - - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0046.Permutations/README.md b/solution/0000-0099/0046.Permutations/README.md index 3b5b5c95aaa1b..e5bf4398b1cda 100644 --- a/solution/0000-0099/0046.Permutations/README.md +++ b/solution/0000-0099/0046.Permutations/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0046.Permutations/README_EN.md) ## 题目描述 +

    给定一个没有重复数字的序列,返回其所有可能的全排列。

    @@ -19,15 +20,14 @@ [3,2,1] ] - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0046.Permutations/README_EN.md b/solution/0000-0099/0046.Permutations/README_EN.md index b84e6350e6baa..c39f131927679 100644 --- a/solution/0000-0099/0046.Permutations/README_EN.md +++ b/solution/0000-0099/0046.Permutations/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0046.Permutations/README.md) ## Description -

    Given a collection of distinct integers, return all possible permutations.

    - +

    Given a collection of distinct integers, return all possible permutations.

    Example:

    - -
     
     Input: [1,2,3]
    @@ -35,12 +32,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0047.Permutations II/README.md b/solution/0000-0099/0047.Permutations II/README.md index 283d6752ca984..804ef7728ed32 100644 --- a/solution/0000-0099/0047.Permutations II/README.md +++ b/solution/0000-0099/0047.Permutations II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0047.Permutations%20II/README_EN.md) ## 题目描述 +

    给定一个可包含重复数字的序列,返回所有不重复的全排列。

    @@ -16,15 +17,14 @@ [2,1,1] ] - - ## 解法 - + ### **Python3** + ```python @@ -32,6 +32,7 @@ ``` ### **Java** + ```java @@ -39,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0047.Permutations II/README_EN.md b/solution/0000-0099/0047.Permutations II/README_EN.md index da96d7b4f87f9..9c2bd8ca301f5 100644 --- a/solution/0000-0099/0047.Permutations II/README_EN.md +++ b/solution/0000-0099/0047.Permutations II/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0047.Permutations%20II/README.md) ## Description -

    Given a collection of numbers that might contain duplicates, return all possible unique permutations.

    - +

    Given a collection of numbers that might contain duplicates, return all possible unique permutations.

    Example:

    - -
     
     Input: [1,1,2]
    @@ -29,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -50,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0048.Rotate Image/README.md b/solution/0000-0099/0048.Rotate Image/README.md index 36e29256a677d..4d93e7f186438 100644 --- a/solution/0000-0099/0048.Rotate Image/README.md +++ b/solution/0000-0099/0048.Rotate Image/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0048.Rotate%20Image/README_EN.md) ## 题目描述 +

    给定一个 × n 的二维矩阵表示一个图像。

    @@ -48,15 +49,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -64,6 +64,7 @@ ``` ### **Java** + ```java @@ -71,8 +72,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0048.Rotate Image/README_EN.md b/solution/0000-0099/0048.Rotate Image/README_EN.md index 6fe51db03f335..4c8ff2b21976d 100644 --- a/solution/0000-0099/0048.Rotate Image/README_EN.md +++ b/solution/0000-0099/0048.Rotate Image/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0000-0099/0048.Rotate%20Image/README.md) ## Description -

    You are given an n x n 2D matrix representing an 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 matrix directly. DO NOT allocate another 2D matrix and do the rotation.

    - -

    Example 1:

    - -
     
     Given input matrix = 
    @@ -53,12 +44,8 @@ rotate the input matrix in-place such that it becomes:
     
     
    - -

    Example 2:

    - -
     
     Given input matrix =
    @@ -93,12 +80,8 @@ rotate the input matrix in-place such that it becomes:
     
     
    - - - ## Solutions - ### **Python3** @@ -114,8 +97,9 @@ rotate the input matrix in-place such that it becomes: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0048.Rotate Image/Solution.js b/solution/0000-0099/0048.Rotate Image/Solution.js index 25c34a02bab71..168962e3e1f82 100644 --- a/solution/0000-0099/0048.Rotate Image/Solution.js +++ b/solution/0000-0099/0048.Rotate Image/Solution.js @@ -2,38 +2,38 @@ * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */ -const rotate1 = function(matrix) { +const rotate1 = function (matrix) { // function swap(x,y){ // console.log(x,y); // let z = x; // x = y; // y = z; // } - for(let i = 0; i < matrix.length; i++){ - for(let j = 0; j <= i; j++){ + for (let i = 0; i < matrix.length; i++) { + for (let j = 0; j <= i; j++) { // swap(matrix[i][j],matrix[j][i]); // let t = matrix[i][j]; // matrix[i][j] = matrix[j][i]; // matrix[j][i] = t; - [matrix[i][j],matrix[j][i]] = [matrix[j][i],matrix[i][j]]; + [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; } } - for(let i = 0, j = matrix.length -1; i < j; i++, j--){ - for(let k = 0; k < matrix.length; k++){ + for (let i = 0, j = matrix.length - 1; i < j; i++, j--) { + for (let k = 0; k < matrix.length; k++) { // swap(matrix[k][i], matrix[k][j]); // let t = matrix[k][i]; // matrix[k][i] = matrix[k][j]; // matrix[k][j] = t; - [matrix[k][i], matrix[k][j]] = [matrix[k][j],matrix[k][i]]; + [matrix[k][i], matrix[k][j]] = [matrix[k][j], matrix[k][i]]; } } }; -const rotate = function(matrix){ +const rotate = function (matrix) { matrix = matrix.reverse(); - for(let i = 0 ; i < matrix.length; i++){ - for(let j = 0; j < i; j++){ - [matrix[i][j],matrix[j][i]] = [matrix[j][i],matrix[i][j]]; + for (let i = 0; i < matrix.length; i++) { + for (let j = 0; j < i; j++) { + [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; } } -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0049.Group Anagrams/README.md b/solution/0000-0099/0049.Group Anagrams/README.md index 723543ab86e57..2ee9260c39c4b 100644 --- a/solution/0000-0099/0049.Group Anagrams/README.md +++ b/solution/0000-0099/0049.Group Anagrams/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0049.Group%20Anagrams/README_EN.md) ## 题目描述 +

    给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。

    @@ -23,15 +24,14 @@
  • 不考虑答案输出的顺序。
  • - - ## 解法 - + ### **Python3** + ```python @@ -39,6 +39,7 @@ ``` ### **Java** + ```java @@ -46,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0049.Group Anagrams/README_EN.md b/solution/0000-0099/0049.Group Anagrams/README_EN.md index c2334b115af1f..9af5a52aab2ea 100644 --- a/solution/0000-0099/0049.Group Anagrams/README_EN.md +++ b/solution/0000-0099/0049.Group Anagrams/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0049.Group%20Anagrams/README.md) ## Description -

    Given an array of strings, group anagrams together.

    - +

    Given an array of strings, group anagrams together.

    Example:

    - -
     
     Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
    @@ -27,26 +24,18 @@
     
     ]
    - -

    Note:

    - -
      -
    • All inputs will be in lowercase.
    • +
    • All inputs will be in lowercase.
    • -
    • The order of your output does not matter.
    • +
    • The order of your output does not matter.
    - - - ## Solutions - ### **Python3** @@ -62,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0050.Pow(x, n)/README.md b/solution/0000-0099/0050.Pow(x, n)/README.md index 319058ca56745..e0df3ebe2122a 100644 --- a/solution/0000-0099/0050.Pow(x, n)/README.md +++ b/solution/0000-0099/0050.Pow(x, n)/README.md @@ -1,8 +1,9 @@ # [50. Pow(x, n)](https://leetcode-cn.com/problems/powx-n) -[English Version](/solution/0000-0099/0050.Pow(x,%20n)/README_EN.md) +[English Version]() ## 题目描述 +

    实现 pow(x, n) ,即计算 x 的 n 次幂函数。

    @@ -31,15 +32,14 @@
  • n 是 32 位有符号整数,其数值范围是 [−231, 231 − 1] 。
  • - - ## 解法 - + ### **Python3** + ```python @@ -47,6 +47,7 @@ ``` ### **Java** + ```java @@ -54,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0050.Pow(x, n)/README_EN.md b/solution/0000-0099/0050.Pow(x, n)/README_EN.md index 5e4afb3a7cb2e..bc0c8e5012c28 100644 --- a/solution/0000-0099/0050.Pow(x, n)/README_EN.md +++ b/solution/0000-0099/0050.Pow(x, n)/README_EN.md @@ -1,16 +1,13 @@ # [50. Pow(x, n)](https://leetcode.com/problems/powx-n) -[中文文档](/solution/0000-0099/0050.Pow(x,%20n)/README.md) +[中文文档]() ## Description -

    Implement pow(x, n), which calculates x raised to the power n (xn).

    - +

    Implement pow(x, n), which calculates x raised to the power n (xn).

    Example 1:

    - -
     
     Input: 2.00000, 10
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 2.10000, 3
    @@ -33,12 +26,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: 2.00000, -2
    @@ -49,26 +38,18 @@
     
     
    - -

    Note:

    - -
      -
    • -100.0 < x < 100.0
    • +
    • -100.0 < x < 100.0
    • -
    • n is a 32-bit signed integer, within the range [−231, 231 − 1]
    • +
    • n is a 32-bit signed integer, within the range [−231, 231 − 1]
    - - - ## Solutions - ### **Python3** @@ -84,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0050.Pow(x, n)/Solution.js b/solution/0000-0099/0050.Pow(x, n)/Solution.js index 8dfd15f5a101a..8a4a7dad9a623 100644 --- a/solution/0000-0099/0050.Pow(x, n)/Solution.js +++ b/solution/0000-0099/0050.Pow(x, n)/Solution.js @@ -3,11 +3,13 @@ * @param {number} n * @return {number} */ -var myPow = function(x, n) { - if (n == 0) return 1 - if (n < 0) { - n = -n - x = 1 / x - } - return (n % 2 == 0) ? Math.pow(x * x, parseInt(n / 2)) : x*Math.pow(x * x, parseInt(n / 2)); - }; \ No newline at end of file +var myPow = function (x, n) { + if (n == 0) return 1; + if (n < 0) { + n = -n; + x = 1 / x; + } + return n % 2 == 0 + ? Math.pow(x * x, parseInt(n / 2)) + : x * Math.pow(x * x, parseInt(n / 2)); +}; diff --git a/solution/0000-0099/0051.N-Queens/README.md b/solution/0000-0099/0051.N-Queens/README.md index 9c8ac90b87d19..35e49cde6977c 100644 --- a/solution/0000-0099/0051.N-Queens/README.md +++ b/solution/0000-0099/0051.N-Queens/README.md @@ -1,8 +1,9 @@ -# [51. N皇后](https://leetcode-cn.com/problems/n-queens) +# [51. N 皇后](https://leetcode-cn.com/problems/n-queens) [English Version](/solution/0000-0099/0051.N-Queens/README_EN.md) ## 题目描述 +

    皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。

    @@ -31,15 +32,14 @@ 解释: 4 皇后问题存在两个不同的解法。 - - ## 解法 - + ### **Python3** + ```python @@ -47,6 +47,7 @@ ``` ### **Java** + ```java @@ -54,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0051.N-Queens/README_EN.md b/solution/0000-0099/0051.N-Queens/README_EN.md index 2b6545167872c..93cd62a3534b0 100644 --- a/solution/0000-0099/0051.N-Queens/README_EN.md +++ b/solution/0000-0099/0051.N-Queens/README_EN.md @@ -3,23 +3,17 @@ [中文文档](/solution/0000-0099/0051.N-Queens/README.md) ## Description -

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

    +

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

    ![](./images/8-queens.png)

    Given an integer n, return all distinct solutions to the n-queens puzzle.

    - -

    Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively.

    - -

    Example:

    - -
     
     Input: 4
    @@ -50,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -71,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0052.N-Queens II/README.md b/solution/0000-0099/0052.N-Queens II/README.md index b237301313608..57584917f32f6 100644 --- a/solution/0000-0099/0052.N-Queens II/README.md +++ b/solution/0000-0099/0052.N-Queens II/README.md @@ -1,8 +1,9 @@ -# [52. N皇后 II](https://leetcode-cn.com/problems/n-queens-ii) +# [52. N 皇后 II](https://leetcode-cn.com/problems/n-queens-ii) [English Version](/solution/0000-0099/0052.N-Queens%20II/README_EN.md) ## 题目描述 +

    皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。

    @@ -30,15 +31,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -46,6 +46,7 @@ ``` ### **Java** + ```java @@ -53,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0052.N-Queens II/README_EN.md b/solution/0000-0099/0052.N-Queens II/README_EN.md index ef71b3797df61..55ea9c2cf7dba 100644 --- a/solution/0000-0099/0052.N-Queens II/README_EN.md +++ b/solution/0000-0099/0052.N-Queens II/README_EN.md @@ -3,20 +3,15 @@ [中文文档](/solution/0000-0099/0052.N-Queens%20II/README.md) ## Description -

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

    +

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

    ![](./images/8-queens.png) -

    Given an integer n, return the number of distinct solutions to the n-queens puzzle.

    - -

    Example:

    - -
     
     Input: 4
    @@ -49,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -70,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0053.Maximum Subarray/README.md b/solution/0000-0099/0053.Maximum Subarray/README.md index e9f9f33c1b5c5..c383361abc458 100644 --- a/solution/0000-0099/0053.Maximum Subarray/README.md +++ b/solution/0000-0099/0053.Maximum Subarray/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md) ## 题目描述 +

    给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。

    @@ -17,15 +18,14 @@

    如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。

    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0053.Maximum Subarray/README_EN.md b/solution/0000-0099/0053.Maximum Subarray/README_EN.md index e89b3075e3c63..ed374a2ef4689 100644 --- a/solution/0000-0099/0053.Maximum Subarray/README_EN.md +++ b/solution/0000-0099/0053.Maximum Subarray/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0053.Maximum%20Subarray/README.md) ## Description -

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

    - +

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

    Example:

    - -
     
     Input: [-2,1,-3,4,-1,2,1,-5,4],
    @@ -21,20 +18,12 @@
     
     
    - -

    Follow up:

    - -

    If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

    - - - ## Solutions - ### **Python3** @@ -50,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0053.Maximum Subarray/Solution.js b/solution/0000-0099/0053.Maximum Subarray/Solution.js index 6964d3fb2ed0e..3225c46377fb8 100644 --- a/solution/0000-0099/0053.Maximum Subarray/Solution.js +++ b/solution/0000-0099/0053.Maximum Subarray/Solution.js @@ -1,9 +1,10 @@ -const maxSubArray = function(nums){ - if(nums.length === 0) return 0; - let ans = nums[0], tmp = nums[0]; - for(let i = 1; i < nums.length; i++){ - tmp = Math.max(tmp+nums[i], nums[i]); - ans = Math.max(ans,tmp); +const maxSubArray = function (nums) { + if (nums.length === 0) return 0; + let ans = nums[0], + tmp = nums[0]; + for (let i = 1; i < nums.length; i++) { + tmp = Math.max(tmp + nums[i], nums[i]); + ans = Math.max(ans, tmp); } return ans; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0054.Spiral Matrix/README.md b/solution/0000-0099/0054.Spiral Matrix/README.md index d419a3fe61ba3..008bfc95f7ce2 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README.md +++ b/solution/0000-0099/0054.Spiral Matrix/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md) ## 题目描述 +

    给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。

    @@ -28,15 +29,14 @@ 输出: [1,2,3,4,8,12,11,10,9,5,6,7] - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0054.Spiral Matrix/README_EN.md b/solution/0000-0099/0054.Spiral Matrix/README_EN.md index 2cc73cc951287..29416c8eff675 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README_EN.md +++ b/solution/0000-0099/0054.Spiral Matrix/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0054.Spiral%20Matrix/README.md) ## Description -

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

    - +

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

    Example 1:

    - -
     
     Input:
    @@ -29,8 +26,6 @@
     
     
    - -

    Example 2:

    @@ -51,10 +46,8 @@
     
     
    - ## Solutions - ### **Python3** @@ -70,8 +63,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0055.Jump Game/README.md b/solution/0000-0099/0055.Jump Game/README.md index e7ce7b2ece159..b1f9ca406acf7 100644 --- a/solution/0000-0099/0055.Jump Game/README.md +++ b/solution/0000-0099/0055.Jump Game/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0055.Jump%20Game/README_EN.md) ## 题目描述 +

    给定一个非负整数数组,你最初位于数组的第一个位置。

    @@ -24,15 +25,14 @@ 解释: 无论怎样,你总会到达索引为 3 的位置。但该位置的最大跳跃长度是 0 , 所以你永远不可能到达最后一个位置。 - - ## 解法 - + ### **Python3** + ```python @@ -40,6 +40,7 @@ ``` ### **Java** + ```java @@ -47,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0055.Jump Game/README_EN.md b/solution/0000-0099/0055.Jump Game/README_EN.md index b99e54a70e568..1ff3569b54eb7 100644 --- a/solution/0000-0099/0055.Jump Game/README_EN.md +++ b/solution/0000-0099/0055.Jump Game/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0055.Jump%20Game/README.md) ## Description -

    Given an array of non-negative integers, you are initially positioned at the first index of the array.

    - +

    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 you are able to reach the last index.

    - -

    Example 1:

    - -
     
     Input: [2,3,1,1,4]
    @@ -29,12 +22,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [3,2,1,0,4]
    @@ -47,12 +36,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -68,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0056.Merge Intervals/README.md b/solution/0000-0099/0056.Merge Intervals/README.md index 0f0b4a470728c..a92991de167be 100644 --- a/solution/0000-0099/0056.Merge Intervals/README.md +++ b/solution/0000-0099/0056.Merge Intervals/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0056.Merge%20Intervals/README_EN.md) ## 题目描述 +

    给出一个区间的集合,请合并所有重叠的区间。

    @@ -19,15 +20,14 @@ 输出: [[1,5]] 解释: 区间 [1,4] 和 [4,5] 可被视为重叠区间。 - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0056.Merge Intervals/README_EN.md b/solution/0000-0099/0056.Merge Intervals/README_EN.md index 1ed2bd586903f..a623ce4406d89 100644 --- a/solution/0000-0099/0056.Merge Intervals/README_EN.md +++ b/solution/0000-0099/0056.Merge Intervals/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0056.Merge%20Intervals/README.md) ## Description -

    Given a collection of intervals, merge all overlapping intervals.

    - +

    Given a collection of intervals, merge all overlapping intervals.

    Example 1:

    - -
     
     Input: [[1,3],[2,6],[8,10],[15,18]]
    @@ -21,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [[1,4],[4,5]]
    @@ -35,16 +28,10 @@
     
     Explanation: Intervals [1,4] and [4,5] are considered overlapping.
    - -

    NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

    - - - ## Solutions - ### **Python3** @@ -60,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0057.Insert Interval/README.md b/solution/0000-0099/0057.Insert Interval/README.md index 12434a145fd6e..f086e12f11c86 100644 --- a/solution/0000-0099/0057.Insert Interval/README.md +++ b/solution/0000-0099/0057.Insert Interval/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0057.Insert%20Interval/README_EN.md) ## 题目描述 +

    给出一个无重叠的 ,按照区间起始端点排序的区间列表。

    @@ -21,15 +22,14 @@ 解释: 这是因为新的区间 [4,8][3,5],[6,7],[8,10] 重叠。 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0057.Insert Interval/README_EN.md b/solution/0000-0099/0057.Insert Interval/README_EN.md index 1cf7726c77fb5..8c90b2afcc578 100644 --- a/solution/0000-0099/0057.Insert Interval/README_EN.md +++ b/solution/0000-0099/0057.Insert Interval/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0057.Insert%20Interval/README.md) ## Description -

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

    - +

    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.

    - -

    Example 1:

    - -
     
     Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
    @@ -37,16 +28,10 @@
     
     Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
    - -

    NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

    - - - ## Solutions - ### **Python3** @@ -62,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0058.Length of Last Word/README.md b/solution/0000-0099/0058.Length of Last Word/README.md index 4146e8271670f..812d6054eeef9 100644 --- a/solution/0000-0099/0058.Length of Last Word/README.md +++ b/solution/0000-0099/0058.Length of Last Word/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md) ## 题目描述 +

    给定一个仅包含大小写字母和空格 ' ' 的字符串 s,返回其最后一个单词的长度。如果字符串从左向右滚动显示,那么最后一个单词就是最后出现的单词。

    @@ -18,15 +19,14 @@ 输出: 5 - - ## 解法 - + ### **Python3** + ```python @@ -34,6 +34,7 @@ ``` ### **Java** + ```java @@ -41,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0058.Length of Last Word/README_EN.md b/solution/0000-0099/0058.Length of Last Word/README_EN.md index fe9a9d1c35b4c..d894f5488f378 100644 --- a/solution/0000-0099/0058.Length of Last Word/README_EN.md +++ b/solution/0000-0099/0058.Length of Last Word/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md) ## Description +

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

    If the last word does not exist, return 0.

    @@ -18,11 +19,8 @@

     

    - - ## Solutions - ### **Python3** @@ -38,8 +36,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0058.Length of Last Word/Solution.js b/solution/0000-0099/0058.Length of Last Word/Solution.js index a8d00bc3f916e..348d2344d0815 100644 --- a/solution/0000-0099/0058.Length of Last Word/Solution.js +++ b/solution/0000-0099/0058.Length of Last Word/Solution.js @@ -1,16 +1,16 @@ var lengthOfLastWord = function (s) { - s = s.trim() - return s.length - s.lastIndexOf(" ") - 1 + s = s.trim(); + return s.length - s.lastIndexOf(" ") - 1; }; var lengthOfLastWord2 = function (s) { - let res = 0 + let res = 0; for (let i = 0; i < s.length; i++) { - if (s[i] !== ' ' && (i === 0 || s[i - 1] === ' ')) { - res = 1 - } else if (s[i] !== ' ') { - res++ + if (s[i] !== " " && (i === 0 || s[i - 1] === " ")) { + res = 1; + } else if (s[i] !== " ") { + res++; } } - return res -} \ No newline at end of file + return res; +}; diff --git a/solution/0000-0099/0059.Spiral Matrix II/README.md b/solution/0000-0099/0059.Spiral Matrix II/README.md index c04d4f1e9ea9d..87309a97c28ec 100644 --- a/solution/0000-0099/0059.Spiral Matrix II/README.md +++ b/solution/0000-0099/0059.Spiral Matrix II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md) ## 题目描述 +

    给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。

    @@ -16,15 +17,14 @@ [ 7, 6, 5 ] ] - - ## 解法 - + ### **Python3** + ```python @@ -32,6 +32,7 @@ ``` ### **Java** + ```java @@ -39,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md index ac1d845a0448f..d14804ab5a3e5 100644 --- a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md +++ b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md) ## Description -

    Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

    - +

    Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

    Example:

    - -
     
     Input: 3
    @@ -29,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -50,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0060.Permutation Sequence/README.md b/solution/0000-0099/0060.Permutation Sequence/README.md index b8b14e5709449..a15e2e70c3e72 100644 --- a/solution/0000-0099/0060.Permutation Sequence/README.md +++ b/solution/0000-0099/0060.Permutation Sequence/README.md @@ -1,8 +1,9 @@ -# [60. 第k个排列](https://leetcode-cn.com/problems/permutation-sequence) +# [60. 第 k 个排列](https://leetcode-cn.com/problems/permutation-sequence) [English Version](/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md) ## 题目描述 +

    给出集合 [1,2,3,…,n],其所有元素共有 n! 种排列。

    @@ -38,15 +39,14 @@ 输出: "2314" - - ## 解法 - + ### **Python3** + ```python @@ -54,6 +54,7 @@ ``` ### **Java** + ```java @@ -61,8 +62,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0060.Permutation Sequence/README_EN.md b/solution/0000-0099/0060.Permutation Sequence/README_EN.md index b66fbc1e2eb70..41b96d73e3819 100644 --- a/solution/0000-0099/0060.Permutation Sequence/README_EN.md +++ b/solution/0000-0099/0060.Permutation Sequence/README_EN.md @@ -3,54 +3,41 @@ [中文文档](/solution/0000-0099/0060.Permutation%20Sequence/README.md) ## Description -

    The set [1,2,3,...,n] contains a total of n! unique permutations.

    - +

    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 for n = 3:

    - -
      -
    1. "123"
    2. +
    3. "123"
    4. -
    5. "132"
    6. +
    7. "132"
    8. -
    9. "213"
    10. +
    11. "213"
    12. -
    13. "231"
    14. +
    15. "231"
    16. -
    17. "312"
    18. +
    19. "312"
    20. -
    21. "321"
    22. +
    23. "321"
    - -

    Given n and k, return the kth permutation sequence.

    - -

    Note:

    - -
      -
    • Given n will be between 1 and 9 inclusive.
    • +
    • Given n will be between 1 and 9 inclusive.
    • -
    • Given k will be between 1 and n! inclusive.
    • +
    • Given k will be between 1 and n! inclusive.
    - -

    Example 1:

    - -
     
     Input: n = 3, k = 3
    @@ -59,12 +46,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: n = 4, k = 9
    @@ -73,12 +56,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -94,8 +73,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0061.Rotate List/README.md b/solution/0000-0099/0061.Rotate List/README.md index fbce1fcd8a4eb..62847f97dfb2d 100644 --- a/solution/0000-0099/0061.Rotate List/README.md +++ b/solution/0000-0099/0061.Rotate List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0061.Rotate%20List/README_EN.md) ## 题目描述 +

    给定一个链表,旋转链表,将链表每个节点向右移动 个位置,其中 是非负数。

    @@ -25,15 +26,14 @@ 向右旋转 3 步: 0->1->2->NULL 向右旋转 4 步: 2->0->1->NULL - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0061.Rotate List/README_EN.md b/solution/0000-0099/0061.Rotate List/README_EN.md index 5a866849a7979..b9eeddf8fe3f7 100644 --- a/solution/0000-0099/0061.Rotate List/README_EN.md +++ b/solution/0000-0099/0061.Rotate List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0061.Rotate%20List/README.md) ## Description -

    Given a linked list, rotate the list to the right by k places, where k is non-negative.

    - +

    Given a linked list, rotate the list to the right by k places, where k is non-negative.

    Example 1:

    - -
     
     Input: 1->2->3->4->5->NULL, k = 2
    @@ -25,12 +22,8 @@ rotate 2 steps to the right: 4->5->1->2->3->NULL
     
     
    - -

    Example 2:

    - -
     
     Input: 0->1->2->NULL, k = 4
    @@ -47,12 +40,8 @@ rotate 3 steps to the right: 0->1->2->NULL
     
     rotate 4 steps to the right: 2->0->1->NULL
    - - - ## Solutions - ### **Python3** @@ -68,8 +57,9 @@ rotate 4 steps to the right: 2->0->1->NULL ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0062.Unique Paths/README.md b/solution/0000-0099/0062.Unique Paths/README.md index 0048c57017d14..6c82a0e4bef74 100644 --- a/solution/0000-0099/0062.Unique Paths/README.md +++ b/solution/0000-0099/0062.Unique Paths/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0062.Unique%20Paths/README_EN.md) ## 题目描述 +

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。

    @@ -41,15 +42,14 @@
  • 题目数据保证答案小于等于 2 * 10 ^ 9
  • - - ## 解法 - + ### **Python3** + ```python @@ -57,6 +57,7 @@ ``` ### **Java** + ```java @@ -64,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0062.Unique Paths/README_EN.md b/solution/0000-0099/0062.Unique Paths/README_EN.md index a2ff7d3348d6f..77e40266be745 100644 --- a/solution/0000-0099/0062.Unique Paths/README_EN.md +++ b/solution/0000-0099/0062.Unique Paths/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0062.Unique%20Paths/README.md) ## Description +

    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 bottom-right corner of the grid (marked 'Finish' in the diagram below).

    @@ -41,11 +42,8 @@ From the top-left corner, there are a total of 3 ways to reach the bottom-right
  • It's guaranteed that the answer will be less than or equal to 2 * 10 ^ 9.
  • - - ## Solutions - ### **Python3** @@ -61,8 +59,9 @@ From the top-left corner, there are a total of 3 ways to reach the bottom-right ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0063.Unique Paths II/README.md b/solution/0000-0099/0063.Unique Paths II/README.md index 32611688892eb..a99d9c6591c5a 100644 --- a/solution/0000-0099/0063.Unique Paths II/README.md +++ b/solution/0000-0099/0063.Unique Paths II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md) ## 题目描述 +

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。

    @@ -32,13 +33,13 @@ 2. 向下 -> 向下 -> 向右 -> 向右 - - ## 解法 + ### **Go** -``` go + +````go func uniquePathsWithObstacles(obstacleGrid [][]int) int { m,n := len(obstacleGrid),len(obstacleGrid[0]) dp := make([][]int,m) @@ -58,7 +59,7 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { dp[i][j] = dp[i][j-1] } } - } + } } return dp[m-1][n-1] } @@ -71,9 +72,10 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { ```python -``` +```` ### **Java** + ```java @@ -81,8 +83,9 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0063.Unique Paths II/README_EN.md b/solution/0000-0099/0063.Unique Paths II/README_EN.md index 325173fe7c16e..91fd5c0e828eb 100644 --- a/solution/0000-0099/0063.Unique Paths II/README_EN.md +++ b/solution/0000-0099/0063.Unique Paths II/README_EN.md @@ -1,108 +1,99 @@ -# [63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii) - -[中文文档](/solution/0000-0099/0063.Unique%20Paths%20II/README.md) - -## Description -

    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 bottom-right corner of the grid (marked 'Finish' in the diagram below).

    - - - -

    Now consider if some obstacles are added to the grids. How many unique paths would there be?

    - -![](./images/robot_maze.png) - -

    An obstacle and empty space is marked as 1 and 0 respectively in the grid.

    - - - -

    Note: m and n will be at most 100.

    - - - -

    Example 1:

    - - - -
    -
    -Input:
    -
    -[
    -
    -  [0,0,0],
    -
    -  [0,1,0],
    -
    -  [0,0,0]
    -
    -]
    -
    -Output: 2
    -
    -Explanation:
    -
    -There is one obstacle in the middle of the 3x3 grid above.
    -
    -There are two ways to reach the bottom-right corner:
    -
    -1. Right -> Right -> Down -> Down
    -
    -2. Down -> Down -> Right -> Right
    -
    -
    - - - - -## Solutions - -### **Go** -```go -func uniquePathsWithObstacles(obstacleGrid [][]int) int { - m,n := len(obstacleGrid),len(obstacleGrid[0]) - dp := make([][]int,m) - for i:=0; i < m;i++ { - dp[i] = make([]int,n) - } - for i := 0; i < m; i++ { - for j := 0; j < n; j++ { - if obstacleGrid[i][j] == 0 { - if i == 0 && j == 0 { - dp[i][j] = 1 - } else if i > 0 && j >0 { - dp[i][j] = dp[i][j-1]+dp[i-1][j] - } else if i > 0 { - dp[i][j] = dp[i-1][j] - } else { - dp[i][j] = dp[i][j-1] - } - } - } - } - return dp[m-1][n-1] -} -``` - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** -``` - -``` - - \ No newline at end of file +# [63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii) + +[中文文档](/solution/0000-0099/0063.Unique%20Paths%20II/README.md) + +## Description + +

    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 bottom-right corner of the grid (marked 'Finish' in the diagram below).

    + +

    Now consider if some obstacles are added to the grids. How many unique paths would there be?

    + +![](./images/robot_maze.png) + +

    An obstacle and empty space is marked as 1 and 0 respectively in the grid.

    + +

    Note: m and n will be at most 100.

    + +

    Example 1:

    + +
    +
    +Input:
    +
    +[
    +
    +  [0,0,0],
    +
    +  [0,1,0],
    +
    +  [0,0,0]
    +
    +]
    +
    +Output: 2
    +
    +Explanation:
    +
    +There is one obstacle in the middle of the 3x3 grid above.
    +
    +There are two ways to reach the bottom-right corner:
    +
    +1. Right -> Right -> Down -> Down
    +
    +2. Down -> Down -> Right -> Right
    +
    +
    + +## Solutions + +### **Go** + +```go +func uniquePathsWithObstacles(obstacleGrid [][]int) int { + m,n := len(obstacleGrid),len(obstacleGrid[0]) + dp := make([][]int,m) + for i:=0; i < m;i++ { + dp[i] = make([]int,n) + } + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + if obstacleGrid[i][j] == 0 { + if i == 0 && j == 0 { + dp[i][j] = 1 + } else if i > 0 && j >0 { + dp[i][j] = dp[i][j-1]+dp[i-1][j] + } else if i > 0 { + dp[i][j] = dp[i-1][j] + } else { + dp[i][j] = dp[i][j-1] + } + } + } + } + return dp[m-1][n-1] +} +``` + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **...** + +``` + +``` + + diff --git a/solution/0000-0099/0064.Minimum Path Sum/README.md b/solution/0000-0099/0064.Minimum Path Sum/README.md index d82c2863642e6..23e370cdc62b2 100644 --- a/solution/0000-0099/0064.Minimum Path Sum/README.md +++ b/solution/0000-0099/0064.Minimum Path Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md) ## 题目描述 +

    给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。

    @@ -20,15 +21,14 @@ 解释: 因为路径 1→3→1→1→1 的总和最小。 - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md index b460ff518ba3c..5bc409fd38007 100644 --- a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md +++ b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md) ## Description -

    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.

    - +

    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 any point in time.

    - -

    Example:

    - -
     
     Input:
    @@ -35,12 +30,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0065.Valid Number/README.md b/solution/0000-0099/0065.Valid Number/README.md index e26f8a48722df..ab31fbb32e221 100644 --- a/solution/0000-0099/0065.Valid Number/README.md +++ b/solution/0000-0099/0065.Valid Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0065.Valid%20Number/README_EN.md) ## 题目描述 +

    验证给定的字符串是否可以解释为十进制数字。

    @@ -37,15 +38,14 @@

    更新于 2015-02-10:
    C++函数的形式已经更新了。如果你仍然看见你的函数接收 const char * 类型的参数,请点击重载按钮重置你的代码。

    - - ## 解法 - + ### **Python3** + ```python @@ -53,6 +53,7 @@ ``` ### **Java** + ```java @@ -60,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0065.Valid Number/README_EN.md b/solution/0000-0099/0065.Valid Number/README_EN.md index c8bb604a3da68..83c028ecc4f42 100644 --- a/solution/0000-0099/0065.Valid Number/README_EN.md +++ b/solution/0000-0099/0065.Valid Number/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0065.Valid%20Number/README.md) ## Description -

    Validate if a given string can be interpreted as a decimal number.

    - +

    Validate if a given string can be interpreted as a decimal number.

    Some examples:
    @@ -37,40 +36,28 @@ "95a54e53" => false

    - -

    Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:

    - -
      -
    • Numbers 0-9
    • +
    • Numbers 0-9
    • -
    • Exponent - "e"
    • +
    • Exponent - "e"
    • -
    • Positive/negative sign - "+"/"-"
    • +
    • Positive/negative sign - "+"/"-"
    • -
    • Decimal point - "."
    • +
    • Decimal point - "."
    - -

    Of course, the context of these characters also matters in the input.

    - -

    Update (2015-02-10):
    -The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.

    - - - +The signature of the C++ function had been updated. If you still see your function signature accepts a const char \* argument, please click the reload button to reset your code definition.

    ## Solutions - ### **Python3** @@ -86,8 +73,9 @@ The signature of the C++ function had been updated. If you still se ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0066.Plus One/README.md b/solution/0000-0099/0066.Plus One/README.md index fd2d027cc8f17..187c4d3da2d7e 100644 --- a/solution/0000-0099/0066.Plus One/README.md +++ b/solution/0000-0099/0066.Plus One/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0066.Plus%20One/README_EN.md) ## 题目描述 +

    给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。

    @@ -24,15 +25,14 @@ 解释: 输入数组表示数字 4321。 - - ## 解法 - + ### **Python3** + ```python @@ -40,6 +40,7 @@ ``` ### **Java** + ```java @@ -47,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0066.Plus One/README_EN.md b/solution/0000-0099/0066.Plus One/README_EN.md index c9680af5cca03..69f4587c9cbda 100644 --- a/solution/0000-0099/0066.Plus One/README_EN.md +++ b/solution/0000-0099/0066.Plus One/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0066.Plus%20One/README.md) ## Description -

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

    - +

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

    The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

    - -

    You may assume the integer does not contain any leading zero, except the number 0 itself.

    - -

    Example 1:

    - -
     
     Input: [1,2,3]
    @@ -29,12 +22,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [4,3,2,1]
    @@ -45,10 +34,8 @@
     
     
    - ## Solutions - ### **Python3** @@ -64,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0066.Plus One/Solution.js b/solution/0000-0099/0066.Plus One/Solution.js index 47adcb87ca3b0..f72bcc367c917 100644 --- a/solution/0000-0099/0066.Plus One/Solution.js +++ b/solution/0000-0099/0066.Plus One/Solution.js @@ -1,12 +1,12 @@ -const plusOne = function(digits){ - for(let i = digits.length - 1; i >= 0; i--){ - if(digits[i] === 9){ +const plusOne = function (digits) { + for (let i = digits.length - 1; i >= 0; i--) { + if (digits[i] === 9) { digits[i] = 0; - }else{ + } else { digits[i] += 1; return digits; } } digits.unshift(1); return digits; -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0067.Add Binary/README.md b/solution/0000-0099/0067.Add Binary/README.md index acd15bbb581ad..ac6bdbabb9789 100644 --- a/solution/0000-0099/0067.Add Binary/README.md +++ b/solution/0000-0099/0067.Add Binary/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0067.Add%20Binary/README_EN.md) ## 题目描述 +

    给定两个二进制字符串,返回他们的和(用二进制表示)。

    @@ -18,15 +19,14 @@
    输入: a = "1010", b = "1011"
     输出: "10101"
    - - ## 解法 - + ### **Python3** + ```python @@ -34,6 +34,7 @@ ``` ### **Java** + ```java @@ -41,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0067.Add Binary/README_EN.md b/solution/0000-0099/0067.Add Binary/README_EN.md index eb46de91f178d..55da79171e77a 100644 --- a/solution/0000-0099/0067.Add Binary/README_EN.md +++ b/solution/0000-0099/0067.Add Binary/README_EN.md @@ -3,42 +3,29 @@ [中文文档](/solution/0000-0099/0067.Add%20Binary/README.md) ## Description -

    Given two binary strings, return their sum (also a binary string).

    - +

    Given two binary strings, return their sum (also a binary string).

    The input strings are both non-empty and contains only characters 1 or 0.

    - -

    Example 1:

    - -
     
     Input: a = "11", b = "1"
     
     Output: "100"
    - -

    Example 2:

    - -
     
     Input: a = "1010", b = "1011"
     
     Output: "10101"
    - - - ## Solutions - ### **Python3** @@ -54,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0068.Text Justification/README.md b/solution/0000-0099/0068.Text Justification/README.md index e4ff717096cc1..d7201c629d18e 100644 --- a/solution/0000-0099/0068.Text Justification/README.md +++ b/solution/0000-0099/0068.Text Justification/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0068.Text%20Justification/README_EN.md) ## 题目描述 +

    给定一个单词数组和一个长度 maxWidth,重新排版单词,使其成为每行恰好有 maxWidth 个字符,且左右两端对齐的文本。

    @@ -66,15 +67,14 @@ maxWidth = 20 ] - - ## 解法 - + ### **Python3** + ```python @@ -82,6 +82,7 @@ maxWidth = 20 ``` ### **Java** + ```java @@ -89,8 +90,9 @@ maxWidth = 20 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0068.Text Justification/README_EN.md b/solution/0000-0099/0068.Text Justification/README_EN.md index 58169dad6c7ce..c2ab75e2fe6bf 100644 --- a/solution/0000-0099/0068.Text Justification/README_EN.md +++ b/solution/0000-0099/0068.Text Justification/README_EN.md @@ -3,42 +3,29 @@ [中文文档](/solution/0000-0099/0068.Text%20Justification/README.md) ## Description -

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

    - +

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.

    - -

    Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

    - -

    For the last line of text, it should be left justified and no extra space is inserted between words.

    - -

    Note:

    - -
      -
    • A word is defined as a character sequence consisting of non-space characters only.
    • +
    • A word is defined as a character sequence consisting of non-space characters only.
    • -
    • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
    • +
    • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
    • -
    • The input array words contains at least one word.
    • +
    • The input array words contains at least one word.
    - -

    Example 1:

    - -
     
     Input:
    @@ -61,12 +48,8 @@ maxWidth = 16
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -95,12 +78,8 @@ maxWidth = 16
     
     
    - -

    Example 3:

    - -
     
     Input:
    @@ -131,12 +110,8 @@ maxWidth = 20
     
     
    - - - ## Solutions - ### **Python3** @@ -152,8 +127,9 @@ maxWidth = 20 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0069.Sqrt(x)/README.md b/solution/0000-0099/0069.Sqrt(x)/README.md index ea68cc1159f92..cfe64205d6ba2 100644 --- a/solution/0000-0099/0069.Sqrt(x)/README.md +++ b/solution/0000-0099/0069.Sqrt(x)/README.md @@ -1,8 +1,9 @@ # [69. x 的平方根](https://leetcode-cn.com/problems/sqrtx) -[English Version](/solution/0000-0099/0069.Sqrt(x)/README_EN.md) +[English Version]() ## 题目描述 +

    实现 int sqrt(int x) 函数。

    @@ -24,15 +25,14 @@   由于返回类型是整数,小数部分将被舍去。 - - ## 解法 - + ### **Python3** + ```python @@ -40,6 +40,7 @@ ``` ### **Java** + ```java @@ -47,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0069.Sqrt(x)/README_EN.md b/solution/0000-0099/0069.Sqrt(x)/README_EN.md index c4f519b69c9ae..eccd64854e912 100644 --- a/solution/0000-0099/0069.Sqrt(x)/README_EN.md +++ b/solution/0000-0099/0069.Sqrt(x)/README_EN.md @@ -1,24 +1,17 @@ # [69. Sqrt(x)](https://leetcode.com/problems/sqrtx) -[中文文档](/solution/0000-0099/0069.Sqrt(x)/README.md) +[中文文档]() ## Description -

    Implement int sqrt(int x).

    - +

    Implement int sqrt(int x).

    Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

    - -

    Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

    - -

    Example 1:

    - -
     
     Input: 4
    @@ -27,12 +20,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 8
    @@ -45,12 +34,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -66,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0069.Sqrt(x)/Solution.js b/solution/0000-0099/0069.Sqrt(x)/Solution.js index 49c3dd5eeb1a5..5b243199c9cb7 100644 --- a/solution/0000-0099/0069.Sqrt(x)/Solution.js +++ b/solution/0000-0099/0069.Sqrt(x)/Solution.js @@ -2,17 +2,17 @@ * @param {number} x * @return {number} */ -var mySqrt = function(x) { - var left = 1 - var right = x - var middle = Math.floor((left + right) / 2) - while( middle !== left ) { - if (middle * middle <= x) { - left = middle - } else { - right = middle - } - middle = Math.floor((left + right) / 2) - } - return middle +var mySqrt = function (x) { + var left = 1; + var right = x; + var middle = Math.floor((left + right) / 2); + while (middle !== left) { + if (middle * middle <= x) { + left = middle; + } else { + right = middle; + } + middle = Math.floor((left + right) / 2); + } + return middle; }; diff --git a/solution/0000-0099/0070.Climbing Stairs/README.md b/solution/0000-0099/0070.Climbing Stairs/README.md index 168f553040a07..a27bda8cd6bcd 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README.md +++ b/solution/0000-0099/0070.Climbing Stairs/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md) ## 题目描述 +

    假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

    @@ -28,15 +29,14 @@ 3. 2 阶 + 1 阶 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0070.Climbing Stairs/README_EN.md b/solution/0000-0099/0070.Climbing Stairs/README_EN.md index 27d6086e33808..be2b26aab794c 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README_EN.md +++ b/solution/0000-0099/0070.Climbing Stairs/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0070.Climbing%20Stairs/README.md) ## Description -

    You are climbing a stair case. It takes n steps to reach to the top.

    - +

    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 positive integer.

    - -

    Example 1:

    - -
     
     Input: 2
    @@ -33,12 +26,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 3
    @@ -55,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -76,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0070.Climbing Stairs/Solution.js b/solution/0000-0099/0070.Climbing Stairs/Solution.js index 15d734536306c..92e09da26613b 100644 --- a/solution/0000-0099/0070.Climbing Stairs/Solution.js +++ b/solution/0000-0099/0070.Climbing Stairs/Solution.js @@ -1,9 +1,9 @@ -const climbStairs = function(n){ +const climbStairs = function (n) { let arr = []; arr[0] = 1; arr[1] = 1; - for(let i = 2; i <= n; i++){ - arr[i] = arr[i-1]+arr[i-2]; + for (let i = 2; i <= n; i++) { + arr[i] = arr[i - 1] + arr[i - 2]; } return arr[n]; -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0071.Simplify Path/README.md b/solution/0000-0099/0071.Simplify Path/README.md index 9176087118238..ea8d13de0e139 100644 --- a/solution/0000-0099/0071.Simplify Path/README.md +++ b/solution/0000-0099/0071.Simplify Path/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0071.Simplify%20Path/README_EN.md) ## 题目描述 +

    以 Unix 风格给出一个文件的绝对路径,你需要简化它。或者换句话说,将其转换为规范路径。

    @@ -50,15 +51,14 @@
    输入:"/a//b////c/d//././/.."
     输出:"/a/b/c"
    - - ## 解法 - + ### **Python3** + ```python @@ -66,6 +66,7 @@ ``` ### **Java** + ```java @@ -73,8 +74,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0071.Simplify Path/README_EN.md b/solution/0000-0099/0071.Simplify Path/README_EN.md index 00db64d63005d..6251a4df2fc60 100644 --- a/solution/0000-0099/0071.Simplify Path/README_EN.md +++ b/solution/0000-0099/0071.Simplify Path/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0000-0099/0071.Simplify%20Path/README.md) ## Description -

    Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

    - +

    Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

    In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period .. moves the directory up a level. For more information, see: Absolute path vs relative path in Linux/Unix

    - -

    Note that the returned canonical path must always begin with a slash /, and there must be only a single slash / between two directory names. The last directory name (if it exists) must not end with a trailing /. Also, the canonical path must be the shortest string representing the absolute path.

    - -

     

    - -

    Example 1:

    - -
     
     Input: "/home/"
    @@ -33,12 +24,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "/../"
    @@ -49,12 +36,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "/home//foo/"
    @@ -65,12 +48,8 @@
     
     
    - -

    Example 4:

    - -
     
     Input: "/a/./b/../../c/"
    @@ -79,12 +58,8 @@
     
     
    - -

    Example 5:

    - -
     
     Input: "/a/../../b/../c//.//"
    @@ -93,12 +68,8 @@
     
     
    - -

    Example 6:

    - -
     
     Input: "/a//b////c/d//././/.."
    @@ -107,12 +78,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -128,8 +95,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0072.Edit Distance/README.md b/solution/0000-0099/0072.Edit Distance/README.md index c28fcbb1c4ddd..c22fff728b59d 100644 --- a/solution/0000-0099/0072.Edit Distance/README.md +++ b/solution/0000-0099/0072.Edit Distance/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0072.Edit%20Distance/README_EN.md) ## 题目描述 +

    给定两个单词 word1 和 word2,计算出将 word1 转换成 word2 所使用的最少操作数 。

    @@ -36,15 +37,14 @@ exention -> exection (将 'n' 替换为 'c') exection -> execution (插入 'u') - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ exection -> execution (插入 'u') ``` ### **Java** + ```java @@ -59,8 +60,9 @@ exection -> execution (插入 'u') ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0072.Edit Distance/README_EN.md b/solution/0000-0099/0072.Edit Distance/README_EN.md index bcdc88394a611..afb5a56137985 100644 --- a/solution/0000-0099/0072.Edit Distance/README_EN.md +++ b/solution/0000-0099/0072.Edit Distance/README_EN.md @@ -3,30 +3,23 @@ [中文文档](/solution/0000-0099/0072.Edit%20Distance/README.md) ## Description -

    Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.

    - +

    Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.

    You have the following 3 operations permitted on a word:

    - -
      -
    1. Insert a character
    2. +
    3. Insert a character
    4. -
    5. Delete a character
    6. +
    7. Delete a character
    8. -
    9. Replace a character
    10. +
    11. Replace a character
    - -

    Example 1:

    - -
     
     Input: word1 = "horse", word2 = "ros"
    @@ -43,12 +36,8 @@ rose -> ros (remove 'e')
     
     
    - -

    Example 2:

    - -
     
     Input: word1 = "intention", word2 = "execution"
    @@ -69,12 +58,8 @@ exection -> execution (insert 'u')
     
     
    - - - ## Solutions - ### **Python3** @@ -90,8 +75,9 @@ exection -> execution (insert 'u') ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README.md b/solution/0000-0099/0073.Set Matrix Zeroes/README.md index 1f8efbb10a16e..85b69831f3e4a 100644 --- a/solution/0000-0099/0073.Set Matrix Zeroes/README.md +++ b/solution/0000-0099/0073.Set Matrix Zeroes/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md) ## 题目描述 +

    给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法

    @@ -45,15 +46,14 @@
  • 你能想出一个常数空间的解决方案吗?
  • - - ## 解法 - + ### **Python3** + ```python @@ -61,6 +61,7 @@ ``` ### **Java** + ```java @@ -68,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md index 0d09cb4a4550f..92aa575bb34bc 100644 --- a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md +++ b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md) ## Description -

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

    - +

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

    Example 1:

    - -
     
     Input: 
    @@ -39,12 +36,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 
    @@ -73,28 +66,20 @@
     
     
    - -

    Follow up:

    - -
      -
    • A straight forward solution using O(mn) space is probably a bad idea.
    • +
    • A straight forward solution using O(mn) space is probably a bad idea.
    • -
    • A simple improvement uses O(m + n) space, but still not the best solution.
    • +
    • A simple improvement uses O(m + n) space, but still not the best solution.
    • -
    • Could you devise a constant space solution?
    • +
    • Could you devise a constant space solution?
    - - - ## Solutions - ### **Python3** @@ -110,8 +95,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README.md b/solution/0000-0099/0074.Search a 2D Matrix/README.md index 0fde83b4965a4..068a7ec9564b6 100644 --- a/solution/0000-0099/0074.Search a 2D Matrix/README.md +++ b/solution/0000-0099/0074.Search a 2D Matrix/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md) ## 题目描述 +

    编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:

    @@ -34,15 +35,14 @@ matrix = [ target = 13 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ target = 13 ``` ### **Java** + ```java @@ -57,8 +58,9 @@ target = 13 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md index 50497987cafaa..ad1ab41b02480 100644 --- a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md +++ b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md @@ -3,24 +3,19 @@ [中文文档](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md) ## Description -

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

    - +

    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.
    • +
    • Integers in each row are sorted from left to right.
    • -
    • The first integer of each row is greater than the last integer of the previous row.
    • +
    • The first integer of each row is greater than the last integer of the previous row.
    - -

    Example 1:

    - -
     
     Input:
    @@ -41,12 +36,8 @@ target = 3
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -65,12 +56,8 @@ target = 13
     
     Output: false
    - - - ## Solutions - ### **Python3** @@ -86,8 +73,9 @@ target = 13 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0075.Sort Colors/README.md b/solution/0000-0099/0075.Sort Colors/README.md index 0e28312ab4ded..02320a0d046c8 100644 --- a/solution/0000-0099/0075.Sort Colors/README.md +++ b/solution/0000-0099/0075.Sort Colors/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0075.Sort%20Colors/README_EN.md) ## 题目描述 +

    给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。

    @@ -24,15 +25,14 @@
  • 你能想出一个仅使用常数空间的一趟扫描算法吗?
  • - - ## 解法 - + ### **Python3** + ```python @@ -40,6 +40,7 @@ ``` ### **Java** + ```java @@ -47,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0075.Sort Colors/README_EN.md b/solution/0000-0099/0075.Sort Colors/README_EN.md index bbe83042d614d..892b9b739727d 100644 --- a/solution/0000-0099/0075.Sort Colors/README_EN.md +++ b/solution/0000-0099/0075.Sort Colors/README_EN.md @@ -3,50 +3,35 @@ [中文文档](/solution/0000-0099/0075.Sort%20Colors/README.md) ## Description -

    Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.

    - +

    Given an array with n objects colored red, white or blue, sort them in-place 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 0, 1, and 2 to represent the color red, white, and blue respectively.

    - -

    Note: You are not suppose to use the library's sort function for this problem.

    - -

    Example:

    - -
     
     Input: [2,0,2,1,1,0]
     
     Output: [0,0,1,1,2,2]
    - -

    Follow up:

    - -
      -
    • A rather straight forward solution is a two-pass algorithm using counting sort.
      +
    • A rather straight forward solution is a two-pass algorithm using counting sort.
      - First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
    • + First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's. -
    • Could you come up with a one-pass algorithm using only constant space?
    • +
    • Could you come up with a one-pass algorithm using only constant space?
    - - - ## Solutions - ### **Python3** @@ -62,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0076.Minimum Window Substring/README.md b/solution/0000-0099/0076.Minimum Window Substring/README.md index 34e7d93818c28..a0ff683747f85 100644 --- a/solution/0000-0099/0076.Minimum Window Substring/README.md +++ b/solution/0000-0099/0076.Minimum Window Substring/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md) ## 题目描述 +

    给你一个字符串 S、一个字符串 T,请在字符串 S 里面找出:包含 T 所有字母的最小子串。

    @@ -18,15 +19,14 @@
  • 如果 S 中存在这样的子串,我们保证它是唯一的答案。
  • - - ## 解法 - + ### **Python3** + ```python @@ -34,6 +34,7 @@ ``` ### **Java** + ```java @@ -41,8 +42,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md index 80534f0c34e79..c61ecc773ebcc 100644 --- a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md +++ b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md) ## Description -

    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).

    - +

    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).

    Example:

    - -
     
     Input: S = "ADOBECODEBANC", T = "ABC"
    @@ -19,26 +16,18 @@
     
     
    - -

    Note:

    - -
      -
    • If there is no such window in S that covers all characters in T, return the empty string "".
    • +
    • If there is no such window in S that covers all characters in T, return the empty string "".
    • -
    • If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
    • +
    • If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
    - - - ## Solutions - ### **Python3** @@ -54,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0077.Combinations/README.md b/solution/0000-0099/0077.Combinations/README.md index 50d5b83c98954..de6bd19ef79a5 100644 --- a/solution/0000-0099/0077.Combinations/README.md +++ b/solution/0000-0099/0077.Combinations/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0077.Combinations/README_EN.md) ## 题目描述 +

    给定两个整数 nk,返回 1 ... n 中所有可能的 k 个数的组合。

    @@ -19,15 +20,14 @@ [1,4], ] - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0077.Combinations/README_EN.md b/solution/0000-0099/0077.Combinations/README_EN.md index 001a30305c770..67dab32bf425c 100644 --- a/solution/0000-0099/0077.Combinations/README_EN.md +++ b/solution/0000-0099/0077.Combinations/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0077.Combinations/README.md) ## Description -

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

    - +

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

    Example:

    - -
     
     Input: n = 4, k = 2
    @@ -35,12 +32,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0078.Subsets/README.md b/solution/0000-0099/0078.Subsets/README.md index 9f139cde15a56..59590a4d782b0 100644 --- a/solution/0000-0099/0078.Subsets/README.md +++ b/solution/0000-0099/0078.Subsets/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0078.Subsets/README_EN.md) ## 题目描述 +

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。

    @@ -23,15 +24,14 @@   [] ] - - ## 解法 - + ### **Python3** + ```python @@ -39,6 +39,7 @@ ``` ### **Java** + ```java @@ -46,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0078.Subsets/README_EN.md b/solution/0000-0099/0078.Subsets/README_EN.md index 7e50c1e684fe5..b85820e6cc206 100644 --- a/solution/0000-0099/0078.Subsets/README_EN.md +++ b/solution/0000-0099/0078.Subsets/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0078.Subsets/README.md) ## Description -

    Given a set of distinct integers, nums, return all possible subsets (the power set).

    - +

    Given a set of distinct integers, nums, return all possible subsets (the power set).

    Note: The solution set must not contain duplicate subsets.

    - -

    Example:

    - -
     
     Input: nums = [1,2,3]
    @@ -41,12 +36,8 @@
     
     ]
    - - - ## Solutions - ### **Python3** @@ -62,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0079.Word Search/README.md b/solution/0000-0099/0079.Word Search/README.md index 1be49f6a2ae38..f904152f9b777 100644 --- a/solution/0000-0099/0079.Word Search/README.md +++ b/solution/0000-0099/0079.Word Search/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0079.Word%20Search/README_EN.md) ## 题目描述 +

    给定一个二维网格和一个单词,找出该单词是否存在于网格中。

    @@ -34,15 +35,14 @@
  • 1 <= word.length <= 10^3
  • - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0079.Word Search/README_EN.md b/solution/0000-0099/0079.Word Search/README_EN.md index a66450fff14e1..cbf5dcf2c0d1f 100644 --- a/solution/0000-0099/0079.Word Search/README_EN.md +++ b/solution/0000-0099/0079.Word Search/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0079.Word%20Search/README.md) ## Description -

    Given a 2D board and a word, find if the word exists in the grid.

    - +

    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 neighboring. The same letter cell may not be used more than once.

    - -

    Example:

    - -
     
     board =
    @@ -39,7 +34,6 @@ Given word = "ABCB", return false.
     
     
    -

     

    Constraints:

    @@ -50,11 +44,8 @@ Given word = "ABCB", return false.
  • 1 <= word.length <= 10^3
  • - - ## Solutions - ### **Python3** @@ -70,8 +61,9 @@ Given word = "ABCB", return false. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md index 782b614b44d12..7ba14fc924ba5 100644 --- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md +++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md) ## 题目描述 +

    给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。

    @@ -42,15 +43,14 @@ for (int i = 0; i < len; i++) {     print(nums[i]); } - - ## 解法 - + ### **Python3** + ```python @@ -58,6 +58,7 @@ for (int i = 0; i < len; i++) { ``` ### **Java** + ```java @@ -65,8 +66,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md index 99e3b60dcc04e..c88cd411c432f 100644 --- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md +++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md) ## Description -

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.

    - +

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    - -

    Example 1:

    - -
     
     Given nums = [1,1,1,2,2,3],
    @@ -27,12 +22,8 @@ Your function should return length = 5, with the f
     
     It doesn't matter what you leave beyond the returned length.
    - -

    Example 2:

    - -
     
     Given nums = [0,0,1,1,1,1,2,3,3],
    @@ -47,24 +38,14 @@ It doesn't matter what values are set beyond the returned length.
     
     
    - -

    Clarification:

    - -

    Confused why the returned value is an integer but your answer is an array?

    - -

    Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.

    - -

    Internally you can think of this:

    - -
     
     // nums is passed in by reference. (i.e., without making a copy)
    @@ -85,12 +66,8 @@ for (int i = 0; i < len; i++) {
     
     
    - - - ## Solutions - ### **Python3** @@ -106,8 +83,9 @@ for (int i = 0; i < len; i++) { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md index b58718d9f6668..e809839e984b3 100644 --- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md +++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) ## 题目描述 +

    假设按照升序排序的数组在预先未知的某个点上进行了旋转。

    @@ -28,15 +29,14 @@
  • 这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?
  • - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md index d17a8bd16cc27..d5146e10c3f4b 100644 --- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md +++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md) ## Description -

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    - +

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).

    - -

    You are given a target value to search. If found in the array return true, otherwise return false.

    - -

    Example 1:

    - -
     
     Input: nums = [2,5,6,0,0,1,2], target = 0
    @@ -27,38 +20,26 @@
     
     
    - -

    Example 2:

    - -
     
     Input: nums = [2,5,6,0,0,1,2], target = 3
     
     Output: false
    - -

    Follow up:

    - -
      -
    • This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates.
    • +
    • This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates.
    • -
    • Would this affect the run-time complexity? How and why?
    • +
    • Would this affect the run-time complexity? How and why?
    - - - ## Solutions - ### **Python3** @@ -74,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md index cc89e3be94b35..7daba867527f3 100644 --- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md +++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md) ## 题目描述 +

    给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。

    @@ -17,15 +18,14 @@
    输入: 1->1->1->2->3
     输出: 2->3
    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md index 91f6211ecd028..384649825b4ac 100644 --- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md +++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md) ## Description +

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

    Return the linked list sorted as well.

    @@ -21,11 +22,8 @@ Output: 2->3 - - ## Solutions - ### **Python3** @@ -41,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md index 7b20bf4ca7ac2..373ae88a938f0 100644 --- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md +++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md) ## 题目描述 +

    给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。

    @@ -17,15 +18,14 @@
    输入: 1->1->2->3->3
     输出: 1->2->3
    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md index 3c4ceaa0b296f..161032da90493 100644 --- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md +++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md) ## Description -

    Given a sorted linked list, delete all duplicates such that each element appear only once.

    - +

    Given a sorted linked list, delete all duplicates such that each element appear only once.

    Example 1:

    - -
     
     Input: 1->1->2
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 1->1->2->3->3
    @@ -33,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -54,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js b/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js index a7236a1b8f10c..7078e3b517e4e 100644 --- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js +++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js @@ -9,15 +9,14 @@ * @param {ListNode} head * @return {ListNode} */ -var deleteDuplicates = function(head) { - var p = head; - while (p && p.next) { - if (p.val == p.next.val) { - p.next = p.next.next; - } else { - p = p.next; - } +var deleteDuplicates = function (head) { + var p = head; + while (p && p.next) { + if (p.val == p.next.val) { + p.next = p.next.next; + } else { + p = p.next; } - return head; - + } + return head; }; diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md index 3366593c5b9ec..84e93ef515c6c 100644 --- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md +++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md) ## 题目描述 +

    给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。

    @@ -27,15 +28,14 @@
    输入: [2,1,5,6,2,3]
     输出: 10
    - - ## 解法 - + ### **Python3** + ```python @@ -43,6 +43,7 @@ ``` ### **Java** + ```java @@ -50,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md index 0da7efe7724d6..dbd4674955338 100644 --- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md +++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md @@ -3,36 +3,25 @@ [中文文档](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md) ## Description -

    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.

    +

    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.

     

    - ![](./images/histogram.png) Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

    - -

     

    - - ![](./images/histogram_area.png) The largest rectangle is shown in the shaded area, which has area = 10 unit.

    - -

     

    - -

    Example:

    - -
     
     Input: [2,1,5,6,2,3]
    @@ -41,12 +30,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -62,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0085.Maximal Rectangle/README.md b/solution/0000-0099/0085.Maximal Rectangle/README.md index 1ba1ebb27969d..3b72263eb25bd 100644 --- a/solution/0000-0099/0085.Maximal Rectangle/README.md +++ b/solution/0000-0099/0085.Maximal Rectangle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md) ## 题目描述 +

    给定一个仅包含 0 和 1 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。

    @@ -17,15 +18,14 @@ ] 输出: 6 - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md index 4b7a91424877b..652eaad17b01f 100644 --- a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md +++ b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0085.Maximal%20Rectangle/README.md) ## Description -

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

    - +

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

    Example:

    - -
     
     Input:
    @@ -31,12 +28,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -52,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0086.Partition List/README.md b/solution/0000-0099/0086.Partition List/README.md index e44fb2c97e45f..288f7ce8604bc 100644 --- a/solution/0000-0099/0086.Partition List/README.md +++ b/solution/0000-0099/0086.Partition List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0086.Partition%20List/README_EN.md) ## 题目描述 +

    给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。

    @@ -14,15 +15,14 @@ 输出: 1->2->2->4->3->5 - - ## 解法 - + ### **Python3** + ```python @@ -30,6 +30,7 @@ ``` ### **Java** + ```java @@ -37,8 +38,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0086.Partition List/README_EN.md b/solution/0000-0099/0086.Partition List/README_EN.md index 45b2ce274a78f..81784efe4d78f 100644 --- a/solution/0000-0099/0086.Partition List/README_EN.md +++ b/solution/0000-0099/0086.Partition List/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0086.Partition%20List/README.md) ## Description -

    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.

    - +

    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 the two partitions.

    - -

    Example:

    - -
     
     Input: head = 1->4->3->2->5->2, x = 3
    @@ -23,12 +18,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -44,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0087.Scramble String/README.md b/solution/0000-0099/0087.Scramble String/README.md index 7196b52032834..d08db2d6af261 100644 --- a/solution/0000-0099/0087.Scramble String/README.md +++ b/solution/0000-0099/0087.Scramble String/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0087.Scramble%20String/README_EN.md) ## 题目描述 +

    给定一个字符串 s1,我们可以把它递归地分割成两个非空子字符串,从而将其表示为二叉树。

    @@ -58,15 +59,14 @@ r g ta e
    输入: s1 = "abcde", s2 = "caebd"
     输出: false
    - - ## 解法 - + ### **Python3** + ```python @@ -74,6 +74,7 @@ r g ta e ``` ### **Java** + ```java @@ -81,8 +82,9 @@ r g ta e ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0087.Scramble String/README_EN.md b/solution/0000-0099/0087.Scramble String/README_EN.md index c6948694098fc..e436b9c98e893 100644 --- a/solution/0000-0099/0087.Scramble String/README_EN.md +++ b/solution/0000-0099/0087.Scramble String/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0087.Scramble%20String/README.md) ## Description -

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.

    - +

    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
    @@ -29,16 +26,10 @@ g   r  e   at
     
     
    - -

    To scramble the string, we may choose any non-leaf node and swap its two children.

    - -

    For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".

    - -
     
         rgeat
    @@ -57,16 +48,10 @@ r   g  e   at
     
     
    - -

    We say that "rgeat" is a scrambled string of "great".

    - -

    Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".

    - -
     
         rgtae
    @@ -85,20 +70,12 @@ r   g  ta  e
     
     
    - -

    We say that "rgtae" is a scrambled string of "great".

    - -

    Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.

    - -

    Example 1:

    - -
     
     Input: s1 = "great", s2 = "rgeat"
    @@ -107,24 +84,16 @@ r   g  ta  e
     
     
    - -

    Example 2:

    - -
     
     Input: s1 = "abcde", s2 = "caebd"
     
     Output: false
    - - - ## Solutions - ### **Python3** @@ -140,8 +109,9 @@ r g ta e ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0088.Merge Sorted Array/README.md b/solution/0000-0099/0088.Merge Sorted Array/README.md index 3306d81aee89e..47b8c97754174 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md) ## 题目描述 +

    给你两个有序整数数组 nums1 nums2,请你将 nums2 合并到 nums1 使 num1 成为一个有序数组。

    @@ -25,15 +26,14 @@ nums2 = [2,5,6], n = 3 输出: [1,2,2,3,5,6] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ nums2 = [2,5,6], n = 3 ``` ### **Java** + ```java @@ -48,8 +49,9 @@ nums2 = [2,5,6], n = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md index c880ae610b72f..25ce1c29a2d53 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md @@ -3,28 +3,21 @@ [中文文档](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md) ## Description -

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

    - +

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

    Note:

    - -
      -
    • The number of elements initialized in nums1 and nums2 are m and n respectively.
    • +
    • The number of elements initialized in nums1 and nums2 are m and n respectively.
    • -
    • You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
    • +
    • You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
    - -

    Example:

    - -
     
     Input:
    @@ -39,10 +32,8 @@ nums2 = [2,5,6],       n = 3
     
     
    - ## Solutions - ### **Python3** @@ -58,8 +49,9 @@ nums2 = [2,5,6], n = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0088.Merge Sorted Array/Solution.js b/solution/0000-0099/0088.Merge Sorted Array/Solution.js index 5079f28b336ae..c58e56f83a7dd 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/Solution.js +++ b/solution/0000-0099/0088.Merge Sorted Array/Solution.js @@ -1,39 +1,40 @@ //beat 88% -const merge1 = function(nums1, m, nums2, n){ - const arr = nums1.slice(0,m); - let i = 0, j = 0; +const merge1 = function (nums1, m, nums2, n) { + const arr = nums1.slice(0, m); + let i = 0, + j = 0; let count = 0; - while(i < m && j < n){ - if(arr[i] <= nums2[j]){ + while (i < m && j < n) { + if (arr[i] <= nums2[j]) { nums1[count++] = arr[i++]; - }else{ + } else { nums1[count++] = nums2[j++]; } } - while(i < m){ + while (i < m) { nums1[count++] = arr[i++]; } - while(j < n){ + while (j < n) { nums1[count++] = nums2[j++]; } }; //beat 30%.... -const merge = function(nums1, m, nums2,n){ +const merge = function (nums1, m, nums2, n) { let index = m + n - 1; let aindex = m - 1; let bindex = n - 1; - while(aindex >= 0 && bindex >= 0){ - if(nums1[aindex] > nums2[bindex]){ + while (aindex >= 0 && bindex >= 0) { + if (nums1[aindex] > nums2[bindex]) { nums1[index--] = nums1[aindex--]; - }else{ + } else { nums1[index--] = nums2[bindex--]; } } - while(aindex >= 0){ + while (aindex >= 0) { nums1[index--] = nums1[aindex--]; } - while(bindex >= 0){ + while (bindex >= 0) { nums1[index--] = nums2[bindex--]; } -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0089.Gray Code/README.md b/solution/0000-0099/0089.Gray Code/README.md index 4d99822445f9b..c22ddd9a1b6d3 100644 --- a/solution/0000-0099/0089.Gray Code/README.md +++ b/solution/0000-0099/0089.Gray Code/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0089.Gray%20Code/README_EN.md) ## 题目描述 +

    格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。

    @@ -35,15 +36,14 @@   因此,当 n = 0 时,其格雷编码序列为 [0]。
    - - ## 解法 - + ### **Python3** + ```python @@ -51,6 +51,7 @@ ``` ### **Java** + ```java @@ -58,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0089.Gray Code/README_EN.md b/solution/0000-0099/0089.Gray Code/README_EN.md index e81cdceca878b..53f0f9707cd11 100644 --- a/solution/0000-0099/0089.Gray Code/README_EN.md +++ b/solution/0000-0099/0089.Gray Code/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0089.Gray%20Code/README.md) ## Description -

    The gray code is a binary numeral system where two successive values differ in only one bit.

    - +

    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 gray code. A gray code sequence must begin with 0.

    - -

    Example 1:

    - -
     
     Input: 2
    @@ -49,12 +44,8 @@ For example, [0,2,3,1] is also a valid gray code sequence.
     
     
    - -

    Example 2:

    - -
     
     Input: 0
    @@ -69,12 +60,8 @@ For example, [0,2,3,1] is also a valid gray code sequence.
     
     
    - - - ## Solutions - ### **Python3** @@ -90,8 +77,9 @@ For example, [0,2,3,1] is also a valid gray code sequence. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0090.Subsets II/README.md b/solution/0000-0099/0090.Subsets II/README.md index 0a08a88795bbe..70dc6976b951e 100644 --- a/solution/0000-0099/0090.Subsets II/README.md +++ b/solution/0000-0099/0090.Subsets II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0090.Subsets%20II/README_EN.md) ## 题目描述 +

    给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。

    @@ -21,15 +22,14 @@ [] ] - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0090.Subsets II/README_EN.md b/solution/0000-0099/0090.Subsets II/README_EN.md index 11d53d3aa59e5..062ab27fab4fd 100644 --- a/solution/0000-0099/0090.Subsets II/README_EN.md +++ b/solution/0000-0099/0090.Subsets II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0090.Subsets%20II/README.md) ## Description -

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).

    - +

    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.

    - -

    Example:

    - -
     
     Input: [1,2,2]
    @@ -39,12 +34,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -60,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0091.Decode Ways/README.md b/solution/0000-0099/0091.Decode Ways/README.md index f95ce72fc1c2a..42c33d68d07f9 100644 --- a/solution/0000-0099/0091.Decode Ways/README.md +++ b/solution/0000-0099/0091.Decode Ways/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0091.Decode%20Ways/README_EN.md) ## 题目描述 +

    一条包含字母 A-Z 的消息通过以下方式进行了编码:

    @@ -28,15 +29,14 @@ 解释: 它可以解码为 "BZ" (2 26), "VF" (22 6), 或者 "BBF" (2 2 6) 。 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0091.Decode Ways/README_EN.md b/solution/0000-0099/0091.Decode Ways/README_EN.md index d125d66ade6de..fbb2287f7d9e0 100644 --- a/solution/0000-0099/0091.Decode Ways/README_EN.md +++ b/solution/0000-0099/0091.Decode Ways/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0091.Decode%20Ways/README.md) ## Description -

    A message containing letters from A-Z is being encoded to numbers using the following mapping:

    - +

    A message containing letters from A-Z is being encoded to numbers using the following mapping:

     
    @@ -19,16 +18,10 @@
     
     
    - -

    Given a non-empty string containing only digits, determine the total number of ways to decode it.

    - -

    Example 1:

    - -
     
     Input: "12"
    @@ -39,12 +32,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "226"
    @@ -53,12 +42,8 @@
     
     Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
    - - - ## Solutions - ### **Python3** @@ -74,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0092.Reverse Linked List II/README.md b/solution/0000-0099/0092.Reverse Linked List II/README.md index 59af2aaaab55d..fc24af1aea79e 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) ## 题目描述 +

    反转从位置 mn 的链表。请使用一趟扫描完成反转。

    @@ -14,15 +15,14 @@
    输入: 1->2->3->4->5->NULL, m = 2, n = 4
     输出: 1->4->3->2->5->NULL
    - - ## 解法 - + ### **Python3** + ```python @@ -30,6 +30,7 @@ ``` ### **Java** + ```java @@ -37,8 +38,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md index 07775878ba889..a7b59fee6ae51 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md) ## Description -

    Reverse a linked list from position m to n. Do it in one-pass.

    - +

    Reverse a linked list from position m to n. Do it in one-pass.

    Note: 1 ≤ mn ≤ length of list.

    - -

    Example:

    - -
     
     Input: 1->2->3->4->5->NULL, m = 2, n = 4
    @@ -23,12 +18,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -44,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0093.Restore IP Addresses/README.md b/solution/0000-0099/0093.Restore IP Addresses/README.md index 0ed15a0fa3862..b3c1143e64ea1 100644 --- a/solution/0000-0099/0093.Restore IP Addresses/README.md +++ b/solution/0000-0099/0093.Restore IP Addresses/README.md @@ -1,8 +1,9 @@ -# [93. 复原IP地址](https://leetcode-cn.com/problems/restore-ip-addresses) +# [93. 复原 IP 地址](https://leetcode-cn.com/problems/restore-ip-addresses) [English Version](/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md) ## 题目描述 +

    给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。

    @@ -11,15 +12,14 @@
    输入: "25525511135"
     输出: ["255.255.11.135", "255.255.111.35"]
    - - ## 解法 - + ### **Python3** + ```python @@ -27,6 +27,7 @@ ``` ### **Java** + ```java @@ -34,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md index db16c12cb4a1d..d5da0b07c4098 100644 --- a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md +++ b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md) ## Description -

    Given a string containing only digits, restore it by returning all possible valid IP address combinations.

    - +

    Given a string containing only digits, restore it by returning all possible valid IP address combinations.

    Example:

    - -
     
     Input: "25525511135"
    @@ -19,12 +16,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md index 8af4a86bdc4e1..c378de43be22e 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回它的中序 遍历。

    @@ -19,15 +20,14 @@

    进阶: 递归算法很简单,你可以通过迭代算法完成吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md index 56984f5cc8df8..7d32fecec87cc 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md) ## Description -

    Given a binary tree, return the inorder traversal of its nodes' values.

    - +

    Given a binary tree, return the inorder traversal of its nodes' values.

    Example:

    - -
     
     Input: [1,null,2,3]
    @@ -29,16 +26,10 @@
     
     Output: [1,3,2]
    - -

    Follow up: Recursive solution is trivial, could you do it iteratively?

    - - - ## Solutions - ### **Python3** @@ -54,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md index 80341cb831f86..56e7ea8dacdf2 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md) ## 题目描述 +

    给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树

    @@ -27,15 +28,14 @@ 2 1 2 3 - - ## 解法 - + ### **Python3** + ```python @@ -43,6 +43,7 @@ ``` ### **Java** + ```java @@ -50,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md index 123b44b4f30c7..38d433039d330 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md) ## Description -

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.

    - +

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.

    Example:

    - -
     
     Input: 3
    @@ -49,12 +46,8 @@ The above output corresponds to the 5 unique BST's shown below:
     
     
    - - - ## Solutions - ### **Python3** @@ -70,8 +63,9 @@ The above output corresponds to the 5 unique BST's shown below: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README.md b/solution/0000-0099/0096.Unique Binary Search Trees/README.md index 3bf57e10ec88d..b7f5c05a71dcf 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md) ## 题目描述 +

    给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种?

    @@ -19,15 +20,14 @@ / / \ \ 2 1 2 3 - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md index 3bd2ce868fbb9..3b1132b7dd19b 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md) ## Description -

    Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?

    - +

    Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?

    Example:

    - -
     
     Input: 3
    @@ -35,12 +32,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0097.Interleaving String/README.md b/solution/0000-0099/0097.Interleaving String/README.md index 1aa1ba2dab625..4075c88291078 100644 --- a/solution/0000-0099/0097.Interleaving String/README.md +++ b/solution/0000-0099/0097.Interleaving String/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0097.Interleaving%20String/README_EN.md) ## 题目描述 +

    给定三个字符串 s1, s2, s3, 验证 s3 是否是由 s1 和 s2 交错组成的。

    @@ -17,15 +18,14 @@
    输入: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
     输出: false
    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0097.Interleaving String/README_EN.md b/solution/0000-0099/0097.Interleaving String/README_EN.md index 50f6cda59a7e7..20799ce25a956 100644 --- a/solution/0000-0099/0097.Interleaving String/README_EN.md +++ b/solution/0000-0099/0097.Interleaving String/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0097.Interleaving%20String/README.md) ## Description -

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.

    - +

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.

    Example 1:

    - -
     
     Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
    @@ -19,12 +16,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
    @@ -33,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -54,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README.md b/solution/0000-0099/0098.Validate Binary Search Tree/README.md index 7e7a0cd707fed..e861085c7c3ae 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +

    给定一个二叉树,判断其是否是一个有效的二叉搜索树。

    @@ -36,15 +37,14 @@   根节点的值为 5 ,但是其右子节点值为 4 。 - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ ``` ### **Java** + ```java @@ -59,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md index 3ae7a7719cec4..49583b3cae0fb 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md @@ -3,34 +3,25 @@ [中文文档](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md) ## Description -

    Given a binary tree, determine if it is a valid binary search tree (BST).

    - +

    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 left subtree of a node contains only nodes with keys less than the node's key.
    • -
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • +
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • -
    • Both the left and right subtrees must also be binary search trees.
    • +
    • Both the left and right subtrees must also be binary search trees.
    - -

     

    - -

    Example 1:

    - -
     
         2
    @@ -47,12 +38,8 @@
     
     
    - -

    Example 2:

    - -
     
         5
    @@ -75,12 +62,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -96,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js index 3041c2dd3d535..e67552a7cfdef 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js +++ b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js @@ -9,20 +9,20 @@ * @param {TreeNode} root * @return {boolean} */ -var isValidBST = function(root) { - if (root == null) return true - let arr = [] - inOrderTraverse(root, arr) +var isValidBST = function (root) { + if (root == null) return true; + let arr = []; + inOrderTraverse(root, arr); for (let i = 0; i < arr.length - 1; i++) { - if (arr[i] >= arr[i + 1]) return false + if (arr[i] >= arr[i + 1]) return false; } - return true -} + return true; +}; -var inOrderTraverse = function(node, arr) { +var inOrderTraverse = function (node, arr) { if (node !== null) { - inOrderTraverse(node.left, arr) - arr.push(node.val) - inOrderTraverse(node.right, arr) + inOrderTraverse(node.left, arr); + arr.push(node.val); + inOrderTraverse(node.right, arr); } -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0099.Recover Binary Search Tree/README.md b/solution/0000-0099/0099.Recover Binary Search Tree/README.md index d288d103fdc23..6a7850d48fafc 100644 --- a/solution/0000-0099/0099.Recover Binary Search Tree/README.md +++ b/solution/0000-0099/0099.Recover Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +

    二叉搜索树中的两个节点被错误地交换。

    @@ -52,15 +53,14 @@
  • 你能想出一个只使用常数空间的解决方案吗?
  • - - ## 解法 - + ### **Python3** + ```python @@ -68,6 +68,7 @@ ``` ### **Java** + ```java @@ -75,8 +76,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md b/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md index 457491de00cee..6b97a8c01c425 100644 --- a/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md +++ b/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md) ## Description -

    Two elements of a binary search tree (BST) are swapped by mistake.

    - +

    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]
    @@ -49,12 +44,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [3,1,4,null,null,2]
    @@ -89,26 +80,18 @@
     
     
    - -

    Follow up:

    - -
      -
    • A solution using O(n) space is pretty straight forward.
    • +
    • A solution using O(n) space is pretty straight forward.
    • -
    • Could you devise a constant space solution?
    • +
    • Could you devise a constant space solution?
    - - - ## Solutions - ### **Python3** @@ -124,8 +107,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 3619c3dd53ddf..692f42c813153 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0100.Same%20Tree/README_EN.md) ## 题目描述 +

    给定两个二叉树,编写一个函数来检验它们是否相同。

    @@ -40,15 +41,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -56,6 +56,7 @@ ``` ### **Java** + ```java @@ -63,8 +64,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0100.Same Tree/README_EN.md b/solution/0100-0199/0100.Same Tree/README_EN.md index 368345c29be55..e6f6e43378417 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0100.Same%20Tree/README.md) ## Description -

    Given two binary trees, write a function to check if they are the same or not.

    - +

    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:

    - -
     
     Input:     1         1
    @@ -33,12 +28,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input:     1         1
    @@ -57,12 +48,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input:     1         1
    @@ -81,12 +68,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -102,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0101.Symmetric Tree/README.md b/solution/0100-0199/0101.Symmetric Tree/README.md index 9ecf7c3272f1a..f10538fda6940 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README.md +++ b/solution/0100-0199/0101.Symmetric Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) ## 题目描述 +

    给定一个二叉树,检查它是否是镜像对称的。

    @@ -28,15 +29,14 @@

    如果你可以运用递归和迭代两种方法解决这个问题,会很加分。

    - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0101.Symmetric Tree/README_EN.md b/solution/0100-0199/0101.Symmetric Tree/README_EN.md index d75f1542a3b6e..d612217ad95fe 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README_EN.md +++ b/solution/0100-0199/0101.Symmetric Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0101.Symmetric%20Tree/README.md) ## Description -

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

    - +

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

    For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

    - -
     
         1
    @@ -25,16 +22,10 @@
     
     
    - -

     

    - -

    But the following [1,2,2,null,3,null,3] is not:

    - -
     
         1
    @@ -49,22 +40,14 @@
     
     
    - -

     

    - -

    Note:
    Bonus points if you could solve it both recursively and iteratively.

    - - - ## Solutions - ### **Python3** @@ -80,8 +63,9 @@ Bonus points if you could solve it both recursively and iteratively.

    ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0101.Symmetric Tree/Solution.js b/solution/0100-0199/0101.Symmetric Tree/Solution.js index c590e2f13e7a2..e15f1cc0937f7 100644 --- a/solution/0100-0199/0101.Symmetric Tree/Solution.js +++ b/solution/0100-0199/0101.Symmetric Tree/Solution.js @@ -9,14 +9,17 @@ * @param {TreeNode} root * @return {boolean} */ -var isSymmetric = function(root) { - if (!root) return true - return checkSymmetric(root.left, root.right) +var isSymmetric = function (root) { + if (!root) return true; + return checkSymmetric(root.left, root.right); }; -const checkSymmetric = function(leftNode, rightNode) { - if (!leftNode && !rightNode) return true - if (!leftNode || !rightNode) return false - return leftNode.val === rightNode.val && checkSymmetric(leftNode.left, rightNode.right) - && checkSymmetric(rightNode.left, leftNode.right) -} \ No newline at end of file +const checkSymmetric = function (leftNode, rightNode) { + if (!leftNode && !rightNode) return true; + if (!leftNode || !rightNode) return false; + return ( + leftNode.val === rightNode.val && + checkSymmetric(leftNode.left, rightNode.right) && + checkSymmetric(rightNode.left, leftNode.right) + ); +}; diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md index 969ef6865532f..04c4202c41b84 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。

    @@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md index e712c78688245..a8920edaeb54f 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md) ## Description -

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

    - +

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

    @@ -49,10 +48,8 @@ return its level order traversal as:

    - ## Solutions - ### **Python3** @@ -68,8 +65,9 @@ return its level order traversal as:
    ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js b/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js index 0717fcfac0f33..9826cd6c22eda 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js @@ -9,26 +9,26 @@ * @param {TreeNode} root * @return {number[][]} */ -var levelOrder = function(root) { - let result = [] - if (!root) return result +var levelOrder = function (root) { + let result = []; + if (!root) return result; - let queue = [] - queue.push(root) - while(queue.length) { - let size = queue.length - let levelItems = [] - while(size--) { - let node = queue.shift() - levelItems.push(node.val) - if(node.left) { - queue.push(node.left) + let queue = []; + queue.push(root); + while (queue.length) { + let size = queue.length; + let levelItems = []; + while (size--) { + let node = queue.shift(); + levelItems.push(node.val); + if (node.left) { + queue.push(node.left); } - if(node.right) { - queue.push(node.right) + if (node.right) { + queue.push(node.right); } } - result.push(levelItems) + result.push(levelItems); } - return result -}; \ No newline at end of file + return result; +}; diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md index 75ece96e292f5..79b3cb39488d1 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。

    @@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md index 68a038af80b8a..4e3f8261a5b38 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md) ## Description -

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

    - +

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

    @@ -49,10 +48,8 @@ return its zigzag level order traversal as:

    - ## Solutions - ### **Python3** @@ -68,8 +65,9 @@ return its zigzag level order traversal as:
    ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md index f111d8367c20c..4b5ce7b7f9d93 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md) ## 题目描述 +

    给定一个二叉树,找出其最大深度。

    @@ -21,15 +22,14 @@

    返回它的最大深度 3 。

    - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md index a49e7cbf3ae72..0bf52ceb30c3d 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md) ## Description -

    Given a binary tree, find its maximum depth.

    - +

    Given a binary tree, find its maximum depth.

    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    - -

    Note: A leaf is a node with no children.

    - -

    Example:

    - -

    Given binary tree [3,9,20,null,null,15,7],

    - -
     
         3
    @@ -35,16 +26,10 @@
     
        15   7
    - -

    return its depth = 3.

    - - - ## Solutions - ### **Python3** @@ -60,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js index acc76d2ef85e0..36003284999dc 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js @@ -9,25 +9,28 @@ * @param {TreeNode} root * @return {number} */ -var maxDepth = function(root) { - if (!root) return 0 - let depth = 1 - return search(root,depth) +var maxDepth = function (root) { + if (!root) return 0; + let depth = 1; + return search(root, depth); }; function search(root, depth) { if (!root.left && !root.right) { - return depth + return depth; } else if (root.left && !root.right) { - return search(root.left, depth + 1) + return search(root.left, depth + 1); } else if (root.right && !root.left) { - return search(root.right, depth + 1) + return search(root.right, depth + 1); } else if (root.left && root.right) { - return Math.max(search(root.left, depth+1), search(root.right,depth+1)) + return Math.max( + search(root.left, depth + 1), + search(root.right, depth + 1) + ); } } -var maxDepth2 = function(root) { - if (!root) return 0 - return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1 -} \ No newline at end of file +var maxDepth2 = function (root) { + if (!root) return 0; + return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; +}; diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md index 6fddec0be4b71..cd7da849ab3a2 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) ## 题目描述 +

    根据一棵树的前序遍历与中序遍历构造二叉树。

    @@ -22,15 +23,14 @@ / \ 15 7 - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md index 0ca32b7c6d18b..69f4372cd8caa 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md) ## Description -

    Given preorder and inorder traversal of a tree, construct the binary tree.

    - +

    Given preorder and inorder traversal of a tree, construct the binary tree.

    Note:
    You may assume that duplicates do not exist in the tree.

    - -

    For example, given

    - -
     
     preorder = [3,9,20,15,7]
     
     inorder = [9,3,15,20,7]
    - -

    Return the following binary tree:

    - -
     
         3
    @@ -41,12 +32,8 @@ inorder = [9,3,15,20,7]
    15 7 - - - ## Solutions - ### **Python3** @@ -62,8 +49,9 @@ inorder = [9,3,15,20,7] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md index e03b9b9fbba7a..2125864397fb5 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) ## 题目描述 +

    根据一棵树的中序遍历与后序遍历构造二叉树。

    @@ -23,15 +24,14 @@ 15 7 - - ## 解法 - + ### **Python3** + ```python @@ -39,6 +39,7 @@ ``` ### **Java** + ```java @@ -46,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md index f8e65e30dd26f..74d5fdd38d360 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md) ## Description -

    Given inorder and postorder traversal of a tree, construct the binary tree.

    - +

    Given inorder and postorder traversal of a tree, construct the binary tree.

    Note:
    You may assume that duplicates do not exist in the tree.

    - -

    For example, given

    - -
     
     inorder = [9,3,15,20,7]
     
     postorder = [9,15,7,20,3]
    - -

    Return the following binary tree:

    - -
     
         3
    @@ -43,12 +34,8 @@ postorder = [9,15,7,20,3]
    - - - ## Solutions - ### **Python3** @@ -64,8 +51,9 @@ postorder = [9,15,7,20,3] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md index 157e94c7b16e1..ffc80589a15fc 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)

    @@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md index 7a3c0a15f86e7..42006796350ab 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md) ## Description -

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).

    - +

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).

    @@ -49,10 +48,8 @@ return its bottom-up level order traversal as:

    - ## Solutions - ### **Python3** @@ -68,8 +65,9 @@ return its bottom-up level order traversal as:
    ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md index c932afd0ef78e..6077962f2eab3 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +

    将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。

    @@ -21,15 +22,14 @@ -10 5 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md index 50ad572b2fae1..76cde842dab9d 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md) ## Description -

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

    - +

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

    For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

    - -

    Example:

    - -
     
     Given the sorted array: [-10,-3,0,5,9],
    @@ -37,12 +32,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig
     
     
    - - - ## Solutions - ### **Python3** @@ -58,8 +49,9 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js index 8ffd2f9ac8f34..6ef60dc3f3c2a 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js @@ -9,15 +9,15 @@ * @param {number[]} nums * @return {TreeNode} */ -var sortedArrayToBST = function(nums) { - return nums ? buildTree(nums, 0, nums.length - 1) : null +var sortedArrayToBST = function (nums) { + return nums ? buildTree(nums, 0, nums.length - 1) : null; }; -const buildTree = function(nums, left, right) { - if (left > right) return null - let mid = Math.floor((left + right) / 2) - let root = new TreeNode(nums[mid]) - root.left = buildTree(nums, left, mid - 1) - root.right = buildTree(nums, mid + 1, right) - return root -} \ No newline at end of file +const buildTree = function (nums, left, right) { + if (left > right) return null; + let mid = Math.floor((left + right) / 2); + let root = new TreeNode(nums[mid]); + root.left = buildTree(nums, left, mid - 1); + root.right = buildTree(nums, mid + 1, right); + return root; +}; diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md index 21b142f40ea9a..5ce855405d27b 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +

    给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。

    @@ -21,15 +22,14 @@ -10 5 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md index 6a2eca49d1542..20924e67b9bbc 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md) ## Description -

    Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

    - +

    Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

    For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

    - -

    Example:

    - -
     
     Given the sorted linked list: [-10,-3,0,5,9],
    @@ -37,12 +32,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig
     
     
    - - - ## Solutions - ### **Python3** @@ -58,8 +49,9 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README.md b/solution/0100-0199/0110.Balanced Binary Tree/README.md index 51f7e5fee936b..06f4af4d525cd 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md) ## 题目描述 +

    给定一个二叉树,判断它是否是高度平衡的二叉树。

    @@ -41,15 +42,14 @@

     

    - - ## 解法 - + ### **Python3** + ```python @@ -57,6 +57,7 @@ ``` ### **Java** + ```java @@ -64,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md index abcc8eb133a6c..619c4ff063891 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md) ## Description +

    Given a binary tree, determine if it is height-balanced.

    For this problem, a height-balanced binary tree is defined as:

    @@ -42,11 +43,8 @@

    Return false.

    - - ## Solutions - ### **Python3** @@ -62,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md index 0359edc04b973..7a536e05255af 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) ## 题目描述 +

    给定一个二叉树,找出其最小深度。

    @@ -22,15 +23,14 @@

    返回它的最小深度  2.

    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md index e0822a1475ba8..a4fe63c976a7a 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md) ## Description -

    Given a binary tree, find its minimum depth.

    - +

    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.

    - -

    Note: A leaf is a node with no children.

    - -

    Example:

    - -

    Given binary tree [3,9,20,null,null,15,7],

    - -
     
         3
    @@ -35,16 +26,10 @@
     
        15   7
    - -

    return its minimum depth = 2.

    - - - ## Solutions - ### **Python3** @@ -60,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0112.Path Sum/README.md b/solution/0100-0199/0112.Path Sum/README.md index 2567d5d2aa64f..b7ca033ad435d 100644 --- a/solution/0100-0199/0112.Path Sum/README.md +++ b/solution/0100-0199/0112.Path Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0112.Path%20Sum/README_EN.md) ## 题目描述 +

    给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。

    @@ -22,15 +23,14 @@

    返回 true, 因为存在目标和为 22 的根节点到叶子节点的路径 5->4->11->2

    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0112.Path Sum/README_EN.md b/solution/0100-0199/0112.Path Sum/README_EN.md index 0b243e525a964..8e900346957e4 100644 --- a/solution/0100-0199/0112.Path Sum/README_EN.md +++ b/solution/0100-0199/0112.Path Sum/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0112.Path%20Sum/README.md) ## Description -

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

    - +

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

    Note: A leaf is a node with no children.

    - -

    Example:

    - -

    Given the below binary tree and sum = 22,

    - -
     
           5
    @@ -37,16 +30,10 @@
     
     
    - -

    return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

    - - - ## Solutions - ### **Python3** @@ -62,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0113.Path Sum II/README.md b/solution/0100-0199/0113.Path Sum II/README.md index d53efa3b16c51..a1f1f9bacb766 100644 --- a/solution/0100-0199/0113.Path Sum II/README.md +++ b/solution/0100-0199/0113.Path Sum II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md) ## 题目描述 +

    给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。

    @@ -28,15 +29,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0113.Path Sum II/README_EN.md b/solution/0100-0199/0113.Path Sum II/README_EN.md index b369576a594df..118a2940d014f 100644 --- a/solution/0100-0199/0113.Path Sum II/README_EN.md +++ b/solution/0100-0199/0113.Path Sum II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0113.Path%20Sum%20II/README.md) ## Description -

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.

    - +

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.

    Note: A leaf is a node with no children.

    - -

    Example:

    - -

    Given the below binary tree and sum = 22,

    - -
     
           5
    @@ -37,12 +30,8 @@
     
     
    - -

    Return:

    - -
     
     [
    @@ -55,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -76,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md index 22a3389d4b938..a623f39613a34 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md) ## 题目描述 +

    给定一个二叉树,原地将它展开为链表。

    @@ -28,15 +29,14 @@ \ 6 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md index 352716c7de4ff..3ed856debda60 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md) ## Description -

    Given a binary tree, flatten it to a linked list in-place.

    - +

    Given a binary tree, flatten it to a linked list in-place.

    For example, given the following tree:

    - -
     
         1
    @@ -25,12 +22,8 @@
     
     
    - -

    The flattened tree should look like:

    - -
     
     1
    @@ -57,12 +50,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -78,8 +67,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0115.Distinct Subsequences/README.md b/solution/0100-0199/0115.Distinct Subsequences/README.md index 697791d09b32c..cbef06791fc79 100644 --- a/solution/0100-0199/0115.Distinct Subsequences/README.md +++ b/solution/0100-0199/0115.Distinct Subsequences/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md) ## 题目描述 +

    给定一个字符串 和一个字符串 T,计算在 S 的子序列中 T 出现的个数。

    @@ -45,15 +46,14 @@ babgbag ^^^ - - ## 解法 - + ### **Python3** + ```python @@ -61,6 +61,7 @@ ``` ### **Java** + ```java @@ -68,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md index 3e71c0e1f0264..2203e08397a58 100644 --- a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md +++ b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0115.Distinct%20Subsequences/README.md) ## Description -

    Given a string S and a string T, count the number of distinct subsequences of S which equals T.

    - +

    Given a string S and a string T, count the number of distinct subsequences of S which equals T.

    A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).

    - -

    Example 1:

    - -
     
     Input: S = "rabbbit", T = "rabbit"
    @@ -45,12 +40,8 @@ As shown below, there are 3 ways you can generate "rabbit" from S.
     
     
    - -

    Example 2:

    - -
     
     Input: S = "babgbag", T = "bag"
    @@ -89,12 +80,8 @@ As shown below, there are 5 ways you can generate "bag" from S.
     
     
    - - - ## Solutions - ### **Python3** @@ -110,8 +97,9 @@ As shown below, there are 5 ways you can generate "bag" from S. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md index fc2c5c82c3524..bf13328542ba9 100644 --- a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md +++ b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md) ## 题目描述 +

    给定一个完美二叉树,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:

    @@ -39,15 +40,14 @@
  • 使用递归解题也符合要求,本题中递归程序占用的栈空间不算做额外的空间复杂度。
  • - - ## 解法 - + ### **Python3** + ```python @@ -55,6 +55,7 @@ ``` ### **Java** + ```java @@ -62,8 +63,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md index 2665d2c0dd03e..c135cdc2224a7 100644 --- a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md +++ b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md) ## Description +

    You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

    @@ -46,11 +47,8 @@ struct Node {
     	
  • -1000 <= node.val <= 1000
  • - - ## Solutions - ### **Python3** @@ -66,8 +64,9 @@ struct Node { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md index 9957c1044720f..00ec462ba409b 100644 --- a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md +++ b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md) ## 题目描述 +

    给定一个二叉树

    @@ -50,15 +51,14 @@
    - - ## 解法 - + ### **Python3** + ```python @@ -66,6 +66,7 @@ ``` ### **Java** + ```java @@ -73,8 +74,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md index 5d0fd0dc892c3..7b866a408b68f 100644 --- a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md +++ b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md) ## Description +

    Given a binary tree

    @@ -46,11 +47,8 @@ struct Node {
     	
  • -100 <= node.val <= 100
  • - - ## Solutions - ### **Python3** @@ -66,8 +64,9 @@ struct Node { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0118.Pascal's Triangle/README.md b/solution/0100-0199/0118.Pascal's Triangle/README.md index 14cc74f16063b..b591fcc606629 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/README.md +++ b/solution/0100-0199/0118.Pascal's Triangle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0118.Pascal's%20Triangle/README_EN.md) ## 题目描述 +

    给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。

    @@ -22,15 +23,14 @@ [1,4,6,4,1] ]
    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md index 6de5e56430cc6..67fd49d6efc89 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md +++ b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md @@ -3,20 +3,15 @@ [中文文档](/solution/0100-0199/0118.Pascal's%20Triangle/README.md) ## Description -

    Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.

    - +

    Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.


    In Pascal's triangle, each number is the sum of the two numbers directly above it.

    - -

    Example:

    - -
     
     Input: 5
    @@ -39,12 +34,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -60,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0118.Pascal's Triangle/Solution.js b/solution/0100-0199/0118.Pascal's Triangle/Solution.js index 389a05a3cee30..1729352a996ef 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/Solution.js +++ b/solution/0100-0199/0118.Pascal's Triangle/Solution.js @@ -1,33 +1,34 @@ -const generate = function(numRows){ +const generate = function (numRows) { let arr = []; - for(let i = 0; i < numRows; i++){ + for (let i = 0; i < numRows; i++) { let row = []; - row[0]=1; + row[0] = 1; row[i] = 1; - for(let j = 1; j < row.length - 1; j++){ - row[j] = arr[i-1][j-1] + arr[i-1][j]; + for (let j = 1; j < row.length - 1; j++) { + row[j] = arr[i - 1][j - 1] + arr[i - 1][j]; } arr.push(row); } return arr; -} +}; -/** +/** * Author: Mcnwork2018 */ -var generate = function(numRows) { +var generate = function (numRows) { if (numRows === 0) return []; if (numRows === 1) return [[1]]; - if (numRows === 2) return [[1],[1,1]]; - let triangleArray = [[1],[1,1]]; - for ( let i = 2; i < numRows; ++i ) { + if (numRows === 2) return [[1], [1, 1]]; + let triangleArray = [[1], [1, 1]]; + for (let i = 2; i < numRows; ++i) { triangleArray[i] = []; - for ( let j = 0; j < i + 1; ++j ) { - if ( j === 0 || j === i ) { + for (let j = 0; j < i + 1; ++j) { + if (j === 0 || j === i) { triangleArray[i][j] = 1; } else { - triangleArray[i][j] = triangleArray[i-1][j-1] + triangleArray[i-1][j]; + triangleArray[i][j] = + triangleArray[i - 1][j - 1] + triangleArray[i - 1][j]; } } } diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README.md b/solution/0100-0199/0119.Pascal's Triangle II/README.md index 17afbcb40665b..522cc9e20959c 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0119.Pascal's%20Triangle%20II/README_EN.md) ## 题目描述 +

    给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。

    @@ -20,15 +21,14 @@

    你可以优化你的算法到 O(k) 空间复杂度吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md index 69a04077c4109..80349d60a4575 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/solution/0100-0199/0119.Pascal's%20Triangle%20II/README.md) ## Description -

    Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

    - +

    Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

    Note that the row index starts from 0.

    - -


    In Pascal's triangle, each number is the sum of the two numbers directly above it.

    - -

    Example:

    - -
     
     Input: 3
    @@ -29,20 +22,12 @@
     
     
    - -

    Follow up:

    - -

    Could you optimize your algorithm to use only O(k) extra space?

    - - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0120.Triangle/README.md b/solution/0100-0199/0120.Triangle/README.md index c7424ca2e6810..ecb8b5431907e 100644 --- a/solution/0100-0199/0120.Triangle/README.md +++ b/solution/0100-0199/0120.Triangle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0120.Triangle/README_EN.md) ## 题目描述 +

    给定一个三角形,找出自顶向下的最小路径和。每一步只能移动到下一行中相邻的结点上。

    @@ -22,15 +23,14 @@

    如果你可以只使用 O(n) 的额外空间(n 为三角形的总行数)来解决这个问题,那么你的算法会很加分。

    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0120.Triangle/README_EN.md b/solution/0100-0199/0120.Triangle/README_EN.md index 9f040325f4e37..2dd78b2659fe7 100644 --- a/solution/0100-0199/0120.Triangle/README_EN.md +++ b/solution/0100-0199/0120.Triangle/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0120.Triangle/README.md) ## Description -

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

    - +

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

    For example, given the following triangle

    - -
     
     [
    @@ -27,24 +24,14 @@
     
     
    - -

    The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

    - -

    Note:

    - -

    Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.

    - - - ## Solutions - ### **Python3** @@ -60,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md index c1ebcaa461003..16a7bb382e6b9 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md) ## 题目描述 +

    给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。

    @@ -25,15 +26,14 @@ 解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。
    - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md index 61a5de7e54f16..841b2dfa58fde 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md) ## Description -

    Say you have an array for which the ith element is the price of a given stock on day i.

    - +

    Say you have an array for which the ith element is the price of a given stock on day i.

    If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

    - -

    Note that you cannot sell a stock before you buy one.

    - -

    Example 1:

    - -
     
     Input: [7,1,5,3,6,4]
    @@ -31,12 +24,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [7,6,4,3,1]
    @@ -47,12 +36,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -68,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js index 3d987432e802b..c3befd504f155 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js @@ -1,13 +1,13 @@ -const maxProfit1 = function(prices){ +const maxProfit1 = function (prices) { let min = prices[0]; let profit = 0; - for(let i = 0; i < prices.length; i++){ - if(prices[i] < min){ + for (let i = 0; i < prices.length; i++) { + if (prices[i] < min) { min = prices[i]; } - if(profit < (prices[i] - min)){ + if (profit < prices[i] - min) { profit = prices[i] - min; } } return profit; -} \ No newline at end of file +}; diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md index 0827a65b60c08..b344f71324c62 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md) ## 题目描述 +

    给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。

    @@ -33,15 +34,14 @@ 输出: 0 解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。 - - ## 解法 - + ### **Python3** + ```python @@ -49,6 +49,7 @@ ``` ### **Java** + ```java @@ -56,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md index 0ae5643d6a583..370ede8140510 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md) ## Description -

    Say you have an array for which the ith element is the price of a given stock on day i.

    - +

    Say you have an array for which the ith element is the price of a given stock on day i.

    Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

    - -

    Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

    - -

    Example 1:

    - -
     
     Input: [7,1,5,3,6,4]
    @@ -31,12 +24,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [1,2,3,4,5]
    @@ -51,12 +40,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: [7,6,4,3,1]
    @@ -65,12 +50,8 @@
     
     Explanation: In this case, no transaction is done, i.e. max profit = 0.
    - - - ## Solutions - ### **Python3** @@ -86,8 +67,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js index 968e6ce14380d..d00f2b0b639a9 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js @@ -1,9 +1,9 @@ -const maxProfit2 = function(prices){ +const maxProfit2 = function (prices) { let profit = 0; - for(let i = 1; i < prices.length; i++){ - if(prices[i]-prices[i-1] > 0){ - profit+=prices[i]-prices[i-1]; + for (let i = 1; i < prices.length; i++) { + if (prices[i] - prices[i - 1] > 0) { + profit += prices[i] - prices[i - 1]; } } return profit; -} \ No newline at end of file +}; diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md index b256b8aca36cd..f2e64cff93f90 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md) ## 题目描述 +

    给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。

    @@ -32,15 +33,14 @@ 输出: 0 解释: 在这个情况下, 没有交易完成, 所以最大利润为 0。 - - ## 解法 - + ### **Python3** + ```python @@ -48,6 +48,7 @@ ``` ### **Java** + ```java @@ -55,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md index b4d8d1eca617b..2853c6d76792f 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md) ## Description -

    Say you have an array for which the ith element is the price of a given stock on day i.

    - +

    Say you have an array for which the ith element is the price of a given stock on day i.

    Design an algorithm to find the maximum profit. You may complete at most two transactions.

    - -

    Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

    - -

    Example 1:

    - -
     
     Input: [3,3,5,0,0,3,1,4]
    @@ -29,12 +22,8 @@
     
                  Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
    - -

    Example 2:

    - -
     
     Input: [1,2,3,4,5]
    @@ -49,12 +38,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: [7,6,4,3,1]
    @@ -63,12 +48,8 @@
     
     Explanation: In this case, no transaction is done, i.e. max profit = 0.
    - - - ## Solutions - ### **Python3** @@ -84,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md index 0d666762f8ca9..224b5f10f81f6 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md) ## 题目描述 +

    给定一个非空二叉树,返回其最大路径和。

    @@ -31,15 +32,14 @@ 输出: 42 - - ## 解法 - + ### **Python3** + ```python @@ -47,6 +47,7 @@ ``` ### **Java** + ```java @@ -54,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md index ecc6ed4fabc43..60ce04d920e91 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md) ## Description -

    Given a non-empty binary tree, find the maximum path sum.

    - +

    Given a non-empty binary tree, find the maximum path sum.

    For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.

    - -

    Example 1:

    - -
     
     Input: [1,2,3]
    @@ -33,12 +28,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [-10,9,20,null,null,15,7]
    @@ -61,12 +52,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -82,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/README.md b/solution/0100-0199/0125.Valid Palindrome/README.md index 8937571686bc4..03e2fd5fb8451 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README.md +++ b/solution/0100-0199/0125.Valid Palindrome/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md) ## 题目描述 +

    给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。

    @@ -20,15 +21,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/README_EN.md b/solution/0100-0199/0125.Valid Palindrome/README_EN.md index 90cbfcf982972..568b1fb9a3112 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README_EN.md +++ b/solution/0100-0199/0125.Valid Palindrome/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0125.Valid%20Palindrome/README.md) ## Description -

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    - +

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    Note: For the purpose of this problem, we define empty string as valid palindrome.

    - -

    Example 1:

    - -
     
     Input: "A man, a plan, a canal: Panama"
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "race a car"
    @@ -37,12 +28,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/Solution.js b/solution/0100-0199/0125.Valid Palindrome/Solution.js index 7b7829d41c008..f31fb301b557f 100644 --- a/solution/0100-0199/0125.Valid Palindrome/Solution.js +++ b/solution/0100-0199/0125.Valid Palindrome/Solution.js @@ -1,48 +1,50 @@ -const isPalindrome1 = function(s){ - let arr1 = [], arr2 = []; - for(let i = 0; i < s.length; i++){ - if(s[i] >= 'A' && s[i] <= 'Z' ){ +const isPalindrome1 = function (s) { + let arr1 = [], + arr2 = []; + for (let i = 0; i < s.length; i++) { + if (s[i] >= "A" && s[i] <= "Z") { arr1.push(s[i].toLowerCase()); } - if(s[i] >= '0' && s[i] <= '9'|| - s[i] >= 'a' && s[i] <= 'z'){ + if ((s[i] >= "0" && s[i] <= "9") || (s[i] >= "a" && s[i] <= "z")) { arr1.push(s[i]); } } arr2 = [...arr1]; arr2.reverse(); - return arr1.join('') === arr2.join(''); -} + return arr1.join("") === arr2.join(""); +}; -const isPalindrome = function(s){ - function isNumOrAl(a){ - if(a >= 'A' && a <= 'Z' || - a >= '0' && a <= '9'|| - a >= 'a' && a <= 'z'){ +const isPalindrome = function (s) { + function isNumOrAl(a) { + if ( + (a >= "A" && a <= "Z") || + (a >= "0" && a <= "9") || + (a >= "a" && a <= "z") + ) { return true; - } - else{ + } else { return false; } } - if(s.length === 0){ + if (s.length === 0) { return true; } - let i = 0, j = s.length - 1; - while(i < j){ - while(i < j && !isNumOrAl(s[i])){ + let i = 0, + j = s.length - 1; + while (i < j) { + while (i < j && !isNumOrAl(s[i])) { i++; } - while(i < j && !isNumOrAl(s[j])){ + while (i < j && !isNumOrAl(s[j])) { j--; } - if(s[i].toLowerCase() !== s[j].toLowerCase()){ + if (s[i].toLowerCase() !== s[j].toLowerCase()) { return false; - }else{ + } else { i++; j--; } } return true; -}; \ No newline at end of file +}; diff --git a/solution/0100-0199/0126.Word Ladder II/README.md b/solution/0100-0199/0126.Word Ladder II/README.md index 266a881b4b34a..07a111c85ce8e 100644 --- a/solution/0100-0199/0126.Word Ladder II/README.md +++ b/solution/0100-0199/0126.Word Ladder II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md) ## 题目描述 +

    给定两个单词(beginWordendWord)和一个字典 wordList,找出所有从 beginWord endWord 的最短转换序列。转换需遵循如下规则:

    @@ -46,15 +47,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以不存在符合要求的转换序列。 - - ## 解法 - + ### **Python3** + ```python @@ -62,6 +62,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -69,8 +70,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0126.Word Ladder II/README_EN.md b/solution/0100-0199/0126.Word Ladder II/README_EN.md index 8945d68e4b420..599d319688121 100644 --- a/solution/0100-0199/0126.Word Ladder II/README_EN.md +++ b/solution/0100-0199/0126.Word Ladder II/README_EN.md @@ -3,44 +3,35 @@ [中文文档](/solution/0100-0199/0126.Word%20Ladder%20II/README.md) ## Description -

    Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:

    - +

    Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:

      -
    1. Only one letter can be changed at a time
    2. +
    3. Only one letter can be changed at a time
    4. -
    5. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
    6. +
    7. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
    - -

    Note:

    - -
      -
    • Return an empty list if there is no such transformation sequence.
    • +
    • Return an empty list if there is no such transformation sequence.
    • -
    • All words have the same length.
    • +
    • All words have the same length.
    • -
    • All words contain only lowercase alphabetic characters.
    • +
    • All words contain only lowercase alphabetic characters.
    • -
    • You may assume no duplicates in the word list.
    • +
    • You may assume no duplicates in the word list.
    • -
    • You may assume beginWord and endWord are non-empty and are not the same.
    • +
    • You may assume beginWord and endWord are non-empty and are not the same.
    - -

    Example 1:

    - -
     
     Input:
    @@ -65,12 +56,8 @@ wordList = ["hot","dot","dog","lot",&quo
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -91,18 +78,12 @@ wordList = ["hot","dot","dog","lot",&quo
     
     
    - -
    - - - ## Solutions - ### **Python3** @@ -118,8 +99,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0127.Word Ladder/README.md b/solution/0100-0199/0127.Word Ladder/README.md index b9dec4b1addb0..696c14972c3b7 100644 --- a/solution/0100-0199/0127.Word Ladder/README.md +++ b/solution/0100-0199/0127.Word Ladder/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0127.Word%20Ladder/README_EN.md) ## 题目描述 +

    给定两个单词(beginWord endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则:

    @@ -45,15 +46,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以无法进行转换。 - - ## 解法 - + ### **Python3** + ```python @@ -61,6 +61,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -68,8 +69,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0127.Word Ladder/README_EN.md b/solution/0100-0199/0127.Word Ladder/README_EN.md index 5532897e8facb..18cffacc47620 100644 --- a/solution/0100-0199/0127.Word Ladder/README_EN.md +++ b/solution/0100-0199/0127.Word Ladder/README_EN.md @@ -3,44 +3,35 @@ [中文文档](/solution/0100-0199/0127.Word%20Ladder/README.md) ## Description -

    Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:

    - +

    Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:

      -
    1. Only one letter can be changed at a time.
    2. +
    3. Only one letter can be changed at a time.
    4. -
    5. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
    6. +
    7. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
    - -

    Note:

    - -
      -
    • Return 0 if there is no such transformation sequence.
    • +
    • Return 0 if there is no such transformation sequence.
    • -
    • All words have the same length.
    • +
    • All words have the same length.
    • -
    • All words contain only lowercase alphabetic characters.
    • +
    • All words contain only lowercase alphabetic characters.
    • -
    • You may assume no duplicates in the word list.
    • +
    • You may assume no duplicates in the word list.
    • -
    • You may assume beginWord and endWord are non-empty and are not the same.
    • +
    • You may assume beginWord and endWord are non-empty and are not the same.
    - -

    Example 1:

    - -
     
     Input:
    @@ -63,12 +54,8 @@ return its length 5.
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -89,18 +76,12 @@ wordList = ["hot","dot","dog","lot",&quo
     
     
    - -
    - - - ## Solutions - ### **Python3** @@ -116,8 +97,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0128.Longest Consecutive Sequence/README.md b/solution/0100-0199/0128.Longest Consecutive Sequence/README.md index 669f43a9ccc40..b4a7a0b25bb18 100644 --- a/solution/0100-0199/0128.Longest Consecutive Sequence/README.md +++ b/solution/0100-0199/0128.Longest Consecutive Sequence/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md) ## 题目描述 +

    给定一个未排序的整数数组,找出最长连续序列的长度。

    @@ -14,15 +15,14 @@ 输出: 4 解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。 - - ## 解法 - + ### **Python3** + ```python @@ -30,6 +30,7 @@ ``` ### **Java** + ```java @@ -37,8 +38,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md index 02c69fe784e7a..c00319c3b127c 100644 --- a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md +++ b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md) ## Description -

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

    - +

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

    Your algorithm should run in O(n) complexity.

    - -

    Example:

    - -
     
     Input: [100, 4, 200, 1, 3, 2]
    @@ -25,12 +20,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md index 3b1488ab21695..a0ca8d3e67db9 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md) ## 题目描述 +

    给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字。

    @@ -39,15 +40,14 @@ 从根到叶子节点路径 4->0 代表数字 40. 因此,数字总和 = 495 + 491 + 40 = 1026. - - ## 解法 - + ### **Python3** + ```python @@ -55,6 +55,7 @@ ``` ### **Java** + ```java @@ -62,8 +63,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md index d1abd44a9bc97..6c3bce87d5295 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md) ## Description -

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

    - +

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

    An example is the root-to-leaf path 1->2->3 which represents the number 123.

    - -

    Find the total sum of all root-to-leaf numbers.

    - -

    Note: A leaf is a node with no children.

    - -

    Example:

    - -
     
     Input: [1,2,3]
    @@ -43,12 +34,8 @@ The root-to-leaf path 1->3 represents the number 13
     
     Therefore, sum = 12 + 13 = 25.
    - -

    Example 2:

    - -
     
     Input: [4,9,0,5,1]
    @@ -75,12 +62,8 @@ The root-to-leaf path 4->0 represents the number 40.
     
     Therefore, sum = 495 + 491 + 40 = 1026.
    - - - ## Solutions - ### **Python3** @@ -96,8 +79,9 @@ Therefore, sum = 495 + 491 + 40 = 1026. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0130.Surrounded Regions/README.md b/solution/0100-0199/0130.Surrounded Regions/README.md index abe3491d2e689..96792addb83c6 100644 --- a/solution/0100-0199/0130.Surrounded Regions/README.md +++ b/solution/0100-0199/0130.Surrounded Regions/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md) ## 题目描述 +

    给定一个二维的矩阵,包含 'X' 和 'O'字母 O)。

    @@ -28,15 +29,14 @@ X O X X

    被围绕的区间不会存在于边界上,换句话说,任何边界上的 'O' 都不会被填充为 'X'。 任何不在边界上,或不与边界上的 'O' 相连的 'O' 最终都会被填充为 'X'。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。

    - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ X O X X ``` ### **Java** + ```java @@ -51,8 +52,9 @@ X O X X ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0130.Surrounded Regions/README_EN.md b/solution/0100-0199/0130.Surrounded Regions/README_EN.md index 7baaa27ce758e..454a9ce57cb78 100644 --- a/solution/0100-0199/0130.Surrounded Regions/README_EN.md +++ b/solution/0100-0199/0130.Surrounded Regions/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0130.Surrounded%20Regions/README.md) ## Description -

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.

    - +

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.

    A region is captured by flipping all 'O's into 'X's in that surrounded region.

    - -

    Example:

    - -
     
     X X X X
    @@ -27,12 +22,8 @@ X O X X
     
     
    - -

    After running your function, the board should be:

    - -
     
     X X X X
    @@ -45,20 +36,12 @@ X O X X
     
     
    - -

    Explanation:

    - -

    Surrounded regions shouldn’t be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.

    - - - ## Solutions - ### **Python3** @@ -74,8 +57,9 @@ X O X X ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0131.Palindrome Partitioning/README.md b/solution/0100-0199/0131.Palindrome Partitioning/README.md index cc5fc2618b7eb..553e46159ef1d 100644 --- a/solution/0100-0199/0131.Palindrome Partitioning/README.md +++ b/solution/0100-0199/0131.Palindrome Partitioning/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md) ## 题目描述 +

    给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。

    @@ -17,15 +18,14 @@ ["a","a","b"] ] - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md index cdaf40438b637..c3fbd5f8eacfd 100644 --- a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md +++ b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0131.Palindrome%20Partitioning/README.md) ## Description -

    Given a string s, partition s such that every substring of the partition is a palindrome.

    - +

    Given a string s, partition s such that every substring of the partition is a palindrome.

    Return all possible palindrome partitioning of s.

    - -

    Example:

    - -
     
     Input: "aab"
    @@ -31,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -52,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README.md b/solution/0100-0199/0132.Palindrome Partitioning II/README.md index 85fdeba48ed38..e52af7b0395ac 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md) ## 题目描述 +

    给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。

    @@ -15,15 +16,14 @@ 解释: 进行一次分割就可将 s 分割成 ["aa","b"] 这样两个回文子串。 - - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md index 730206937fd48..9a5e96d1928e5 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md) ## Description -

    Given a string s, partition s such that every substring of the partition is a palindrome.

    - +

    Given a string s, partition s such that every substring of the partition is a palindrome.

    Return the minimum cuts needed for a palindrome partitioning of s.

    - -

    Example:

    - -
     
     Input: "aab"
    @@ -25,12 +20,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0133.Clone Graph/README.md b/solution/0100-0199/0133.Clone Graph/README.md index ed9e5432e2857..cc0104f398d23 100644 --- a/solution/0100-0199/0133.Clone Graph/README.md +++ b/solution/0100-0199/0133.Clone Graph/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0133.Clone%20Graph/README_EN.md) ## 题目描述 +

    给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆)。

    @@ -74,15 +75,14 @@
  • 图是连通图,你可以从给定节点访问到所有节点。
  • - - ## 解法 - + ### **Python3** + ```python @@ -90,6 +90,7 @@ ``` ### **Java** + ```java @@ -97,8 +98,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0133.Clone Graph/README_EN.md b/solution/0100-0199/0133.Clone Graph/README_EN.md index c60c1ee19d3e5..56e92130b62df 100644 --- a/solution/0100-0199/0133.Clone Graph/README_EN.md +++ b/solution/0100-0199/0133.Clone Graph/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0133.Clone%20Graph/README.md) ## Description +

    Given a reference of a node in a connected undirected graph.

    Return a deep copy (clone) of the graph.

    @@ -79,11 +80,8 @@ class Node {
  • The Graph is connected and all nodes can be visited starting from the given node.
  • - - ## Solutions - ### **Python3** @@ -99,8 +97,9 @@ class Node { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0134.Gas Station/README.md b/solution/0100-0199/0134.Gas Station/README.md index 53969a2a9ac69..ee8256c2e858d 100644 --- a/solution/0100-0199/0134.Gas Station/README.md +++ b/solution/0100-0199/0134.Gas Station/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0134.Gas%20Station/README_EN.md) ## 题目描述 +

    在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。

    @@ -51,15 +52,14 @@ cost = [3,4,3] 你无法返回 2 号加油站,因为返程需要消耗 4 升汽油,但是你的油箱只有 3 升汽油。 因此,无论怎样,你都不可能绕环路行驶一周。 - - ## 解法 - + ### **Python3** + ```python @@ -67,6 +67,7 @@ cost = [3,4,3] ``` ### **Java** + ```java @@ -74,8 +75,9 @@ cost = [3,4,3] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0134.Gas Station/README_EN.md b/solution/0100-0199/0134.Gas Station/README_EN.md index a6d0313fb280a..f480dbae98bf3 100644 --- a/solution/0100-0199/0134.Gas Station/README_EN.md +++ b/solution/0100-0199/0134.Gas Station/README_EN.md @@ -3,38 +3,27 @@ [中文文档](/solution/0100-0199/0134.Gas%20Station/README.md) ## Description -

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i].

    - +

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i].

    You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.

    - -

    Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

    - -

    Note:

    - -
      -
    • If there exists a solution, it is guaranteed to be unique.
    • +
    • If there exists a solution, it is guaranteed to be unique.
    • -
    • Both input arrays are non-empty and have the same length.
    • +
    • Both input arrays are non-empty and have the same length.
    • -
    • Each element in the input arrays is a non-negative integer.
    • +
    • Each element in the input arrays is a non-negative integer.
    - -

    Example 1:

    - -
     
     Input: 
    @@ -67,12 +56,8 @@ Therefore, return 3 as the starting index.
     
     
    - -

    Example 2:

    - -
     
     Input: 
    @@ -103,12 +88,8 @@ Therefore, you can't travel around the circuit once no matter where you star
     
     
    - - - ## Solutions - ### **Python3** @@ -124,8 +105,9 @@ Therefore, you can't travel around the circuit once no matter where you star ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0135.Candy/README.md b/solution/0100-0199/0135.Candy/README.md index 0da185cb0d1e8..4fe98bb6ea2cc 100644 --- a/solution/0100-0199/0135.Candy/README.md +++ b/solution/0100-0199/0135.Candy/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0135.Candy/README_EN.md) ## 题目描述 +

    老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分。

    @@ -29,15 +30,14 @@ 解释: 你可以分别给这三个孩子分发 1、2、1 颗糖果。 第三个孩子只得到 1 颗糖果,这已满足上述两个条件。 - - ## 解法 - + ### **Python3** + ```python @@ -45,6 +45,7 @@ ``` ### **Java** + ```java @@ -52,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0135.Candy/README_EN.md b/solution/0100-0199/0135.Candy/README_EN.md index 951113ed77041..38ab6559be674 100644 --- a/solution/0100-0199/0135.Candy/README_EN.md +++ b/solution/0100-0199/0135.Candy/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0135.Candy/README.md) ## Description -

    There are N children standing in a line. Each child is assigned a rating value.

    - +

    There are N children standing in a line. Each child is assigned a rating value.

    You are giving candies to these children subjected to the following requirements:

    - -
      -
    • Each child must have at least one candy.
    • +
    • Each child must have at least one candy.
    • -
    • Children with a higher rating get more candies than their neighbors.
    • +
    • Children with a higher rating get more candies than their neighbors.
    - -

    What is the minimum candies you must give?

    - -

    Example 1:

    - -
     
     Input: [1,0,2]
    @@ -39,12 +30,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [1,2,2]
    @@ -57,12 +44,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -78,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/README.md b/solution/0100-0199/0136.Single Number/README.md index d56f9ed935162..db48956a93ae5 100644 --- a/solution/0100-0199/0136.Single Number/README.md +++ b/solution/0100-0199/0136.Single Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0136.Single%20Number/README_EN.md) ## 题目描述 +

    给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。

    @@ -21,9 +22,8 @@
    输入: [4,1,2,1,2]
     输出: 4
    - - ## 解法 + 异或运算求解。 @@ -33,6 +33,7 @@ ### **Python3** + ```python @@ -45,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -60,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/README_EN.md b/solution/0100-0199/0136.Single Number/README_EN.md index af064b6d6c979..b2d674e9034f3 100644 --- a/solution/0100-0199/0136.Single Number/README_EN.md +++ b/solution/0100-0199/0136.Single Number/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0136.Single%20Number/README.md) ## Description -

    Given a non-empty array of integers, every element appears twice except for one. Find that single one.

    - +

    Given a non-empty array of integers, every element appears twice except for one. Find that single one.

    Note:

    - -

    Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

    - -

    Example 1:

    - -
     
     Input: [2,2,1]
    @@ -27,12 +20,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [4,1,2,1,2]
    @@ -41,12 +30,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -75,8 +60,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/Solution.js b/solution/0100-0199/0136.Single Number/Solution.js index 094bc6fcfcb65..35d56f03a1468 100644 --- a/solution/0100-0199/0136.Single Number/Solution.js +++ b/solution/0100-0199/0136.Single Number/Solution.js @@ -1,26 +1,26 @@ -const singleNumber2 = function(nums){ +const singleNumber2 = function (nums) { const map = {}; - for(let i = 0; i < nums.length; i++){ - if(map[nums[i]] === undefined){ + for (let i = 0; i < nums.length; i++) { + if (map[nums[i]] === undefined) { map[nums[i]] = 1; - }else if(map[nums[i]] === 1){ + } else if (map[nums[i]] === 1) { map[nums[i]]++; } } - for(let key in map){ - if(map[key] === 1){ + for (let key in map) { + if (map[key] === 1) { return Number(key); } } -} -const singleNumber = function(nums){ +}; +const singleNumber = function (nums) { //XOR let result = 0; - for(let i = 0; i < nums.length; i++){ + for (let i = 0; i < nums.length; i++) { result = result ^ nums[i]; } return result; //or in es6 //return nums.reduce((result, num) => result ^ num, 0); -} +}; diff --git a/solution/0100-0199/0137.Single Number II/README.md b/solution/0100-0199/0137.Single Number II/README.md index 652039d6e293f..444fd87c2639a 100644 --- a/solution/0100-0199/0137.Single Number II/README.md +++ b/solution/0100-0199/0137.Single Number II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) ## 题目描述 +

    给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次。找出那个只出现了一次的元素。

    @@ -21,9 +22,8 @@
    输入: [0,1,0,1,0,1,99]
     输出: 99
    - - ## 解法 + 统计所有数字每个位中 1 出现的次数,对于某个位,1 出现的次数一定是 3 的倍数 +1 或 0。对这个数 %3 得到的结果就是那个出现一次的数字在该位上的值。 @@ -31,6 +31,7 @@ ### **Python3** + ```python @@ -38,6 +39,7 @@ ``` ### **Java** + ```java @@ -63,8 +65,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0137.Single Number II/README_EN.md b/solution/0100-0199/0137.Single Number II/README_EN.md index 958587dfc15c2..78521cf9a9282 100644 --- a/solution/0100-0199/0137.Single Number II/README_EN.md +++ b/solution/0100-0199/0137.Single Number II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0137.Single%20Number%20II/README.md) ## Description -

    Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.

    - +

    Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.

    Note:

    - -

    Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

    - -

    Example 1:

    - -
     
     Input: [2,2,3,2]
    @@ -27,24 +20,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [0,1,0,1,0,1,99]
     
     Output: 99
    - - - ## Solutions - ### **Python3** @@ -78,8 +63,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0138.Copy List with Random Pointer/README.md b/solution/0100-0199/0138.Copy List with Random Pointer/README.md index 56cc4d6360715..2a555e7ed20b7 100644 --- a/solution/0100-0199/0138.Copy List with Random Pointer/README.md +++ b/solution/0100-0199/0138.Copy List with Random Pointer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md) ## 题目描述 +

    给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。

    @@ -58,15 +59,14 @@
  • 节点数目不超过 1000 。
  • - - ## 解法 - + ### **Python3** + ```python @@ -74,6 +74,7 @@ ``` ### **Java** + ```java @@ -81,8 +82,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md b/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md index ff09f9b646f63..eafcb7bbe9a2c 100644 --- a/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md +++ b/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md) ## Description +

    A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

    Return a deep copy of the list.

    @@ -59,11 +60,8 @@
  • Number of Nodes will not exceed 1000.
  • - - ## Solutions - ### **Python3** @@ -79,8 +77,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0139.Word Break/README.md b/solution/0100-0199/0139.Word Break/README.md index c895d5fcc4f4f..0d73c8b9ac2c5 100644 --- a/solution/0100-0199/0139.Word Break/README.md +++ b/solution/0100-0199/0139.Word Break/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0139.Word%20Break/README_EN.md) ## 题目描述 +

    给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。

    @@ -34,15 +35,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0139.Word Break/README_EN.md b/solution/0100-0199/0139.Word Break/README_EN.md index 8a22fab944b13..7e6310f54d2fe 100644 --- a/solution/0100-0199/0139.Word Break/README_EN.md +++ b/solution/0100-0199/0139.Word Break/README_EN.md @@ -3,28 +3,21 @@ [中文文档](/solution/0100-0199/0139.Word%20Break/README.md) ## Description -

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

    - +

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

    Note:

    - -
      -
    • The same word in the dictionary may be reused multiple times in the segmentation.
    • +
    • The same word in the dictionary may be reused multiple times in the segmentation.
    • -
    • You may assume the dictionary does not contain duplicate words.
    • +
    • You may assume the dictionary does not contain duplicate words.
    - -

    Example 1:

    - -
     
     Input: s = "leetcode", wordDict = ["leet", "code"]
    @@ -35,12 +28,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: s = "applepenapple", wordDict = ["apple", "pen"]
    @@ -53,12 +42,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
    @@ -67,12 +52,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -88,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0140.Word Break II/README.md b/solution/0100-0199/0140.Word Break II/README.md index c452d47af5a9e..21646391f8ba2 100644 --- a/solution/0100-0199/0140.Word Break II/README.md +++ b/solution/0100-0199/0140.Word Break II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0140.Word%20Break%20II/README_EN.md) ## 题目描述 +

    给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中。返回所有这些可能的句子。

    @@ -48,15 +49,14 @@ wordDict = ["cats", "dog", "sand", "and"
    [] - - ## 解法 - + ### **Python3** + ```python @@ -64,6 +64,7 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **Java** + ```java @@ -71,8 +72,9 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0140.Word Break II/README_EN.md b/solution/0100-0199/0140.Word Break II/README_EN.md index a2387fc4cabd5..b5db5c303f2d5 100644 --- a/solution/0100-0199/0140.Word Break II/README_EN.md +++ b/solution/0100-0199/0140.Word Break II/README_EN.md @@ -3,28 +3,21 @@ [中文文档](/solution/0100-0199/0140.Word%20Break%20II/README.md) ## Description -

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.

    - +

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.

    Note:

    - -
      -
    • The same word in the dictionary may be reused multiple times in the segmentation.
    • +
    • The same word in the dictionary may be reused multiple times in the segmentation.
    • -
    • You may assume the dictionary does not contain duplicate words.
    • +
    • You may assume the dictionary does not contain duplicate words.
    - -

    Example 1:

    - -
     
     Input:
    @@ -45,12 +38,8 @@ wordDict = ["cat", "cats", "and", "sand
     
     
    - -

    Example 2:

    - -
     
     Input:
    @@ -75,12 +64,8 @@ wordDict = ["apple", "pen", "applepen", "pine
     
     
    - -

    Example 3:

    - -
     
     Input:
    @@ -93,12 +78,8 @@ wordDict = ["cats", "dog", "sand", "and"
     
     []
    - - - ## Solutions - ### **Python3** @@ -114,8 +95,9 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/README.md b/solution/0100-0199/0141.Linked List Cycle/README.md index d7a2019a0407e..689a543d57151 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README.md +++ b/solution/0100-0199/0141.Linked List Cycle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) ## 题目描述 +

    给定一个链表,判断链表中是否有环。

    @@ -26,7 +27,6 @@ 解释:链表中有一个环,其尾部连接到第一个节点。 - ![](./images/circularlinkedlist_test2.png)

    示例 3:

    @@ -44,19 +44,18 @@

    你能用 O(1)(即,常量)内存解决此问题吗?

    - - ## 解法 + 定义快慢指针 `slow`、`fast`,初始指向 `head`。 快指针每次走两步,慢指针每次走一步,不断循环。当相遇时,说明链表存在环。如果循环结束依然没有相遇,说明链表不存在环。 - ### **Python3** + ```python @@ -77,6 +76,7 @@ class Solution: ``` ### **Java** + ```java @@ -108,8 +108,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/README_EN.md b/solution/0100-0199/0141.Linked List Cycle/README_EN.md index 94f762619328c..71a9efcb7518c 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README_EN.md +++ b/solution/0100-0199/0141.Linked List Cycle/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md) ## Description -

    Given a linked list, determine if it has a cycle in it.

    - +

    Given a linked list, determine if it has a cycle in it.

    To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

    - -

     

    - -

    Example 1:

    - -
     
     Input: head = [3,2,0,-4], pos = 1
    @@ -33,18 +26,12 @@
     
     
    - -
    ![](./images/circularlinkedlist.png) - -

    Example 2:

    - -
     
     Input: head = [1,2], pos = 0
    @@ -57,17 +44,12 @@
     
     
    - -
    ![](./images/circularlinkedlist_test2.png) -

    Example 3:

    - -
     
     Input: head = [1], pos = -1
    @@ -80,27 +62,16 @@
     
     
    - - ![](./images/circularlinkedlist_test3.png) -

     

    - -

    Follow up:

    - -

    Can you solve it using O(1) (i.e. constant) memory?

    - - - ## Solutions - ### **Python3** @@ -153,8 +124,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/Solution.js b/solution/0100-0199/0141.Linked List Cycle/Solution.js index b2203e08904d7..e8d13b69e8d94 100644 --- a/solution/0100-0199/0141.Linked List Cycle/Solution.js +++ b/solution/0100-0199/0141.Linked List Cycle/Solution.js @@ -10,29 +10,26 @@ * @param {ListNode} head * @return {boolean} */ -var hasCycle = function(head) { - flag = false; - - dfs(head); +var hasCycle = function (head) { + flag = false; - return flag; + dfs(head); + + return flag; }; function dfs(node) { - if (flag) - return; + if (flag) return; - if (node === null) - return; + if (node === null) return; if (node.flag) { flag = true; return; } - if (node.next === null) - return; + if (node.next === null) return; node.flag = true; dfs(node.next); -} \ No newline at end of file +} diff --git a/solution/0100-0199/0142.Linked List Cycle II/README.md b/solution/0100-0199/0142.Linked List Cycle II/README.md index 4fd91c4c7c801..12bc2b2d822d1 100644 --- a/solution/0100-0199/0142.Linked List Cycle II/README.md +++ b/solution/0100-0199/0142.Linked List Cycle II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) ## 题目描述 +

    给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null

    @@ -44,9 +45,8 @@

    进阶:
    你是否可以不用额外空间解决此题?

    - - ## 解法 + 先利用快慢指针判断链表是否有环,没有环则直接返回 `null`。 @@ -57,7 +57,7 @@ ![](./images/linked-list-cycle-ii.png) -我们根据式子①②,得出 `X+Y=N(Y+Z)` => `X=(N-1)(Y+Z)+Z`。 +我们根据式子 ①②,得出 `X+Y=N(Y+Z)` => `X=(N-1)(Y+Z)+Z`。 当 `N=1`(快指针在环中走了一圈与慢指针相遇) 时,`X=(1-1)(Y+Z)+Z`,即 `X=Z`。此时只要定义一个 `p` 指针指向头节点,然后慢指针与 `p` 开始同时走,当慢指针与 `p` 相遇时,也就到达了环入口,直接返回 `p` 即可。 @@ -66,6 +66,7 @@ ### **Python3** + ```python @@ -93,6 +94,7 @@ class Solution: ``` ### **Java** + ```java @@ -133,8 +135,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0142.Linked List Cycle II/README_EN.md b/solution/0100-0199/0142.Linked List Cycle II/README_EN.md index bf20a2f8650cd..2e3d01697b628 100644 --- a/solution/0100-0199/0142.Linked List Cycle II/README_EN.md +++ b/solution/0100-0199/0142.Linked List Cycle II/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md) ## Description +

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

    To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

    @@ -46,11 +47,8 @@

    Follow-up:
    Can you solve it without using extra space?

    - - ## Solutions - ### **Python3** @@ -119,8 +117,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0143.Reorder List/README.md b/solution/0100-0199/0143.Reorder List/README.md index b9d6e6f26bce8..434cc69789710 100644 --- a/solution/0100-0199/0143.Reorder List/README.md +++ b/solution/0100-0199/0143.Reorder List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0143.Reorder%20List/README_EN.md) ## 题目描述 +

    给定一个单链表 LL0L1→…→Ln-1Ln ,
    将其重新排列后变为: L0LnL1Ln-1L2Ln-2→…

    @@ -17,15 +18,14 @@
    给定链表 1->2->3->4->5, 重新排列为 1->5->2->4->3.
    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0143.Reorder List/README_EN.md b/solution/0100-0199/0143.Reorder List/README_EN.md index 11025db0f4555..82833ecd51b6a 100644 --- a/solution/0100-0199/0143.Reorder List/README_EN.md +++ b/solution/0100-0199/0143.Reorder List/README_EN.md @@ -3,42 +3,29 @@ [中文文档](/solution/0100-0199/0143.Reorder%20List/README.md) ## Description +

    Given a singly linked list L: L0L1→…→Ln-1Ln,
    reorder it to: L0LnL1Ln-1L2Ln-2→…

    - -

    You may not modify the values in the list's nodes, only nodes itself may be changed.

    - -

    Example 1:

    - -
     
     Given 1->2->3->4, reorder it to 1->4->2->3.
    - -

    Example 2:

    - -
     
     Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
     
     
    - - - ## Solutions - ### **Python3** @@ -54,8 +41,9 @@ Given 1->2->3->4->5, reorder it to 1->5->2->4->3. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md index 176921b426a63..77ed81d7f5325 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回它的 前序 遍历。

    @@ -20,15 +21,14 @@

    进阶: 递归算法很简单,你可以通过迭代算法完成吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md index 96a14ed933aa7..2cf76c191bc96 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md) ## Description -

    Given a binary tree, return the preorder traversal of its nodes' values.

    - +

    Given a binary tree, return the preorder traversal of its nodes' values.

    Example:

    - -
     
     Input: [1,null,2,3]
    @@ -31,16 +28,10 @@
     
     
    - -

    Follow up: Recursive solution is trivial, could you do it iteratively?

    - - - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md index af565cfdb2e76..3d62457bd5272 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md) ## 题目描述 +

    给定一个二叉树,返回它的 后序 遍历。

    @@ -19,15 +20,14 @@

    进阶: 递归算法很简单,你可以通过迭代算法完成吗?

    - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md index 0ebfc7e06a972..1aa49480e34d9 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md) ## Description -

    Given a binary tree, return the postorder traversal of its nodes' values.

    - +

    Given a binary tree, return the postorder traversal of its nodes' values.

    Example:

    - -
     
     Input: [1,null,2,3]
    @@ -31,16 +28,10 @@
     
     
    - -

    Follow up: Recursive solution is trivial, could you do it iteratively?

    - - - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0146.Lru Cache/README.md b/solution/0100-0199/0146.Lru Cache/README.md index 9e048805a5fc8..6b6b91a40f423 100644 --- a/solution/0100-0199/0146.Lru Cache/README.md +++ b/solution/0100-0199/0146.Lru Cache/README.md @@ -1,8 +1,9 @@ -# [146. LRU缓存机制](https://leetcode-cn.com/problems/lru-cache) +# [146. LRU 缓存机制](https://leetcode-cn.com/problems/lru-cache) [English Version](/solution/0100-0199/0146.Lru%20Cache/README_EN.md) ## 题目描述 +

    运用你所掌握的数据结构,设计和实现一个  LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和 写入数据 put

    @@ -28,15 +29,14 @@ cache.get(3); // 返回 3 cache.get(4); // 返回 4 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ cache.get(4); // 返回 4 ``` ### **Java** + ```java @@ -51,8 +52,9 @@ cache.get(4); // 返回 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0146.Lru Cache/README_EN.md b/solution/0100-0199/0146.Lru Cache/README_EN.md index c036b1feaca13..de96df3b4ec1a 100644 --- a/solution/0100-0199/0146.Lru Cache/README_EN.md +++ b/solution/0100-0199/0146.Lru Cache/README_EN.md @@ -3,30 +3,21 @@ [中文文档](/solution/0100-0199/0146.Lru%20Cache/README.md) ## Description -

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

    - +

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

    get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
    put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

    - -

    The cache is initialized with a positive capacity.

    - -

    Follow up:
    Could you do both operations in O(1) time complexity?

    - -

    Example:

    - -
     
     LRUCache cache = new LRUCache( 2 /* capacity */ );
    @@ -53,16 +44,10 @@ cache.get(4);       // returns 4
     
     
    - -

     

    - - - ## Solutions - ### **Python3** @@ -78,8 +63,9 @@ cache.get(4); // returns 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0147.Insertion Sort List/README.md b/solution/0100-0199/0147.Insertion Sort List/README.md index 8f17e5bf0d67e..f89c6bf02283c 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README.md +++ b/solution/0100-0199/0147.Insertion Sort List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) ## 题目描述 +

    对链表进行插入排序。

    @@ -34,15 +35,14 @@ 输出: -1->0->3->4->5 - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0147.Insertion Sort List/README_EN.md b/solution/0100-0199/0147.Insertion Sort List/README_EN.md index d64447373d89a..50f0f542de0af 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README_EN.md +++ b/solution/0100-0199/0147.Insertion Sort List/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md) ## Description -

    Sort a linked list using insertion sort.

    - +

    Sort a linked list using insertion sort.

    - -


    A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.
    @@ -21,36 +18,26 @@ With each iteration one element (red) is removed from the input data and inserte  

    - -
    - -

    Algorithm of Insertion Sort:

    - -
      -
    1. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
    2. +
    3. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
    4. -
    5. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
    6. +
    7. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
    8. -
    9. It repeats until no input elements remain.
    10. +
    11. It repeats until no input elements remain.
    - -


    Example 1:

    - -
     
     Input: 4->2->1->3
    @@ -59,12 +46,8 @@ With each iteration one element (red) is removed from the input data and inserte
     
     
    - -

    Example 2:

    - -
     
     Input: -1->5->3->4->0
    @@ -73,12 +56,8 @@ With each iteration one element (red) is removed from the input data and inserte
     
     
    - - - ## Solutions - ### **Python3** @@ -94,8 +73,9 @@ With each iteration one element (red) is removed from the input data and inserte ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0148.Sort List/README.md b/solution/0100-0199/0148.Sort List/README.md index 273f94ffc9eb0..4a0f810efe14c 100644 --- a/solution/0100-0199/0148.Sort List/README.md +++ b/solution/0100-0199/0148.Sort List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0148.Sort%20List/README_EN.md) ## 题目描述 +

    在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序。

    @@ -17,15 +18,14 @@
    输入: -1->5->3->4->0
     输出: -1->0->3->4->5
    - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0148.Sort List/README_EN.md b/solution/0100-0199/0148.Sort List/README_EN.md index f8c4cb1401e32..8630904e1c58d 100644 --- a/solution/0100-0199/0148.Sort List/README_EN.md +++ b/solution/0100-0199/0148.Sort List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0148.Sort%20List/README.md) ## Description -

    Sort a linked list in O(n log n) time using constant space complexity.

    - +

    Sort a linked list in O(n log n) time using constant space complexity.

    Example 1:

    - -
     
     Input: 4->2->1->3
    @@ -19,24 +16,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: -1->5->3->4->0
     
     Output: -1->0->3->4->5
    - - - ## Solutions - ### **Python3** @@ -52,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0149.Max Points on a Line/README.md b/solution/0100-0199/0149.Max Points on a Line/README.md index ce607accddbaf..22c75d33b7c4e 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README.md +++ b/solution/0100-0199/0149.Max Points on a Line/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md) ## 题目描述 +

    给定一个二维平面,平面上有 个点,求最多有多少个点在同一条直线上。

    @@ -34,15 +35,14 @@ +-------------------> 0  1  2  3  4  5  6 - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0149.Max Points on a Line/README_EN.md b/solution/0100-0199/0149.Max Points on a Line/README_EN.md index 75101c4a67381..99ec40316dc1a 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README_EN.md +++ b/solution/0100-0199/0149.Max Points on a Line/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md) ## Description -

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

    - +

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

    Example 1:

    - -
     
     Input: [[1,1],[2,2],[3,3]]
    @@ -35,12 +32,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
    @@ -67,16 +60,10 @@
     
     
    - -

    NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

    - - - ## Solutions - ### **Python3** @@ -92,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md index 5d7fa91102ff5..e9191e42477a4 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) ## 题目描述 +

    根据逆波兰表示法,求表达式的值。

    @@ -42,15 +43,14 @@ = 17 + 5 = 22 - - ## 解法 - + ### **Python3** + ```python @@ -58,6 +58,7 @@ ``` ### **Java** + ```java @@ -65,8 +66,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md index 99058b99f0352..0e7223b2d8f0e 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md) ## Description -

    Evaluate the value of an arithmetic expression in Reverse Polish Notation.

    - +

    Evaluate the value of an arithmetic expression in Reverse Polish Notation.

    Valid operators are +, -, *, /. Each operand may be an integer or another expression.

    - -

    Note:

    - -
      -
    • Division between two integers should truncate toward zero.
    • +
    • Division between two integers should truncate toward zero.
    • -
    • The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
    • +
    • The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
    - -

    Example 1:

    - -
     
     Input: ["2", "1", "+", "3", "*"]
    @@ -39,12 +30,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: ["4", "13", "5", "/", "+"]
    @@ -55,12 +42,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
    @@ -85,12 +68,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -106,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0151.Reverse Words in a String/README.md b/solution/0100-0199/0151.Reverse Words in a String/README.md index c03768b73732d..4f03f03f9a304 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md) ## 题目描述 +

    给定一个字符串,逐个翻转字符串中的每个单词。

    @@ -44,15 +45,14 @@

    请选用 C 语言的用户尝试使用 O(1) 额外空间复杂度的原地解法。

    - - ## 解法 - + ### **Python3** + ```python @@ -60,6 +60,7 @@ ``` ### **Java** + ```java @@ -67,8 +68,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md index 91aa38be326ce..d53d7a76ab067 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md) ## Description -

    Given an input string, reverse the string word by word.

    - +

    Given an input string, reverse the string word by word.

     

    - -

    Example 1:

    - -
     
     Input: "the sky is blue"
    @@ -23,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "  hello world!  "
    @@ -39,12 +30,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "a good   example"
    @@ -55,42 +42,28 @@
     
     
    - -

     

    - -

    Note:

    - -
      -
    • A word is defined as a sequence of non-space characters.
    • +
    • A word is defined as a sequence of non-space characters.
    • -
    • Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
    • +
    • Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
    • -
    • You need to reduce multiple spaces between two words to a single space in the reversed string.
    • +
    • You need to reduce multiple spaces between two words to a single space in the reversed string.
    - -

     

    - -

    Follow up:

    - -

    For C programmers, try to solve it in-place in O(1) extra space.

    - ## Solutions - ### **Python3** @@ -106,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0152.Maximum Product Subarray/README.md b/solution/0100-0199/0152.Maximum Product Subarray/README.md index 3385b68ba2eda..437cdb312c7b5 100644 --- a/solution/0100-0199/0152.Maximum Product Subarray/README.md +++ b/solution/0100-0199/0152.Maximum Product Subarray/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) ## 题目描述 +

    给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。

    @@ -19,15 +20,14 @@ 输出: 0 解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。 - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md b/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md index 93a510bc00d6f..bbf770d875b2d 100644 --- a/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md +++ b/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md) ## Description -

    Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

    - +

    Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

    Example 1:

    - -
     
     Input: [2,3,-2,4]
    @@ -21,12 +18,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [-2,0,-1]
    @@ -35,12 +28,8 @@
     
     Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
    - - - ## Solutions - ### **Python3** @@ -56,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md index 7d8f658bb546e..4222a73be2634 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) ## 题目描述 +

    假设按照升序排序的数组在预先未知的某个点上进行了旋转。

    @@ -22,15 +23,14 @@
    输入: [4,5,6,7,0,1,2]
     输出: 0
    - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md index 9b436f7a24d88..2b0bd455c1c36 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md) ## Description -

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    - +

    Suppose an array sorted in ascending order 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]).

    - -

    Find the minimum element.

    - -

    You may assume no duplicate exists in the array.

    - -

    Example 1:

    - -
     
     Input: [3,4,5,1,2] 
    @@ -31,12 +22,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: [4,5,6,7,0,1,2]
    @@ -45,12 +32,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -66,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md index 0bcc0da4aa076..b829a8cb0620a 100644 --- a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md +++ b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) ## 题目描述 +

    假设按照升序排序的数组在预先未知的某个点上进行了旋转。

    @@ -29,15 +30,14 @@
  • 允许重复会影响算法的时间复杂度吗?会如何影响,为什么?
  • - - ## 解法 - + ### **Python3** + ```python @@ -45,6 +45,7 @@ ``` ### **Java** + ```java @@ -52,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md index 08f335507ef59..a955be9d8506e 100644 --- a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md +++ b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md @@ -3,64 +3,43 @@ [中文文档](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md) ## Description -

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    - +

    Suppose an array sorted in ascending order 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]).

    - -

    Find the minimum element.

    - -

    The array may contain duplicates.

    - -

    Example 1:

    - -
     
     Input: [1,3,5]
     
     Output: 1
    - -

    Example 2:

    - -
     
     Input: [2,2,2,0,1]
     
     Output: 0
    - -

    Note:

    - - - - - ## Solutions - ### **Python3** @@ -76,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0155.Min Stack/README.md b/solution/0100-0199/0155.Min Stack/README.md index 6b514f0f705c3..04008542e3ef6 100644 --- a/solution/0100-0199/0155.Min Stack/README.md +++ b/solution/0100-0199/0155.Min Stack/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0155.Min%20Stack/README_EN.md) ## 题目描述 +

    设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。

    @@ -25,15 +26,14 @@ minStack.top(); --> 返回 0. minStack.getMin(); --> 返回 -2. - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ minStack.getMin(); --> 返回 -2. ``` ### **Java** + ```java @@ -48,8 +49,9 @@ minStack.getMin(); --> 返回 -2. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0155.Min Stack/README_EN.md b/solution/0100-0199/0155.Min Stack/README_EN.md index 884b6eb3e9b14..82d21e247b15a 100644 --- a/solution/0100-0199/0155.Min Stack/README_EN.md +++ b/solution/0100-0199/0155.Min Stack/README_EN.md @@ -3,32 +3,25 @@ [中文文档](/solution/0100-0199/0155.Min%20Stack/README.md) ## Description -

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

    - +

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

      -
    • push(x) -- Push element x onto stack.
    • +
    • push(x) -- Push element x onto stack.
    • -
    • pop() -- Removes the element on top of the stack.
    • +
    • pop() -- Removes the element on top of the stack.
    • -
    • top() -- Get the top element.
    • +
    • top() -- Get the top element.
    • -
    • getMin() -- Retrieve the minimum element in the stack.
    • +
    • getMin() -- Retrieve the minimum element in the stack.
    - -

     

    - -

    Example:

    - -
     
     MinStack minStack = new MinStack();
    @@ -49,16 +42,10 @@ minStack.getMin();   --> Returns -2.
     
     
    - -

     

    - - - ## Solutions - ### **Python3** @@ -74,8 +61,9 @@ minStack.getMin(); --> Returns -2. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0155.Min Stack/Solution.js b/solution/0100-0199/0155.Min Stack/Solution.js index 6eeb33e680fc0..4c285f515456d 100644 --- a/solution/0100-0199/0155.Min Stack/Solution.js +++ b/solution/0100-0199/0155.Min Stack/Solution.js @@ -1,62 +1,62 @@ /** * initialize your data structure here. */ -const MinStack = function() { +const MinStack = function () { this.arr = []; - this.help = []; + this.help = []; }; -/** +/** * @param {number} x * @return {void} */ -MinStack.prototype.push = function(x) { - this.arr.push(x); - if(this.help.length === 0){ - this.help.push(0); - }else{ - let min = this.getMin(); - if(x < min){ - this.help.push(this.arr.length-1); - } +MinStack.prototype.push = function (x) { + this.arr.push(x); + if (this.help.length === 0) { + this.help.push(0); + } else { + let min = this.getMin(); + if (x < min) { + this.help.push(this.arr.length - 1); } + } }; /** * @return {void} */ -MinStack.prototype.pop = function() { - if(this.arr.length === 0){ - throw new Error('???'); - } - if(this.arr.length - 1 === this.help[this.help.length - 1]){ - this.help.pop(); - } - this.arr.pop(); +MinStack.prototype.pop = function () { + if (this.arr.length === 0) { + throw new Error("???"); + } + if (this.arr.length - 1 === this.help[this.help.length - 1]) { + this.help.pop(); + } + this.arr.pop(); }; /** * @return {number} */ -MinStack.prototype.top = function() { - return this.arr[this.arr.length-1]; +MinStack.prototype.top = function () { + return this.arr[this.arr.length - 1]; }; /** * @return {number} */ -MinStack.prototype.getMin = function() { - if(this.arr.length === 0){ - throw new Error("???"); - } - return this.arr[this.help[this.help.length-1]]; +MinStack.prototype.getMin = function () { + if (this.arr.length === 0) { + throw new Error("???"); + } + return this.arr[this.help[this.help.length - 1]]; }; -/** +/** * Your MinStack object will be instantiated and called as such: * var obj = Object.create(MinStack).createNew() * obj.push(x) * obj.pop() * var param_3 = obj.top() * var param_4 = obj.getMin() - */ \ No newline at end of file + */ diff --git a/solution/0100-0199/0156.Binary Tree Upside Down/README.md b/solution/0100-0199/0156.Binary Tree Upside Down/README.md index 3c6bbf66c38ca..a45ca3d3cc82d 100644 --- a/solution/0100-0199/0156.Binary Tree Upside Down/README.md +++ b/solution/0100-0199/0156.Binary Tree Upside Down/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md) ## 题目描述 +

    给定一个二叉树,其中所有的右节点要么是具有兄弟节点(拥有相同父节点的左节点)的叶节点,要么为空,将此二叉树上下翻转并将它变成一棵树, 原来的右节点将转换成左叶节点。返回新的根。

    @@ -44,15 +45,14 @@

    上面的二叉树则被序列化为 [1,2,3,#,#,4,#,#,5].

    - - ## 解法 - + ### **Python3** + ```python @@ -60,6 +60,7 @@ ``` ### **Java** + ```java @@ -67,8 +68,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md b/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md index 493e5c496e5e0..8f19f8901cdb2 100644 --- a/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md +++ b/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README.md) ## Description +

    Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.

    Example:

    @@ -45,11 +46,8 @@

    The above binary tree is serialized as [1,2,3,#,#,4,#,#,5].

    - - ## Solutions - ### **Python3** @@ -65,8 +63,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0157.Read N Characters Given Read4/README.md b/solution/0100-0199/0157.Read N Characters Given Read4/README.md index 4dfb3942c8a83..5b9bc2ba1370b 100644 --- a/solution/0100-0199/0157.Read N Characters Given Read4/README.md +++ b/solution/0100-0199/0157.Read N Characters Given Read4/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md) ## 题目描述 +

    给你一个文件,并且该文件只能通过给定的 read4 方法来读取,请实现一个方法使其能够读取 n 个字符。

    @@ -85,15 +86,14 @@ read4(buf4); // read4 返回 0。现在 buf = "",fp 指向文件末
  • 你可以假定目标缓存数组 buf 保证有足够的空间存下 n 个字符。 
  • - - ## 解法 - + ### **Python3** + ```python @@ -101,6 +101,7 @@ read4(buf4); // read4 返回 0。现在 buf = "",fp 指向文件末 ``` ### **Java** + ```java @@ -108,8 +109,9 @@ read4(buf4); // read4 返回 0。现在 buf = "",fp 指向文件末 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md b/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md index 8c39b5a5d9849..d306bce26c002 100644 --- a/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md +++ b/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README.md) ## Description +

    Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters.

     

    @@ -97,11 +98,8 @@ Note: buf[] is destination not source, you will need to write the results to buf
  • You may assume the destination buffer array, buf, is guaranteed to have enough space for storing n characters.
  • - - ## Solutions - ### **Python3** @@ -117,8 +115,9 @@ Note: buf[] is destination not source, you will need to write the results to buf ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README.md b/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README.md index 11c333e4c2bfc..ba31567c28cb2 100644 --- a/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README.md +++ b/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md) ## 题目描述 +

    给你一个文件,并且该文件只能通过给定的 read4 方法来读取,请实现一个方法使其能够读取 n 个字符。注意:你的 read 方法可能会被调用多次。

    @@ -66,15 +67,14 @@ sol.read(buf, 1); // 由于已经到达了文件末尾,没有更多的字符
  • 保证在一个给定测试用例中,read 函数使用的是同一个 buf
  • - - ## 解法 - + ### **Python3** + ```python @@ -82,6 +82,7 @@ sol.read(buf, 1); // 由于已经到达了文件末尾,没有更多的字符 ``` ### **Java** + ```java @@ -89,8 +90,9 @@ sol.read(buf, 1); // 由于已经到达了文件末尾,没有更多的字符 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README_EN.md b/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README_EN.md index ca38b8618f282..ec891672b4ed8 100644 --- a/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README_EN.md +++ b/solution/0100-0199/0158.Read N Characters Given Read4 II - Call multiple times/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README.md) ## Description +

    Given a file and assume that you can only read the file using a given method read4, implement a method read to read n characters. Your method read may be called multiple times.

     

    @@ -87,11 +88,8 @@ sol.read(buf, 1); // We have reached the end of file, no more characters can be
  • It is guaranteed that in a given test case the same buffer buf is called by read.
  • - - ## Solutions - ### **Python3** @@ -107,8 +105,9 @@ sol.read(buf, 1); // We have reached the end of file, no more characters can be ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md index 87887fbb8c50d..b2dfcfe28f4dd 100644 --- a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md +++ b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md) ## 题目描述 +

    给定一个字符串 s ,找出 至多 包含两个不同字符的最长子串 t ,并返回该子串的长度。

    @@ -20,15 +21,14 @@ 解释: t 是 "aabbb",长度为5。 - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md index a29d4f8877a91..c08dc0db6f62c 100644 --- a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md +++ b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md) ## Description +

    Given a string s , find the length of the longest substring t  that contains at most 2 distinct characters.

    Example 1:

    @@ -21,11 +22,8 @@ Explanation: t is "aabbb" which its length is 5. - - ## Solutions - ### **Python3** @@ -41,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md index 8b81ac821a1fc..e296ff43193d7 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) ## 题目描述 +

    编写一个程序,找到两个单链表相交的起始节点。

    @@ -57,15 +58,14 @@
  • 程序尽量满足 O(n) 时间复杂度,且仅用 O(1) 内存。
  • - - ## 解法 - + ### **Python3** + ```python @@ -73,6 +73,7 @@ ``` ### **Java** + ```java @@ -80,8 +81,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md b/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md index 9fbe09a1c110b..10f91e6292613 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md) ## Description -

    Write a program to find the node at which the intersection of two singly linked lists begins.

    - +

    Write a program to find the node at which the intersection of two singly linked lists begins.

    For example, the following two linked lists:

    ![](./images/160_statement.png) - -

    begin to intersect at node c1.

    - -

     

    - -

    Example 1:

    ![](./images/160_example_1.png) @@ -33,12 +26,8 @@ Input Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. - -

     

    - -

    Example 2:

    ![](./images/160_example_2.png) @@ -53,12 +42,8 @@ - -

     

    - -

    Example 3:

    ![](./images/160_example_3.png) @@ -75,16 +60,10 @@ - -

     

    - -

    Notes:

    - -
    • If the two linked lists have no intersection at all, return null.
    • The linked lists must retain their original structure after the function returns.
    • @@ -92,12 +71,8 @@
    • Your code should preferably run in O(n) time and use only O(1) memory.
    - - - ## Solutions - ### **Python3** @@ -113,8 +88,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js b/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js index 85fa7ca7bdbc1..fb3af0ee88f41 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js @@ -1,45 +1,46 @@ -var getIntersectionNode2 = function(headA, headB) { +var getIntersectionNode2 = function (headA, headB) { if (!headA || !headB) { - return null + return null; } - let q = headA, p = headB - let lengthA = 1 - let lengthB = 1 - while(q.next) { - q = q.next - lengthA++ + let q = headA, + p = headB; + let lengthA = 1; + let lengthB = 1; + while (q.next) { + q = q.next; + lengthA++; } while (p.next) { - p = p.next - lengthB++ + p = p.next; + lengthB++; } if (q !== p) { - return null + return null; } - q = headA, p = headB + (q = headA), (p = headB); if (lengthA > lengthB) { for (let i = 0; i < lengthA - lengthB; i++) { - q = q.next + q = q.next; } } else { for (let i = 0; i < lengthB - lengthA; i++) { - p = p.next + p = p.next; } } while (q !== p && q !== null) { - q = q.next - p = p.next + q = q.next; + p = p.next; } - return q + return q; }; -var getIntersectionNode = function(headA, headB) { +var getIntersectionNode = function (headA, headB) { let p1 = headA; - let p2 = headB; - while (p1 != p2) { - p1 = p1 ? p1.next : headB; - p2 = p2 ? p2.next : headA; - } - return p1; -} \ No newline at end of file + let p2 = headB; + while (p1 != p2) { + p1 = p1 ? p1.next : headB; + p2 = p2 ? p2.next : headA; + } + return p1; +}; diff --git a/solution/0100-0199/0161.One Edit Distance/README.md b/solution/0100-0199/0161.One Edit Distance/README.md index 088fb6e7aa7d9..1b627775d4118 100644 --- a/solution/0100-0199/0161.One Edit Distance/README.md +++ b/solution/0100-0199/0161.One Edit Distance/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md) ## 题目描述 +

    给定两个字符串 s t,判断他们的编辑距离是否为 1。

    @@ -35,15 +36,14 @@ 输出: true 解释: 可以将字符串 s 中的 '0' 替换为 '1' 来得到 t。 - - ## 解法 - + ### **Python3** + ```python @@ -51,6 +51,7 @@ ``` ### **Java** + ```java @@ -58,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0161.One Edit Distance/README_EN.md b/solution/0100-0199/0161.One Edit Distance/README_EN.md index 18766f11cbae1..3a1f8c60ae2c8 100644 --- a/solution/0100-0199/0161.One Edit Distance/README_EN.md +++ b/solution/0100-0199/0161.One Edit Distance/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0161.One%20Edit%20Distance/README.md) ## Description +

    Given two strings s and t, determine if they are both one edit distance apart.

    Note: 

    @@ -37,11 +38,8 @@ Output: true Explanation: We can replace '0' with '1' to get t. - - ## Solutions - ### **Python3** @@ -57,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0162.Find Peak Element/README.md b/solution/0100-0199/0162.Find Peak Element/README.md index 96054d3f4c26e..dbc2a35c61950 100644 --- a/solution/0100-0199/0162.Find Peak Element/README.md +++ b/solution/0100-0199/0162.Find Peak Element/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md) ## 题目描述 +

    峰值元素是指其值大于左右相邻值的元素。

    @@ -30,15 +31,14 @@

    你的解法应该是 O(logN) 时间复杂度的。

    - - ## 解法 - + ### **Python3** + ```python @@ -46,6 +46,7 @@ ``` ### **Java** + ```java @@ -53,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0162.Find Peak Element/README_EN.md b/solution/0100-0199/0162.Find Peak Element/README_EN.md index 063fd7fb35953..af3c34a0561b8 100644 --- a/solution/0100-0199/0162.Find Peak Element/README_EN.md +++ b/solution/0100-0199/0162.Find Peak Element/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0162.Find%20Peak%20Element/README.md) ## Description -

    A peak element is an element that is greater than its neighbors.

    - +

    A peak element is an element that is greater than its neighbors.

    Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.

    - -

    The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

    - -

    You may imagine that nums[-1] = nums[n] = -∞.

    - -

    Example 1:

    - -
     
     Input: nums = [1,2,3,1]
    @@ -31,12 +22,8 @@
     
     Explanation: 3 is a peak element and your function should return the index number 2.
    - -

    Example 2:

    - -
     
     Input: nums = [1,2,1,3,5,6,4]
    @@ -49,20 +36,12 @@
     
     
    - -

    Note:

    - -

    Your solution should be in logarithmic complexity.

    - - - ## Solutions - ### **Python3** @@ -78,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0163.Missing Ranges/README.md b/solution/0100-0199/0163.Missing Ranges/README.md index 9cef25d7a57cc..b405ba8357e0e 100644 --- a/solution/0100-0199/0163.Missing Ranges/README.md +++ b/solution/0100-0199/0163.Missing Ranges/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md) ## 题目描述 +

    给定一个排序的整数数组 nums ,其中元素的范围在 闭区间 [lower, upper] 当中,返回不包含在数组中的缺失区间。

    @@ -12,15 +13,14 @@ 输出: ["2", "4->49", "51->74", "76->99"] - - ## 解法 - + ### **Python3** + ```python @@ -28,6 +28,7 @@ ``` ### **Java** + ```java @@ -35,8 +36,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0163.Missing Ranges/README_EN.md b/solution/0100-0199/0163.Missing Ranges/README_EN.md index ebab1bfdc1c99..6aa7c1351751c 100644 --- a/solution/0100-0199/0163.Missing Ranges/README_EN.md +++ b/solution/0100-0199/0163.Missing Ranges/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0163.Missing%20Ranges/README.md) ## Description +

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges.

    Example:

    @@ -12,11 +13,8 @@ Output: ["2", "4->49", "51->74", "76->99"] - - ## Solutions - ### **Python3** @@ -32,8 +30,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0164.Maximum Gap/README.md b/solution/0100-0199/0164.Maximum Gap/README.md index dedde8c673694..32fb75af6aa80 100644 --- a/solution/0100-0199/0164.Maximum Gap/README.md +++ b/solution/0100-0199/0164.Maximum Gap/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md) ## 题目描述 +

    给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。

    @@ -27,15 +28,14 @@
  • 请尝试在线性时间复杂度和空间复杂度的条件下解决此问题。
  • - - ## 解法 - + ### **Python3** + ```python @@ -43,6 +43,7 @@ ``` ### **Java** + ```java @@ -50,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0164.Maximum Gap/README_EN.md b/solution/0100-0199/0164.Maximum Gap/README_EN.md index 1ebf70bb243d2..0b4d2b9ca8794 100644 --- a/solution/0100-0199/0164.Maximum Gap/README_EN.md +++ b/solution/0100-0199/0164.Maximum Gap/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0164.Maximum%20Gap/README.md) ## Description -

    Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

    - +

    Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

    Return 0 if the array contains less than 2 elements.

    - -

    Example 1:

    - -
     
     Input: [3,6,9,1]
    @@ -25,12 +20,8 @@
     
                  (3,6) or (6,9) has the maximum difference 3.
    - -

    Example 2:

    - -
     
     Input: [10]
    @@ -39,26 +30,18 @@
     
     Explanation: The array contains less than 2 elements, therefore return 0.
    - -

    Note:

    - -
      -
    • You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
    • +
    • You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
    • -
    • Try to solve it in linear time/space.
    • +
    • Try to solve it in linear time/space.
    - - - ## Solutions - ### **Python3** @@ -74,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0165.Compare Version Numbers/README.md b/solution/0100-0199/0165.Compare Version Numbers/README.md index 458eef8ab3d9a..c0697f6cf90e4 100644 --- a/solution/0100-0199/0165.Compare Version Numbers/README.md +++ b/solution/0100-0199/0165.Compare Version Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md) ## 题目描述 +

    比较两个版本号 version1 version2
    如果 version1 version2 返回 1,如果 version1 version2 返回 -1, 除此之外返回 0

    @@ -52,15 +53,14 @@
  • 版本字符串不以点开始或结束,并且其中不会有两个连续的点。
  • - - ## 解法 - + ### **Python3** + ```python @@ -68,6 +68,7 @@ ``` ### **Java** + ```java @@ -75,8 +76,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0165.Compare Version Numbers/README_EN.md b/solution/0100-0199/0165.Compare Version Numbers/README_EN.md index f3713172229bd..1047540f1ec1a 100644 --- a/solution/0100-0199/0165.Compare Version Numbers/README_EN.md +++ b/solution/0100-0199/0165.Compare Version Numbers/README_EN.md @@ -3,12 +3,11 @@ [中文文档](/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md) ## Description +

    Compare two version numbers version1 and version2.
    If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.

    - -

    You may assume that the version strings are non-empty and contain only digits and the . character.

    The . character does not represent a decimal point and is used to separate number sequences.

    @@ -17,12 +16,8 @@ If version1 > version2 return 1;&

    You may assume the default revision number for each level of a version number to be 0. For example, version number 3.4 has a revision number of 3 and 4 for its first and second level revision number. Its third and fourth level revision number are both 0.

    - -

     

    - -

    Example 1:

    @@ -31,8 +26,6 @@ If version1 > version2 return 1;&
     
     Output: -1
    - -

    Example 2:

    @@ -41,8 +34,6 @@ If version1 > version2 return 1;&
     
     Output: 1
    - -

    Example 3:

    @@ -51,8 +42,6 @@ If version1 > version2 return 1;&
     
     Output: -1
    - -

    Example 4:

    @@ -63,8 +52,6 @@ If version1 > version2 return 1;&
     
     Explanation: Ignoring leading zeroes, both “01” and “001" represent the same number “1”
    - -

    Example 5:

    @@ -75,12 +62,8 @@ If version1 > version2 return 1;&
     
     Explanation: The first version number does not have a third level revision number, which means its third level revision number is default to "0"
    - -

     

    - -

    Note:

      @@ -91,10 +74,8 @@ If version1 > version2 return 1;&
    - ## Solutions - ### **Python3** @@ -110,8 +91,9 @@ If version1 > version2 return 1;& ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md index 96dfc475b2a59..699aceb90abe2 100644 --- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md +++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md) ## 题目描述 +

    给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数。

    @@ -25,15 +26,14 @@ 输出: "0.(6)" - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md index ea42108b023e1..89ea0c1fc53fa 100644 --- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md +++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md) ## Description -

    Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

    - +

    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.

    - -

    Example 1:

    - -
     
     Input: numerator = 1, denominator = 2
    @@ -23,24 +18,16 @@
     
     
    - -

    Example 2:

    - -
     
     Input: numerator = 2, denominator = 1
     
     Output: "2"
    - -

    Example 3:

    - -
     
     Input: numerator = 2, denominator = 3
    @@ -49,12 +36,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -70,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md index 8786fdc0aef66..02bab717e57b5 100644 --- a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md +++ b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md) ## 题目描述 +

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。

    @@ -21,15 +22,14 @@ 输出: [1,2] 解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md index 33d337e94e60a..93e10121e9e9d 100644 --- a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md +++ b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md) ## Description -

    Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

    - +

    Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

    The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

    - -

    Note:

    - -
      -
    • Your returned answers (both index1 and index2) are not zero-based.
    • +
    • Your returned answers (both index1 and index2) are not zero-based.
    • -
    • You may assume that each input would have exactly one solution and you may not use the same element twice.
    • +
    • You may assume that each input would have exactly one solution and you may not use the same element twice.
    - -

    Example:

    - -
     
     Input: numbers = [2,7,11,15], target = 9
    @@ -37,12 +28,8 @@
     
     Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.
    - - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README.md b/solution/0100-0199/0168.Excel Sheet Column Title/README.md index a3c596748e4ab..e0bdcb12f4d74 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README.md @@ -1,8 +1,9 @@ -# [168. Excel表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title) +# [168. Excel 表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title) [English Version](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md) ## 题目描述 +

    给定一个正整数,返回它在 Excel 表中相对应的列名称。

    @@ -36,15 +37,14 @@ 输出: "ZY" - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ ``` ### **Java** + ```java @@ -59,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md index 5d2ed514ed4e9..852b873e441b9 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md) ## Description -

    Given a positive integer, return its corresponding column title as appear in an Excel sheet.

    - +

    Given a positive integer, return its corresponding column title as appear in an Excel sheet.

    For example:

    - -
     
         1 -> A
    @@ -31,12 +28,8 @@
     
     
    - -

    Example 1:

    - -
     
     Input: 1
    @@ -45,12 +38,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: 28
    @@ -59,12 +48,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: 701
    @@ -73,10 +58,8 @@
     
     
    - ## Solutions - ### **Python3** @@ -92,8 +75,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0169.Majority Element/README.md b/solution/0100-0199/0169.Majority Element/README.md index 33de71d6dea40..e957b1bf9c1a3 100644 --- a/solution/0100-0199/0169.Majority Element/README.md +++ b/solution/0100-0199/0169.Majority Element/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0169.Majority%20Element/README_EN.md) ## 题目描述 +

    给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素。

    @@ -19,15 +20,14 @@ 输出: 2 - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0169.Majority Element/README_EN.md b/solution/0100-0199/0169.Majority Element/README_EN.md index f14ba258ec417..9977fd088c891 100644 --- a/solution/0100-0199/0169.Majority Element/README_EN.md +++ b/solution/0100-0199/0169.Majority Element/README_EN.md @@ -3,30 +3,21 @@ [中文文档](/solution/0100-0199/0169.Majority%20Element/README.md) ## Description -

    Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

    - +

    Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

    You may assume that the array is non-empty and the majority element always exist in the array.

    - -

    Example 1:

    - -
     
     Input: [3,2,3]
     
     Output: 3
    - -

    Example 2:

    - -
     
     Input: [2,2,1,1,1,2,2]
    @@ -35,12 +26,8 @@
     
     
    - - - ## Solutions - ### **Python3** @@ -56,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md index 7da2de65848b7..346dea31880bb 100644 --- a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md +++ b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md) ## 题目描述 +

    设计并实现一个 TwoSum 的类,使该类需要支持 add 和 find 的操作。

    @@ -22,15 +23,14 @@ find(7) -> false find(3) -> true find(6) -> false - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ find(6) -> false ``` ### **Java** + ```java @@ -45,8 +46,9 @@ find(6) -> false ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md b/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md index 13dcef6f1138e..b913326ce3b4e 100644 --- a/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md +++ b/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README.md) ## Description +

    Design and implement a TwoSum class. It should support the following operations: add and find.

    add - Add the number to an internal data structure.
    @@ -23,11 +24,8 @@ add(3); add(1); add(2); find(3) -> true find(6) -> false - - ## Solutions - ### **Python3** @@ -43,8 +41,9 @@ find(6) -> false ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0171.Excel Sheet Column Number/README.md b/solution/0100-0199/0171.Excel Sheet Column Number/README.md index 18216072f3f7e..c9b40cdd50e59 100644 --- a/solution/0100-0199/0171.Excel Sheet Column Number/README.md +++ b/solution/0100-0199/0171.Excel Sheet Column Number/README.md @@ -1,8 +1,9 @@ -# [171. Excel表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number) +# [171. Excel 表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number) [English Version](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md) ## 题目描述 +

    给定一个Excel表格中的列名称,返回其相应的列序号。

    @@ -38,15 +39,14 @@

    致谢:
    特别感谢 @ts 添加此问题并创建所有测试用例。

    - - ## 解法 - + ### **Python3** + ```python @@ -54,6 +54,7 @@ ``` ### **Java** + ```java @@ -61,8 +62,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md b/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md index e3782b98e47b9..4f0920b121551 100644 --- a/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md +++ b/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md) ## Description -

    Given a column title as appear in an Excel sheet, return its corresponding column number.

    - +

    Given a column title as appear in an Excel sheet, return its corresponding column number.

    For example:

    - -
     
         A -> 1
    @@ -31,12 +28,8 @@
     
     
    - -

    Example 1:

    - -
     
     Input: "A"
    @@ -45,12 +38,8 @@
     
     
    - -

    Example 2:

    - -
     
     Input: "AB"
    @@ -59,12 +48,8 @@
     
     
    - -

    Example 3:

    - -
     
     Input: "ZY"
    @@ -73,10 +58,8 @@
     
     
    - ## Solutions - ### **Python3** @@ -92,8 +75,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md index 1aa9641ca98ff..bca3869a60238 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md) ## 题目描述 +

    给定一个整数 n,返回 n! 结果尾数中零的数量。

    @@ -20,15 +21,14 @@

    说明: 你算法的时间复杂度应为 O(log n) 

    - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md index 2c580b3ff463c..fd6ec1a2434c5 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md) ## Description -

    Given an integer n, return the number of trailing zeroes in n!.

    - +

    Given an integer n, return the number of trailing zeroes in n!.

    Example 1:

    - -
     
     Input: 3
    @@ -19,12 +16,8 @@
     
     Explanation: 3! = 6, no trailing zero.
    - -

    Example 2:

    - -
     
     Input: 5
    @@ -33,16 +26,10 @@
     
     Explanation: 5! = 120, one trailing zero.
    - -

    Note: Your solution should be in logarithmic time complexity.

    - - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md index ba82513247428..f5f98d8de4e4f 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md) ## 题目描述 +

    实现一个二叉搜索树迭代器。你将使用二叉搜索树的根节点初始化迭代器。

    @@ -34,15 +35,14 @@ iterator.hasNext(); // 返回 false
  • 你可以假设 next() 调用总是有效的,也就是说,当调用 next() 时,BST 中至少存在一个下一个最小的数。
  • - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ iterator.hasNext(); // 返回 false ``` ### **Java** + ```java @@ -57,8 +58,9 @@ iterator.hasNext(); // 返回 false ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md index d97be98a65f82..45e8106776964 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md @@ -3,32 +3,21 @@ [中文文档](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md) ## Description -

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.

    - +

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.

    Calling next() will return the next smallest number in the BST.

    - -

     

    - -
    - -

    Example:

    - - ![](./images/bst-tree.png) - -
     
     BSTIterator iterator = new BSTIterator(root);
    @@ -53,27 +42,17 @@ iterator.hasNext(); // return false
     
     
    - -

     

    - -

    Note:

    - -
    • next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tree.
    • You may assume that next() call will always be valid, that is, there will be at least a next smallest number in the BST when next() is called.
    - - - ## Solutions - ### **Python3** @@ -89,8 +68,9 @@ iterator.hasNext(); // return false ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0174.Dungeon Game/README.md b/solution/0100-0199/0174.Dungeon Game/README.md index 7441e4222d73d..7ebd768fff8f3 100644 --- a/solution/0100-0199/0174.Dungeon Game/README.md +++ b/solution/0100-0199/0174.Dungeon Game/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0174.Dungeon%20Game/README_EN.md) ## 题目描述 + - -

    一些恶魔抓住了公主(P)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。

    - -

    骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以下,他会立即死亡。

    - -

    有些房间由恶魔守卫,因此骑士在进入这些房间时会失去健康点数(若房间里的值为负整数,则表示骑士将损失健康点数);其他房间要么是空的(房间里的值为 0),要么包含增加骑士健康点数的魔法球(若房间里的值为正整数,则表示骑士将增加健康点数)。

    - -

    为了尽快到达公主,骑士决定每次只向右或向下移动一步。

    - -

     

    - -

    编写一个函数来计算确保骑士能够拯救到公主所需的最低初始健康点数。

    - -

    例如,考虑到如下布局的地下城,如果骑士遵循最佳路径 右 -> 右 -> 下 -> 下,则骑士的初始健康点数至少为 7

    - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
    -2 (K)-2 (K)-3-333
    -5-5-10-1011
    10103030-5 (P)-5 (P)
    @@ -96,36 +81,30 @@ table.dungeon, .dungeon th, .dungeon td { 10 30 5P--> - -

     

    - -

    说明:

    - -
      -
    • +
    • -

      骑士的健康点数没有上限。

      +

      骑士的健康点数没有上限。

      -
    • + -
    • 任何房间都可能对骑士的健康点数造成威胁,也可能增加骑士的健康点数,包括骑士进入的左上角房间以及公主被监禁的右下角房间。
    • +
    • 任何房间都可能对骑士的健康点数造成威胁,也可能增加骑士的健康点数,包括骑士进入的左上角房间以及公主被监禁的右下角房间。
    - ## 解法 - + ### **Python3** + ```python @@ -133,6 +112,7 @@ table.dungeon, .dungeon th, .dungeon td { ``` ### **Java** + ```java @@ -140,8 +120,9 @@ table.dungeon, .dungeon th, .dungeon td { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0174.Dungeon Game/README_EN.md b/solution/0100-0199/0174.Dungeon Game/README_EN.md index 5f5feb3f18885..f83b65f283a20 100644 --- a/solution/0100-0199/0174.Dungeon Game/README_EN.md +++ b/solution/0100-0199/0174.Dungeon Game/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0174.Dungeon%20Game/README.md) ## Description +