├── .gitignore ├── 0001-0500 ├── 0001.Two Sum.c ├── 0001.Two Sum.java ├── 0001.Two Sum.py ├── 0002.Add Two Numbers.c ├── 0002.Add Two Numbers.py ├── 0003.Longest Substring Without Repeating Characters.2.c ├── 0003.Longest Substring Without Repeating Characters.2.py ├── 0003.Longest Substring Without Repeating Characters.c ├── 0003.Longest Substring Without Repeating Characters.py ├── 0004.Median of Two Sorted Arrays.c ├── 0005.Longest Palindromic Substring.c ├── 0005.Longest Palindromic Substring.java ├── 0005.Longest Palindromic Substring.py ├── 0005.Longest Palindromic Substring.ts ├── 0006.Zigzag Conversion.c ├── 0007.Reverse Integer.c ├── 0008.String to Integer (atoi).java ├── 0009.Palindrome Number.2.c ├── 0009.Palindrome Number.c ├── 0010.Regular Expression Matching.java ├── 0011.Container With Most Water.py ├── 0012.Integer to Roman.java ├── 0013.Roman to Integer.cpp ├── 0014.Longest Common Prefix.py ├── 0015.3Sum.2.py ├── 0015.3Sum.py ├── 0016.3Sum Closest.py ├── 0017.Letter Combinations of a Phone Number.py ├── 0018.4Sum.py ├── 0019.Remove Nth Node From End of List.2.c ├── 0019.Remove Nth Node From End of List.c ├── 0020.Valid Parentheses.cpp ├── 0021.Merge Two Sorted Lists.py ├── 0022.Generate Parentheses.py ├── 0023.Merge k Sorted Lists.c ├── 0023.Merge k Sorted Lists.py ├── 0024.Swap Nodes in Pairs.c ├── 0025.Reverse Nodes in k-Group.java ├── 0026.Remove Duplicates from Sorted Array.1.py ├── 0026.Remove Duplicates from Sorted Array.2.py ├── 0026.Remove Duplicates from Sorted Array.java ├── 0027.Remove Element.2.py ├── 0027.Remove Element.py ├── 0028.Find the Index of the First Occurrence in a String.(KMP).py ├── 0029.Divide Two Integers.java ├── 0030.Substring with Concatenation of All Words.py ├── 0031.Next Permutation.py ├── 0032.Longest Valid Parentheses.py ├── 0033.Search in Rotated Sorted Array.java ├── 0033.Search in Rotated Sorted Array.rb ├── 0034.Find First and Last Position of Element in Sorted Array.java ├── 0034.Find First and Last Position of Element in Sorted Array.py ├── 0035.Search Insert Position.cpp ├── 0035.Search Insert Position.rb ├── 0036.Valid Sudoku.py ├── 0037.Sudoku Solver.2.(bitwise and prune).java ├── 0037.Sudoku Solver.java ├── 0037.Sudoku Solver.py ├── 0038.Count and Say.java ├── 0038.Count and Say.py ├── 0039.Combination Sum.(dynamic programming).py ├── 0039.Combination Sum.py ├── 0040.Combination Sum II.py ├── 0041.First Missing Positive.py ├── 0041.First Missing Positive.rb ├── 0042.Trapping Rain Water.2.py ├── 0042.Trapping Rain Water.py ├── 0043.Multiply Strings.py ├── 0044.Wildcard Matching.2.py ├── 0044.Wildcard Matching.py ├── 0045.Jump Game II.java ├── 0045.Jump Game II.py ├── 0046.Permutations.py ├── 0047.Permutations II.py ├── 0048.Rotate Image.c ├── 0048.Rotate Image.py ├── 0049.Group Anagrams.py ├── 0049.Group Anagrams.rb ├── 0050.Pow(x, n).c ├── 0050.Pow(x, n).cpp ├── 0051.N-Queens.py ├── 0052.N-Queens II.py ├── 0053.Maximum Subarray.cpp ├── 0053.Maximum Subarray.py ├── 0053.Maximum Subarray.rb ├── 0054.Spiral Matrix.java ├── 0054.Spiral Matrix.py ├── 0055.Jump Game.2.py ├── 0055.Jump Game.py ├── 0055.Jump Game.rb ├── 0056.Merge Intervals.java ├── 0056.Merge Intervals.py ├── 0057.Insert Interval.py ├── 0058.Length of Last Word.py ├── 0059.Spiral Matrix II.py ├── 0060.Permutation Sequence.rb ├── 0061.Rotate List.java ├── 0062.Unique Paths.2.(iterative addition).py ├── 0062.Unique Paths.3.(math).py ├── 0062.Unique Paths.py ├── 0062.Unique Paths.rb ├── 0063.Unique Paths II.java ├── 0064.Minimum Path Sum.java ├── 0064.Minimum Path Sum.py ├── 0064.Minimum Path Sum.rb ├── 0065.Valid Number.py ├── 0066.Plus One.py ├── 0066.Plus One.rb ├── 0067.Add Binary.py ├── 0068.Text Justification.java ├── 0069.Sqrt(x).cpp ├── 0070.Climbing Stairs.java ├── 0070.Climbing Stairs.py ├── 0071.Simplify Path.py ├── 0072.Edit Distance.py ├── 0072.Edit Distance.rb ├── 0073.Set Matrix Zeroes.cpp ├── 0074.Search a 2D Matrix.c ├── 0074.Search a 2D Matrix.py ├── 0075.Sort Colors.py ├── 0075.Sort Colors.rb ├── 0076.Minimum Window Substring.2.py ├── 0076.Minimum Window Substring.py ├── 0077.Combinations.java ├── 0078.Subsets.py ├── 0078.Subsets.rb ├── 0079.Word Search.java ├── 0080.Remove Duplicates from Sorted Array II.java ├── 0080.Remove Duplicates from Sorted Array II.py ├── 0081.Search in Rotated Sorted Array II.py ├── 0082.Remove Duplicates from Sorted List II.java ├── 0083.Remove Duplicates from Sorted List.java ├── 0084.Largest Rectangle in Histogram.java ├── 0084.Largest Rectangle in Histogram.py ├── 0085.Maximal Rectangle.2.py ├── 0085.Maximal Rectangle.py ├── 0086.Partition List.java ├── 0087.Scramble String.py ├── 0088.Merge Sorted Array.c ├── 0088.Merge Sorted Array.py ├── 0089.Gray Code.2.py ├── 0089.Gray Code.3.py ├── 0089.Gray Code.java ├── 0089.Gray Code.py ├── 0090.Subsets II.py ├── 0090.Subsets II.rb ├── 0091.Decode Ways.cpp ├── 0092.Reverse Linked List II.java ├── 0093.Restore IP Addresses.java ├── 0094.Binary Tree Inorder Traversal.py ├── 0095.Unique Binary Search Trees II.java ├── 0095.Unique Binary Search Trees II.py ├── 0096.Unique Binary Search Trees.java ├── 0096.Unique Binary Search Trees.py ├── 0096.Unique Binary Search Trees.rb ├── 0097.Interleaving String.java ├── 0098.Validate Binary Search Tree.java ├── 0099.Recover Binary Search Tree.py ├── 0100.Same Tree.java ├── 0100.Same Tree.rb ├── 0101.Symmetric Tree.java ├── 0102.Binary Tree Level Order Traversal.java ├── 0103.Binary Tree Zigzag Level Order Traversal.java ├── 0104.Maximum Depth of Binary Tree.java ├── 0105.Construct Binary Tree from Preorder and Inorder Traversal.java ├── 0105.Construct Binary Tree from Preorder and Inorder Traversal.py ├── 0106.Construct Binary Tree from Inorder and Postorder Traversal.py ├── 0107.Binary Tree Level Order Traversal II.java ├── 0107.Binary Tree Level Order Traversal II.rb ├── 0108.Convert Sorted Array to Binary Search Tree.py ├── 0109.Convert Sorted List to Binary Search Tree.py ├── 0110.Balanced Binary Tree.c ├── 0111.Minimum Depth of Binary Tree.cpp ├── 0112.Path Sum.c ├── 0113.Path Sum II.java ├── 0114.Flatten Binary Tree to Linked List.java ├── 0115.Distinct Subsequences.py ├── 0116.Populating Next Right Pointers in Each Node.java ├── 0117.Populating Next Right Pointers in Each Node II.java ├── 0118.Pascal's Triangle.cpp ├── 0119.Pascal's Triangle II.cpp ├── 0119.Pascal's Triangle II.py ├── 0120.Triangle.py ├── 0121.Best Time to Buy and Sell Stock.java ├── 0122.Best Time to Buy and Sell Stock II.rb ├── 0123.Best Time to Buy and Sell Stock III.py ├── 0124.Binary Tree Maximum Path Sum.2.rb ├── 0124.Binary Tree Maximum Path Sum.java ├── 0124.Binary Tree Maximum Path Sum.py ├── 0124.Binary Tree Maximum Path Sum.rb ├── 0125.Valid Palindrome.java ├── 0125.Valid Palindrome.rb ├── 0126.Word Ladder II.py ├── 0127.Word Ladder.py ├── 0128.Longest Consecutive Sequence.java ├── 0129.Sum Root to Leaf Numbers.py ├── 0129.Sum Root to Leaf Numbers.rb ├── 0130.Surrounded Regions.java ├── 0130.Surrounded Regions.rb ├── 0131.Palindrome Partitioning.py ├── 0132.Palindrome Partitioning II.py ├── 0133.Clone Graph.py ├── 0134.Gas Station.py ├── 0135.Candy.c ├── 0136.Single Number.java ├── 0136.Single Number.py ├── 0136.Single Number.rb ├── 0137.Single Number II.2.(bitwise).java ├── 0137.Single Number II.java ├── 0137.Single Number II.rb ├── 0138.Copy List with Random Pointer.2.(hashmap in one run, overflow).java ├── 0138.Copy List with Random Pointer.java ├── 0139.Word Break.cpp ├── 0140.Word Break II.2.(check by word size).java ├── 0140.Word Break II.java ├── 0141.Linked List Cycle.cpp ├── 0141.Linked List Cycle.java ├── 0142.Linked List Cycle II.js ├── 0143.Reorder List.py ├── 0144.Binary Tree Preorder Traversal.ts ├── 0145.Binary Tree Postorder Traversal.java ├── 0146.LRU Cache.java ├── 0146.LRU Cache.rb ├── 0147.Insertion Sort List.java ├── 0148.Sort List.cpp ├── 0149.Max Points on a Line.py ├── 0150.Evaluate Reverse Polish Notation.java ├── 0150.Evaluate Reverse Polish Notation.py ├── 0151.Reverse Words in a String.c ├── 0152.Maximum Product Subarray.py ├── 0153.Find Minimum in Rotated Sorted Array.java ├── 0154.Find Minimum in Rotated Sorted Array II.java ├── 0155.Min Stack.java ├── 0155.Min Stack.rb ├── 0157.Read N Characters Given Read4.c ├── 0160.Intersection of Two Linked Lists.cpp ├── 0162.Find Peak Element.py ├── 0164.Maximum Gap.py ├── 0165.Compare Version Numbers.java ├── 0166.Fraction to Recurring Decimal.py ├── 0167.Two Sum II - Input Array Is Sorted.java ├── 0168.Excel Sheet Column Title.java ├── 0168.Excel Sheet Column Title.py ├── 0169.Majority Element.c ├── 0169.Majority Element.rb ├── 0171.Excel Sheet Column Number.java ├── 0171.Excel Sheet Column Number.py ├── 0172.Factorial Trailing Zeroes.java ├── 0172.Factorial Trailing Zeroes.py ├── 0173.Binary Search Tree Iterator.java ├── 0173.Binary Search Tree Iterator.py ├── 0174.Dungeon Game.py ├── 0175.Combine Two Tables.sql ├── 0179.Largest Number.py ├── 0181.Employees Earning More Than Their Managers.sql ├── 0182.Duplicate Emails.sql ├── 0183.Customers Who Never Order.sql ├── 0187.Repeated DNA Sequences.java ├── 0188.Best Time to Buy and Sell Stock IV.java ├── 0189.Rotate Array.java ├── 0190.Reverse Bits.cpp ├── 0190.Reverse Bits.java ├── 0191.Number of 1 Bits.cpp ├── 0192.Word Frequency.sh ├── 0193.Valid Phone Numbers.sh ├── 0194.Transpose File.sh ├── 0195.Tenth Line.sh ├── 0198.House Robber.java ├── 0199.Binary Tree Right Side View.c ├── 0200.Number of Islands.c ├── 0200.Number of Islands.py ├── 0200.Number of Islands.rb ├── 0201.Bitwise AND of Numbers Range.rb ├── 0202.Happy Number.cpp ├── 0202.Happy Number.rb ├── 0203.Remove Linked List Elements.c ├── 0203.Remove Linked List Elements.rb ├── 0204.Count Primes.(linear sieve).py ├── 0205.Isomorphic Strings.cpp ├── 0206.Reverse Linked List.cpp ├── 0207.Course Schedule.py ├── 0207.Course Schedule.rb ├── 0208.Implement Trie (Prefix Tree).rb ├── 0209.Minimum Size Subarray Sum.java ├── 0210.Course Schedule II.java ├── 0210.Course Schedule II.py ├── 0211.Design Add and Search Words Data Structure.py ├── 0212.Word Search II.java ├── 0212.Word Search II.py ├── 0212.Word Search II.rb ├── 0213.House Robber II.py ├── 0215.Kth Largest Element in an Array.java ├── 0215.Kth Largest Element in an Array.py ├── 0216.Combination Sum III.java ├── 0217.Contains Duplicate.py ├── 0218.The Skyline Problem.java ├── 0219.Contains Duplicate II.c ├── 0219.Contains Duplicate II.py ├── 0220.Contains Duplicate III.py ├── 0221.Maximal Square.c ├── 0221.Maximal Square.rb ├── 0222.Count Complete Tree Nodes.java ├── 0222.Count Complete Tree Nodes.rb ├── 0223.Rectangle Area.c ├── 0224.Basic Calculator.py ├── 0225.Implement Stack using Queues.java ├── 0226.Invert Binary Tree.c ├── 0226.Invert Binary Tree.py ├── 0226.Invert Binary Tree.rb ├── 0227.Basic Calculator II.py ├── 0228.Summary Ranges.java ├── 0229.Majority Element II.py ├── 0230.Kth Smallest Element in a BST.rb ├── 0231.Power of Two.java ├── 0231.Power of Two.py ├── 0231.Power of Two.rb ├── 0232.Implement Queue using Stacks.java ├── 0233.Number of Digit One.c ├── 0234.Palindrome Linked List.java ├── 0235.Lowest Common Ancestor of a Binary Search Tree.c ├── 0236.Lowest Common Ancestor of a Binary Tree.cpp ├── 0237.Delete Node in a Linked List.cpp ├── 0237.Delete Node in a Linked List.rb ├── 0238.Product of Array Except Self.cpp ├── 0238.Product of Array Except Self.py ├── 0238.Product of Array Except Self.rb ├── 0239.Sliding Window Maximum.java ├── 0239.Sliding Window Maximum.py ├── 0240.Search a 2D Matrix II.c ├── 0240.Search a 2D Matrix II.java ├── 0241.Different Ways to Add Parentheses.java ├── 0242.Valid Anagram.c ├── 0246.Strobogrammatic Number.ts ├── 0252.Meeting Rooms.ts ├── 0257.Binary Tree Paths.py ├── 0258.Add Digits.py ├── 0260.Single Number III.py ├── 0260.Single Number III.ts ├── 0263.Ugly Number.c ├── 0263.Ugly Number.py ├── 0264.Ugly Number II.rb ├── 0268.Missing Number.js ├── 0273.Integer to English Words.java ├── 0274.H-Index.py ├── 0275.H-Index II.rb ├── 0278.First Bad Version.rb ├── 0279.Perfect Squares.rb ├── 0282.Expression Add Operators.py ├── 0283.Move Zeroes.2.py ├── 0283.Move Zeroes.py ├── 0283.Move Zeroes.rb ├── 0284.Peeking Iterator.py ├── 0285.Inorder Successor in BST.py ├── 0287.Find the Duplicate Number.rb ├── 0289.Game of Life.c ├── 0290.Word Pattern.py ├── 0290.Word Pattern.rb ├── 0291.Word Pattern II.py ├── 0292.Nim Game.c ├── 0295.Find Median from Data Stream.py ├── 0297.Serialize and Deserialize Binary Tree.js ├── 0299.Bulls and Cows.py ├── 0300.Longest Increasing Subsequence.java ├── 0301.Remove Invalid Parentheses.ts ├── 0303.Range Sum Query - Immutable.cpp ├── 0303.Range Sum Query - Immutable.py ├── 0304.Range Sum Query 2D - Immutable.py ├── 0306.Additive Number.ts ├── 0307.Range Sum Query - Mutable.(BIT).java ├── 0307.Range Sum Query - Mutable.java ├── 0307.Range Sum Query - Mutable.py ├── 0309.Best Time to Buy and Sell Stock with Cooldown.py ├── 0310.Minimum Height Trees.2.(stack overflow).java ├── 0310.Minimum Height Trees.py ├── 0312.Burst Balloons.(lru_cache).py ├── 0312.Burst Balloons.1.(iterative).py ├── 0312.Burst Balloons.2.(recursive).py ├── 0312.Burst Balloons.c ├── 0313.Super Ugly Number.py ├── 0315.Count of Smaller Numbers After Self.java ├── 0316.Remove Duplicate Letters.py ├── 0318.Maximum Product of Word Lengths.py ├── 0319.Bulb Switcher.cpp ├── 0321.Create Maximum Number.py ├── 0322.Coin Change.java ├── 0322.Coin Change.py ├── 0324.Wiggle Sort II.py ├── 0326.Power of Three.cpp ├── 0327.Count of Range Sum.py ├── 0328.Odd Even Linked List.java ├── 0328.Odd Even Linked List.rb ├── 0329.Longest Increasing Path in a Matrix.java ├── 0329.Longest Increasing Path in a Matrix.py ├── 0330.Patching Array.c ├── 0331.Verify Preorder Serialization of a Binary Tree.java ├── 0332.Reconstruct Itinerary.rb ├── 0334.Increasing Triplet Subsequence.java ├── 0334.Increasing Triplet Subsequence.py ├── 0335.Self Crossing.ts ├── 0337.House Robber III.py ├── 0338.Counting Bits.2.py ├── 0338.Counting Bits.py ├── 0338.Counting Bits.rb ├── 0341.Flatten Nested List Iterator.java ├── 0342.Power of Four.2.py ├── 0342.Power of Four.py ├── 0343.Integer Break.java ├── 0344.Reverse String.c ├── 0345.Reverse Vowels of a String.c ├── 0345.Reverse Vowels of a String.py ├── 0347.Top K Frequent Elements.2.py ├── 0347.Top K Frequent Elements.py ├── 0349.Intersection of Two Arrays.cpp ├── 0349.Intersection of Two Arrays.py ├── 0350.Intersection of Two Arrays II.cpp ├── 0352.Data Stream as Disjoint Intervals.py ├── 0354.Russian Doll Envelopes.py ├── 0357.Count Numbers with Unique Digits.ts ├── 0359.Logger Rate Limiter.py ├── 0363.Max Sum of Rectangle No Larger Than K.py ├── 0365.Water and Jug Problem.py ├── 0367.Valid Perfect Square.rb ├── 0368.Largest Divisible Subset.py ├── 0368.Largest Divisible Subset.rb ├── 0371.Sum of Two Integers.c ├── 0372.Super Pow.ts ├── 0373.Find K Pairs with Smallest Sums.java ├── 0374.Guess Number Higher or Lower.cpp ├── 0374.Guess Number Higher or Lower.py ├── 0375.Guess Number Higher or Lower II.java ├── 0376.Wiggle Subsequence.java ├── 0377.Combination Sum IV.java ├── 0378.Kth Smallest Element in a Sorted Matrix.java ├── 0380.Insert Delete GetRandom O(1).rb ├── 0381.Insert Delete GetRandom O(1) - Duplicates allowed.py ├── 0381.Insert Delete GetRandom O(1) - Duplicates allowed.rb ├── 0382.Linked List Random Node.ts ├── 0383.Ransom Note.2.c ├── 0383.Ransom Note.c ├── 0383.Ransom Note.rb ├── 0384.Shuffle an Array.java ├── 0385.Mini Parser.ts ├── 0386.Lexicographical Numbers.ts ├── 0387.First Unique Character in a String.py ├── 0387.First Unique Character in a String.rb ├── 0388.Longest Absolute File Path.java ├── 0389.Find the Difference.cpp ├── 0389.Find the Difference.py ├── 0390.Elimination Game.py ├── 0391.Perfect Rectangle.ts ├── 0392.Is Subsequence.py ├── 0392.Is Subsequence.rb ├── 0393.UTF-8 Validation.py ├── 0394.Decode String.java ├── 0395.Longest Substring with At Least K Repeating Characters.py ├── 0396.Rotate Function.c ├── 0397.Integer Replacement.cpp ├── 0398.Random Pick Index.java ├── 0399.Evaluate Division.py ├── 0400.Nth Digit.ts ├── 0401.Binary Watch.py ├── 0402.Remove K Digits.java ├── 0402.Remove K Digits.js ├── 0402.Remove K Digits.py ├── 0403.Frog Jump.py ├── 0404.Sum of Left Leaves.cpp ├── 0405.Convert a Number to Hexadecimal.c ├── 0406.Queue Reconstruction by Height.py ├── 0406.Queue Reconstruction by Height.rb ├── 0407.Trapping Rain Water II.py ├── 0409.Longest Palindrome.cpp ├── 0410.Split Array Largest Sum.py ├── 0412.Fizz Buzz.java ├── 0412.Fizz Buzz.py ├── 0413.Arithmetic Slices.py ├── 0414.Third Maximum Number.cpp ├── 0415.Add Strings.cpp ├── 0416.Partition Equal Subset Sum.py ├── 0417.Pacific Atlantic Water Flow.py ├── 0419.Battleships in a Board.java ├── 0421.Maximum XOR of Two Numbers in an Array.py ├── 0423.Reconstruct Original Digits from English.ts ├── 0424.Longest Repeating Character Replacement.py ├── 0427.Construct Quad Tree.ts ├── 0429.N-ary Tree Level Order Traversal.ts ├── 0430.Flatten a Multilevel Doubly Linked List.java ├── 0432.All O`one Data Structure.java ├── 0433.Minimum Genetic Mutation.1.(Hash).java ├── 0433.Minimum Genetic Mutation.2.(Queue).java ├── 0434.Number of Segments in a String.ts ├── 0435.Non-overlapping Intervals.py ├── 0436.Find Right Interval.py ├── 0437.Path Sum III.py ├── 0438.Find All Anagrams in a String.rb ├── 0441.Arranging Coins.cpp ├── 0441.Arranging Coins.rb ├── 0442.Find All Duplicates in an Array.2.py ├── 0442.Find All Duplicates in an Array.py ├── 0443.String Compression.c ├── 0445.Add Two Numbers II.py ├── 0446.Arithmetic Slices II - Subsequence.py ├── 0447.Number of Boomerangs.cpp ├── 0448.Find All Numbers Disappeared in an Array.rb ├── 0449.Serialize and Deserialize BST.py ├── 0450.Delete Node in a BST.py ├── 0451.Sort Characters By Frequency.rb ├── 0452.Minimum Number of Arrows to Burst Balloons.py ├── 0453.Minimum Moves to Equal Array Elements.cpp ├── 0455.Assign Cookies.cpp ├── 0456.132 Pattern.py ├── 0457.Circular Array Loop.py ├── 0458.Poor Pigs.cpp ├── 0458.Poor Pigs.java ├── 0459.Repeated Substring Pattern.py ├── 0461.Hamming Distance.cpp ├── 0462.Minimum Moves to Equal Array Elements II.c ├── 0463.Island Perimeter.cpp ├── 0463.Island Perimeter.py ├── 0463.Island Perimeter.rb ├── 0468.Validate IP Address.rb ├── 0470.Implement Rand10() Using Rand7().c ├── 0472.Concatenated Words.2.py ├── 0472.Concatenated Words.py ├── 0474.Ones and Zeroes.py ├── 0475.Heaters.ts ├── 0476.Number Complement.rb ├── 0477.Total Hamming Distance.cpp ├── 0477.Total Hamming Distance.py ├── 0480.Sliding Window Median.py ├── 0482.License Key Formatting.py ├── 0483.Smallest Good Base.py ├── 0485.Max Consecutive Ones.py ├── 0486.Predict the Winner.java ├── 0488.Zuma Game.py ├── 0492.Construct the Rectangle.java ├── 0494.Target Sum.java ├── 0495.Teemo Attacking.2.(Floyd Warshall).py ├── 0495.Teemo Attacking.py ├── 0496.Next Greater Element I.py ├── 0497.Random Point in Non-overlapping Rectangles.java ├── 0498.Diagonal Traverse.py ├── 0500.Keyboard Row.2.py ├── 0500.Keyboard Row.js ├── 0500.Keyboard Row.py └── README.md ├── 0501-1000 ├── 0502.IPO.py ├── 0503.Next Greater Element II.py ├── 0504.Base 7.ts ├── 0506.Relative Ranks.py ├── 0507.Perfect Number.py ├── 0508.Most Frequent Subtree Sum.py ├── 0509.Fibonacci Number.java ├── 0516.Longest Palindromic Subsequence.py ├── 0517.Super Washing Machines.ts ├── 0518.Coin Change II.java ├── 0519.Random Flip Matrix.py ├── 0520.Detect Capital.c ├── 0521.Longest Uncommon Subsequence I.java ├── 0523.Continuous Subarray Sum.java ├── 0524.Longest Word in Dictionary through Deleting.py ├── 0525.Contiguous Array.2.rb ├── 0525.Contiguous Array.3.rb ├── 0525.Contiguous Array.py ├── 0525.Contiguous Array.rb ├── 0526.Beautiful Arrangement.py ├── 0528.Random Pick with Weight.rb ├── 0530.Minimum Absolute Difference in BST.py ├── 0532.K-diff Pairs in an Array.py ├── 0535.Encode and Decode TinyURL.py ├── 0537.Complex Number Multiplication.ts ├── 0538.Convert BST to Greater Tree.py ├── 0539.Minimum Time Difference.ts ├── 0540.Single Element in a Sorted Array.js ├── 0541.Reverse String II.py ├── 0542.01 Matrix.py ├── 0543.Diameter of Binary Tree.rb ├── 0547.Number of Provinces.(Friend Circles).c ├── 0551.Student Attendance Record I.ts ├── 0552.Student Attendance Record II.py ├── 0553.Optimal Division.2.py ├── 0553.Optimal Division.py ├── 0554.Brick Wall.py ├── 0556.Next Greater Element III.py ├── 0557.Reverse Words in a String III.c ├── 0559.Maximum Depth of N-ary Tree.py ├── 0560.Subarray Sum Equals K.rb ├── 0561.Array Partition.rb ├── 0563.Binary Tree Tilt.py ├── 0564.Find the Closest Palindrome.py ├── 0566.Reshape the Matrix.py ├── 0567.Permutation in String.py ├── 0567.Permutation in String.rb ├── 0575.Distribute Candies.ts ├── 0576.Out of Boundary Paths.py ├── 0581.Shortest Unsorted Continuous Subarray.py ├── 0583.Delete Operation for Two Strings.java ├── 0587.Erect the Fence.py ├── 0589.N-ary Tree Preorder Traversal.js ├── 0590.N-ary Tree Postorder Traversal.py ├── 0591.Tag Validator.ts ├── 0593.Valid Square.py ├── 0594.Longest Harmonious Subsequence.ts ├── 0595.Big Countries.sql ├── 0598.Range Addition II.php ├── 0599.Minimum Index Sum of Two Lists.ts ├── 0600.Non-negative Integers without Consecutive Ones.py ├── 0605.Can Place Flowers.c ├── 0606.Construct String from Binary Tree.ts ├── 0611.Valid Triangle Number.py ├── 0617.Merge Two Binary Trees.java ├── 0621.Task Scheduler.2.py ├── 0621.Task Scheduler.py ├── 0622.Design Circular Queue.py ├── 0623.Add One Row to Tree.js ├── 0628.Maximum Product of Three Numbers.py ├── 0629.K Inverse Pairs Array.py ├── 0630.Course Schedule III.java ├── 0632.Smallest Range Covering Elements from K Lists.py ├── 0633.Sum of Square Numbers.py ├── 0638.Shopping Offers.ts ├── 0639.Decode Ways II.ts ├── 0643.Maximum Average Subarray I.py ├── 0645.Set Mismatch.cpp ├── 0649.Dota2 Senate.py ├── 0650.2 Keys Keyboard.py ├── 0652.Find Duplicate Subtrees.py ├── 0653.Two Sum IV - Input is a BST.py ├── 0654.Maximum Binary Tree.java ├── 0655.Print Binary Tree.py ├── 0657.Robot Return to Origin.java ├── 0659.Split Array into Consecutive Subsequences.py ├── 0661.Image Smoother.ts ├── 0662.Maximum Width of Binary Tree.rb ├── 0664.Strange Printer.py ├── 0665.Non-decreasing Array.c ├── 0667.Beautiful Arrangement II.py ├── 0669.Trim a Binary Search Tree.cpp ├── 0671.Second Minimum Node In a Binary Tree.java ├── 0673.Number of Longest Increasing Subsequence.py ├── 0674.Longest Continuous Increasing Subsequence.c ├── 0677.Map Sum Pairs.py ├── 0678.Valid Parenthesis String.2.rb ├── 0678.Valid Parenthesis String.rb ├── 0680.Valid Palindrome II.py ├── 0682.Baseball Game.ts ├── 0683.K Empty Slots.py ├── 0684.Redundant Connection.py ├── 0686.Repeated String Match.ts ├── 0687.Longest Univalue Path.py ├── 0688.Knight Probability in Chessboard.py ├── 0689.Maximum Sum of 3 Non-Overlapping Subarrays.py ├── 0690.Employee Importance.php ├── 0692.Top K Frequent Words.py ├── 0693.Binary Number with Alternating Bits.ts ├── 0695.Max Area of Island.py ├── 0696.Count Binary Substrings.py ├── 0697.Degree of an Array.java ├── 0698.Partition to K Equal Sum Subsets.py ├── 0700.Search in a Binary Search Tree.rb ├── 0701.Insert into a Binary Search Tree.cpp ├── 0701.Insert into a Binary Search Tree.rb ├── 0703.Kth Largest Element in a Stream.py ├── 0704.Binary Search.c ├── 0705.Design HashSet.rb ├── 0706.Design HashMap.java ├── 0709.To Lower Case.ts ├── 0710.Random Pick with Blacklist.py ├── 0713.Subarray Product Less Than K.py ├── 0714.Best Time to Buy and Sell Stock with Transaction Fee.java ├── 0717.1-bit and 2-bit Characters.ts ├── 0720.Longest Word in Dictionary.ts ├── 0721.Accounts Merge.py ├── 0722.Remove Comments.py ├── 0724.Find Pivot Index.py ├── 0725.Split Linked List in Parts.c ├── 0726.Number of Atoms.py ├── 0728.Self Dividing Numbers.py ├── 0729.My Calendar I.py ├── 0731.My Calendar II.py ├── 0733.Flood Fill.rb ├── 0735.Asteroid Collision.py ├── 0738.Monotone Increasing Digits.py ├── 0740.Delete and Earn.java ├── 0741.Cherry Pickup.py ├── 0743.Network Delay Time.py ├── 0744.Find Smallest Letter Greater Than Target.ts ├── 0746.Min Cost Climbing Stairs.py ├── 0747.Largest Number At Least Twice of Others.java ├── 0748.Shortest Completing Word.ts ├── 0752.Open the Lock.(step cost being the next stage - Dijkstra).py ├── 0752.Open the Lock.2.py ├── 0752.Open the Lock.py ├── 0756.Pyramid Transition Matrix.java ├── 0760.Find Anagram Mappings.py ├── 0761.Special Binary String.py ├── 0763.Partition Labels.py ├── 0764.Largest Plus Sign.java ├── 0765.Couples Holding Hands.py ├── 0766.Toeplitz Matrix.2.java ├── 0766.Toeplitz Matrix.java ├── 0767.Reorganize String.py ├── 0768.Max Chunks To Make Sorted II.py ├── 0769.Max Chunks To Make Sorted.py ├── 0771.Jewels and Stones.rb ├── 0773.Sliding Puzzle.py ├── 0778.Swim in Rising Water.py ├── 0780.Reaching Points.ts ├── 0781.Rabbits in Forest.py ├── 0782.Transform to Chessboard.py ├── 0783.Minimum Distance Between BST Nodes.py ├── 0785.Is Graph Bipartite?.rb ├── 0786.K-th Smallest Prime Fraction.py ├── 0787.Cheapest Flights Within K Stops.py ├── 0787.Cheapest Flights Within K Stops.rb ├── 0788.Rotated Digits.py ├── 0789.Escape The Ghosts.py ├── 0790.Domino and Tromino Tiling.java ├── 0790.Domino and Tromino Tiling.py ├── 0791.Custom Sort String.2.py ├── 0791.Custom Sort String.py ├── 0792.Number of Matching Subsequences.py ├── 0794.Valid Tic-Tac-Toe State.py ├── 0796.Rotate String.ts ├── 0797.All Paths From Source to Target.java ├── 0799.Champagne Tower.py ├── 0802.Find Eventual Safe States.py ├── 0803.Bricks Falling When Hit.py ├── 0804.Unique Morse Code Words.py ├── 0805.Split Array With Same Average.rb ├── 0806.Number of Lines To Write String.py ├── 0807.Max Increase to Keep City Skyline.c ├── 0809.Expressive Words.py ├── 0810.Chalkboard XOR Game.c ├── 0811.Subdomain Visit Count.2.py ├── 0811.Subdomain Visit Count.py ├── 0812.Largest Triangle Area.ts ├── 0813.Largest Sum of Averages.py ├── 0815.Bus Routes.js ├── 0815.Bus Routes.py ├── 0819.Most Common Word.java ├── 0821.Shortest Distance to a Character.py ├── 0822.Card Flipping Game.2.py ├── 0822.Card Flipping Game.py ├── 0824.Goat Latin.py ├── 0825.Friends Of Appropriate Ages.py ├── 0827.Making A Large Island.py ├── 0828.Count Unique Characters of All Substrings of a Given String.py ├── 0829.Consecutive Numbers Sum.py ├── 0830.Positions of Large Groups.java ├── 0832.Flipping an Image.java ├── 0834.Sum of Distances in Tree.py ├── 0835.Image Overlap.java ├── 0836.Rectangle Overlap.java ├── 0838.Push Dominoes.py ├── 0839.Similar String Groups.py ├── 0842.Split Array into Fibonacci Sequence.py ├── 0844.Backspace String Compare.py ├── 0844.Backspace String Compare.rb ├── 0845.Longest Mountain in Array.py ├── 0846.Hand of Straights.py ├── 0847.Shortest Path Visiting All Nodes.py ├── 0848.Shifting Letters.py ├── 0849.Maximize Distance to Closest Person.py ├── 0851.Loud and Rich.py ├── 0852.Peak Index in a Mountain Array.py ├── 0853.Car Fleet.py ├── 0854.K-Similar Strings.py ├── 0857.Minimum Cost to Hire K Workers.py ├── 0858.Mirror Reflection.py ├── 0859.Buddy Strings.py ├── 0860.Lemonade Change.py ├── 0861.Score After Flipping Matrix.py ├── 0862.Shortest Subarray with Sum at Least K.py ├── 0863.All Nodes Distance K in Binary Tree.py ├── 0867.Transpose Matrix.rb ├── 0868.Binary Gap.py ├── 0869.Reordered Power of 2.2.ts ├── 0869.Reordered Power of 2.ts ├── 0872.Leaf-Similar Trees.py ├── 0873.Length of Longest Fibonacci Subsequence.py ├── 0874.Walking Robot Simulation.py ├── 0876.Middle of the Linked List.py ├── 0876.Middle of the Linked List.rb ├── 0877.Stone Game.py ├── 0878.Nth Magical Number.(lcm loop).py ├── 0879.Profitable Schemes.py ├── 0880.Decoded String at Index.py ├── 0881.Boats to Save People.py ├── 0882.Reachable Nodes In Subdivided Graph.py ├── 0883.Projection Area of 3D Shapes.py ├── 0884.Uncommon Words from Two Sentences.py ├── 0885.Spiral Matrix III.java ├── 0886.Possible Bipartition.rb ├── 0888.Fair Candy Swap.py ├── 0889.Construct Binary Tree from Preorder and Postorder Traversal.py ├── 0890.Find and Replace Pattern.py ├── 0892.Surface Area of 3D Shapes.py ├── 0893.Groups of Special-Equivalent Strings.py ├── 0894.All Possible Full Binary Trees.py ├── 0895.Maximum Frequency Stack.py ├── 0896.Monotonic Array.py ├── 0897.Increasing Order Search Tree.py ├── 0898.Bitwise ORs of Subarrays.py ├── 0899.Orderly Queue.py ├── 0900.RLE Iterator.py ├── 0901.Online Stock Span.py ├── 0901.Online Stock Span.rb ├── 0902.Numbers At Most N Given Digit Set.py ├── 0904.Fruit Into Baskets.py ├── 0905.Sort Array By Parity.rb ├── 0908.Smallest Range I.py ├── 0909.Snakes and Ladders.py ├── 0911.Online Election.2.py ├── 0911.Online Election.py ├── 0912.Sort an Array.py ├── 0913.Cat and Mouse.py ├── 0914.X of a Kind in a Deck of Cards.py ├── 0916.Word Subsets.py ├── 0917.Reverse Only Letters.c ├── 0918.Maximum Sum Circular Subarray.py ├── 0919.Complete Binary Tree Inserter.java ├── 0921.Minimum Add to Make Parentheses Valid.py ├── 0922.Sort Array By Parity II.py ├── 0923.3Sum With Multiplicity.py ├── 0924.Minimize Malware Spread.py ├── 0925.Long Pressed Name.java ├── 0926.Flip String to Monotone Increasing.py ├── 0927.Three Equal Parts.py ├── 0929.Unique Email Addresses.py ├── 0930.Binary Subarrays With Sum.ts ├── 0931.Minimum Falling Path Sum.js ├── 0933.Number of Recent Calls.java ├── 0934.Shortest Bridge.py ├── 0937.Reorder Data in Log Files.py ├── 0938.Range Sum of BST.rb ├── 0939.Minimum Area Rectangle.py ├── 0941.Valid Mountain Array.py ├── 0942.DI String Match.py ├── 0944.Delete Columns to Make Sorted.py ├── 0947.Most Stones Removed with Same Row or Column.py ├── 0948.Bag of Tokens.py ├── 0949.Largest Time for Given Digits.java ├── 0950.Reveal Cards In Increasing Order.py ├── 0951.Flip Equivalent Binary Trees.py ├── 0952.Largest Component Size by Common Factor.py ├── 0953.Verifying an Alien Dictionary.py ├── 0954.Array of Doubled Pairs.2.py ├── 0954.Array of Doubled Pairs.py ├── 0955.Delete Columns to Make Sorted II.py ├── 0956.Tallest Billboard.py ├── 0957.Prison Cells After N Days.py ├── 0958.Check Completeness of a Binary Tree.py ├── 0958.Check Completeness of a Binary Tree.rb ├── 0959.Regions Cut By Slashes.py ├── 0960.Delete Columns to Make Sorted III.py ├── 0961.N-Repeated Element in Size 2N Array.2.py ├── 0961.N-Repeated Element in Size 2N Array.py ├── 0962.Maximum Width Ramp.py ├── 0963.Minimum Area Rectangle II.py ├── 0965.Univalued Binary Tree.java ├── 0966.Vowel Spellchecker.py ├── 0967.Numbers With Same Consecutive Differences.rb ├── 0968.Binary Tree Cameras.py ├── 0969.Pancake Sorting.py ├── 0970.Powerful Integers.py ├── 0971.Flip Binary Tree To Match Preorder Traversal.java ├── 0973.K Closest Points to Origin.rb ├── 0974.Subarray Sums Divisible by K.java ├── 0976.Largest Perimeter Triangle.py ├── 0977.Squares of a Sorted Array.py ├── 0978.Longest Turbulent Subarray.py ├── 0979.Distribute Coins in Binary Tree.py ├── 0980.Unique Paths III.py ├── 0981.Time Based Key-Value Store.py ├── 0982.Triples with Bitwise AND Equal To Zero.cpp ├── 0983.Minimum Cost For Tickets.java ├── 0984.String Without AAA or BBB.py ├── 0985.Sum of Even Numbers After Queries.rb ├── 0986.Interval List Intersections.rb ├── 0987.Vertical Order Traversal of a Binary Tree.py ├── 0988.Smallest String Starting From Leaf.py ├── 0989.Add to Array-Form of Integer.py ├── 0990.Satisfiability of Equality Equations.py ├── 0991.Broken Calculator.java ├── 0992.Subarrays with K Different Integers.py ├── 0993.Cousins in Binary Tree.rb ├── 0994.Rotting Oranges.2.py ├── 0994.Rotting Oranges.py ├── 0995.Minimum Number of K Consecutive Bit Flips.md ├── 0995.Minimum Number of K Consecutive Bit Flips.py ├── 0996.Number of Squareful Arrays.py ├── 0997.Find the Town Judge.py ├── 0997.Find the Town Judge.rb ├── 0998.Maximum Binary Tree II.py ├── 0999.Available Captures for Rook.py ├── 1000.Minimum Cost to Merge Stones.py └── README.md ├── 1001-1500 ├── 1001.Grid Illumination.py ├── 1002.Find Common Characters.py ├── 1003.Check If Word Is Valid After Substitutions.py ├── 1004.Max Consecutive Ones III.java ├── 1005.Maximize Sum Of Array After K Negations.py ├── 1006.Clumsy Factorial.py ├── 1007.Minimum Domino Rotations For Equal Row.py ├── 1008.Construct Binary Search Tree from Preorder Traversal.py ├── 1008.Construct Binary Search Tree from Preorder Traversal.rb ├── 1009.Complement of Base 10 Integer.py ├── 1010.Pairs of Songs With Total Durations Divisible by 60.py ├── 1011.Capacity To Ship Packages Within D Days.py ├── 1013.Partition Array Into Three Parts With Equal Sum.md ├── 1013.Partition Array Into Three Parts With Equal Sum.py ├── 1014.Best Sightseeing Pair.py ├── 1015.Smallest Integer Divisible by K.py ├── 1016.Binary String With Substrings Representing 1 To N.py ├── 1017.Convert to Base -2.py ├── 1018.Binary Prefix Divisible By 5.py ├── 1019.Next Greater Node In Linked List.py ├── 1020.Number of Enclaves.py ├── 1021.Remove Outermost Parentheses.py ├── 1022.Sum of Root To Leaf Binary Numbers.py ├── 1023.Camelcase Matching.py ├── 1024.Video Stitching.py ├── 1025.Divisor Game.py ├── 1026.Maximum Difference Between Node and Ancestor.py ├── 1027.Longest Arithmetic Subsequence.py ├── 1028.Recover a Tree From Preorder Traversal.py ├── 1029.Two City Scheduling.py ├── 1029.Two City Scheduling.rb ├── 1030.Matrix Cells in Distance Order.py ├── 1031.Maximum Sum of Two Non-Overlapping Subarrays.py ├── 1032.Stream of Characters.py ├── 1033.Moving Stones Until Consecutive.py ├── 1034.Coloring A Border.py ├── 1035.Uncrossed Lines.py ├── 1035.Uncrossed Lines.rb ├── 1036.Escape a Large Maze.py ├── 1037.Valid Boomerang.py ├── 1038.Binary Search Tree to Greater Sum Tree.c ├── 1039.Minimum Score Triangulation of Polygon.py ├── 1040.Moving Stones Until Consecutive II.py ├── 1041.Robot Bounded In Circle.py ├── 1042.Flower Planting With No Adjacent.py ├── 1043.Partition Array for Maximum Sum.2.py ├── 1043.Partition Array for Maximum Sum.py ├── 1044.Longest Duplicate Substring.rb ├── 1046.Last Stone Weight.py ├── 1046.Last Stone Weight.rb ├── 1047.Remove All Adjacent Duplicates In String.py ├── 1048.Longest String Chain.2.py ├── 1048.Longest String Chain.py ├── 1049.Last Stone Weight II.py ├── 1051.Height Checker.py ├── 1052.Grumpy Bookstore Owner.py ├── 1053.Previous Permutation With One Swap.py ├── 1054.Distant Barcodes.py ├── 1061.Lexicographically Smallest Equivalent String.php ├── 1071.Greatest Common Divisor of Strings.py ├── 1072.Flip Columns For Maximum Number of Equal Rows.py ├── 1073.Adding Two Negabinary Numbers.py ├── 1074.Number of Submatrices That Sum to Target.py ├── 1078.Occurrences After Bigram.py ├── 1079.Letter Tile Possibilities.py ├── 1080.Insufficient Nodes in Root to Leaf Paths.py ├── 1081.Smallest Subsequence of Distinct Characters.py ├── 1089.Duplicate Zeros.java ├── 1090.Largest Values From Labels.py ├── 1091.Shortest Path in Binary Matrix.py ├── 1092.Shortest Common Supersequence.py ├── 1093.Statistics from a Large Sample.py ├── 1094.Car Pooling.py ├── 1095.Find in Mountain Array.md ├── 1095.Find in Mountain Array.py ├── 1096.Brace Expansion II.md ├── 1096.Brace Expansion II.py ├── 1103.Distribute Candies to People.py ├── 1104.Path In Zigzag Labelled Binary Tree.py ├── 1105.Filling Bookcase Shelves.py ├── 1106.Parsing A Boolean Expression.py ├── 1108.Defanging an IP Address.py ├── 1109.Corporate Flight Bookings.md ├── 1109.Corporate Flight Bookings.py ├── 1110.Delete Nodes And Return Forest.md ├── 1110.Delete Nodes And Return Forest.py ├── 1111.Maximum Nesting Depth of Two Valid Parentheses Strings.md ├── 1111.Maximum Nesting Depth of Two Valid Parentheses Strings.py ├── 1114.Print in Order.java ├── 1115.Print FooBar Alternately.java ├── 1116.Print Zero Even Odd.java ├── 1117.Building H2O.java ├── 1122.Relative Sort Array.py ├── 1123.Lowest Common Ancestor of Deepest Leaves.py ├── 1124.Longest Well-Performing Interval.java ├── 1124.Longest Well-Performing Interval.py ├── 1128.Number of Equivalent Domino Pairs.2.py ├── 1128.Number of Equivalent Domino Pairs.py ├── 1129.Shortest Path with Alternating Colors.py ├── 1130.Minimum Cost Tree From Leaf Values.py ├── 1131.Maximum of Absolute Value Expression.py ├── 1137.N-th Tribonacci Number.py ├── 1138.Alphabet Board Path.py ├── 1139.Largest 1-Bordered Square.py ├── 1140.Stone Game II.py ├── 1143.Longest Common Subsequence.py ├── 1143.Longest Common Subsequence.rb ├── 1144.Decrease Elements To Make Array Zigzag.py ├── 1145.Binary Tree Coloring Game.py ├── 1146.Snapshot Array.py ├── 1147.Longest Chunked Palindrome Decomposition.py ├── 1154.Day of the Year.java ├── 1155.Number of Dice Rolls With Target Sum.java ├── 1156.Swap For Longest Repeated Character Substring.java ├── 1160.Find Words That Can Be Formed by Characters.java ├── 1161.Maximum Level Sum of a Binary Tree.java ├── 1162.As Far from Land as Possible.java ├── 1163.Last Substring in Lexicographical Order.java ├── 1165.Single-Row Keyboard.java ├── 1165.Single-Row Keyboard.py ├── 1166.Design File System.java ├── 1169.Invalid Transactions.py ├── 1170.Compare Strings by Frequency of the Smallest Character.py ├── 1171.Remove Zero Sum Consecutive Nodes from Linked List.java ├── 1172.Dinner Plate Stacks.py ├── 1175.Prime Arrangements.py ├── 1176.Diet Plan Performance.py ├── 1177.Can Make Palindrome from Substring.py ├── 1178.Number of Valid Words for Each Puzzle.py ├── 1184.Distance Between Bus Stops.py ├── 1185.Day of the Week.py ├── 1186.Maximum Subarray Sum with One Deletion.py ├── 1187.Make Array Strictly Increasing.md ├── 1187.Make Array Strictly Increasing.py ├── 1189.Maximum Number of Balloons.py ├── 1190.Reverse Substrings Between Each Pair of Parentheses.py ├── 1191.K-Concatenation Maximum Sum.py ├── 1192.Critical Connections in a Network.md ├── 1192.Critical Connections in a Network.py ├── 1195.Fizz Buzz Multithreaded.java ├── 1196.How Many Apples Can You Put into the Basket.py ├── 1197.Minimum Knight Moves.py ├── 1198.Find Smallest Common Element in All Rows.py ├── 1199.Minimum Time to Build Blocks.2.py ├── 1199.Minimum Time to Build Blocks.py ├── 1200.Minimum Absolute Difference.py ├── 1201.Ugly Number III.py ├── 1202.Smallest String With Swaps.py ├── 1203.Sort Items by Groups Respecting Dependencies.py ├── 1207.Unique Number of Occurrences.py ├── 1208.Get Equal Substrings Within Budget.py ├── 1209.Remove All Adjacent Duplicates in String II.py ├── 1210.Minimum Moves to Reach Target with Rotations.py ├── 1213.Intersection of Three Sorted Arrays.java ├── 1214.Two Sum BSTs.java ├── 1217.Minimum Cost to Move Chips to The Same Position.py ├── 1218.Longest Arithmetic Subsequence of Given Difference.py ├── 1219.Path with Maximum Gold.py ├── 1220.Count Vowels Permutation.py ├── 1221.Split a String in Balanced Strings.java ├── 1222.Queens That Can Attack the King.java ├── 1223.Dice Roll Simulation.py ├── 1224.Maximum Equal Frequency.py ├── 1226.The Dining Philosophers.java ├── 1227.Airplane Seat Assignment Probability.java ├── 1227.Airplane Seat Assignment Probability.md ├── 1232.Check If It Is a Straight Line.rb ├── 1233.Remove Sub-Folders from the Filesystem.py ├── 1234.Replace the Substring for Balanced String.py ├── 1235.Maximum Profit in Job Scheduling.py ├── 1237.Find Positive Integer Solution for a Given Equation.java ├── 1238.Circular Permutation in Binary Representation.py ├── 1239.Maximum Length of a Concatenated String with Unique Characters.py ├── 1240.Tiling a Rectangle with the Fewest Squares.py ├── 1243.Array Transformation.py ├── 1244.Design A Leaderboard.py ├── 1245.Tree Diameter.java ├── 1246.Palindrome Removal.2.py ├── 1246.Palindrome Removal.py ├── 1247.Minimum Swaps to Make Strings Equal.py ├── 1248.Count Number of Nice Subarrays.py ├── 1249.Minimum Remove to Make Valid Parentheses.py ├── 1250.Check If It Is a Good Array.py ├── 1252.Cells with Odd Values in a Matrix.py ├── 1253.Reconstruct a 2-Row Binary Matrix.py ├── 1254.Number of Closed Islands.py ├── 1255.Maximum Score Words Formed by Letters.py ├── 1256.Encode Number.py ├── 1257.Smallest Common Region.py ├── 1258.Synonymous Sentences.java ├── 1259.Handshakes That Don't Cross.2.java ├── 1259.Handshakes That Don't Cross.java ├── 1260.Shift 2D Grid.py ├── 1261.Find Elements in a Contaminated Binary Tree.py ├── 1262.Greatest Sum Divisible by Three.py ├── 1263.Minimum Moves to Move a Box to Their Target Location.py ├── 1266.Minimum Time Visiting All Points.py ├── 1267.Count Servers that Communicate.c ├── 1268.Search Suggestions System.py ├── 1269.Number of Ways to Stay in the Same Place After Some Steps.py ├── 1271.Hexspeak.py ├── 1272.Remove Interval.py ├── 1273.Delete Tree Nodes.py ├── 1274.Number of Ships in a Rectangle.java ├── 1275.Find Winner on a Tic Tac Toe Game.py ├── 1276.Number of Burgers with No Waste of Ingredients.py ├── 1277.Count Square Submatrices with All Ones.py ├── 1277.Count Square Submatrices with All Ones.rb ├── 1278.Palindrome Partitioning III.py ├── 1281.Subtract the Product and Sum of Digits of an Integer.py ├── 1282.Group the People Given the Group Size They Belong To.py ├── 1283.Find the Smallest Divisor Given a Threshold.py ├── 1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix.py ├── 1286.Iterator for Combination.2.py ├── 1286.Iterator for Combination.3.txt ├── 1286.Iterator for Combination.py ├── 1287.Element Appearing More Than 25% In Sorted Array.py ├── 1288.Remove Covered Intervals.py ├── 1289.Minimum Falling Path Sum II.py ├── 1290.Convert Binary Number in a Linked List to Integer.c ├── 1290.Convert Binary Number in a Linked List to Integer.java ├── 1291.Sequential Digits.py ├── 1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold.py ├── 1293.Shortest Path in a Grid with Obstacles Elimination.2.py ├── 1295.Find Numbers with Even Number of Digits.py ├── 1296.Divide Array in Sets of K Consecutive Numbers.py ├── 1297.Maximum Number of Occurrences of a Substring.2.py ├── 1297.Maximum Number of Occurrences of a Substring.py ├── 1298.Maximum Candies You Can Get from Boxes.py ├── 1299.Replace Elements with Greatest Element on Right Side.py ├── 1300.Sum of Mutated Array Closest to Target.py ├── 1301.Number of Paths with Max Score.py ├── 1302.Deepest Leaves Sum.py ├── 1304.Find N Unique Integers Sum up to Zero.rb ├── 1305.All Elements in Two Binary Search Trees.2.py ├── 1305.All Elements in Two Binary Search Trees.py ├── 1306.Jump Game III.java ├── 1307.Verbal Arithmetic Puzzle.c ├── 1309.Decrypt String from Alphabet to Integer Mapping.py ├── 1310.XOR Queries of a Subarray.py ├── 1311.Get Watched Videos by Your Friends.py ├── 1312.Minimum Insertion Steps to Make a String Palindrome.md ├── 1312.Minimum Insertion Steps to Make a String Palindrome.py ├── 1313.Decompress Run-Length Encoded List.py ├── 1314.Matrix Block Sum.cpp ├── 1315.Sum of Nodes with Even-Valued Grandparent.cpp ├── 1316.Distinct Echo Substrings.md ├── 1316.Distinct Echo Substrings.py ├── 1317.Convert Integer to the Sum of Two No-Zero Integers.py ├── 1318.Minimum Flips to Make a OR b Equal to c.py ├── 1319.Number of Operations to Make Network Connected.py ├── 1320.Minimum Distance to Type a Word Using Two Fingers.py ├── 1323.Maximum 69 Number.py ├── 1324.Print Words Vertically.py ├── 1325.Delete Leaves With a Given Value.md ├── 1325.Delete Leaves With a Given Value.py ├── 1326.Minimum Number of Taps to Open to Water a Garden.py ├── 1328.Break a Palindrome.py ├── 1329.Sort the Matrix Diagonally.py ├── 1330.Reverse Subarray To Maximize Array Value.c ├── 1331.Rank Transform of an Array.py ├── 1332.Remove Palindromic Subsequences.py ├── 1333.Filter Restaurants by Vegan-Friendly, Price and Distance.py ├── 1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance.py ├── 1335.Minimum Difficulty of a Job Schedule.py ├── 1337.The K Weakest Rows in a Matrix.py ├── 1338.Reduce Array Size to The Half.py ├── 1339.Maximum Product of Splitted Binary Tree.py ├── 1340.Jump Game V.2.py ├── 1340.Jump Game V.md ├── 1340.Jump Game V.py ├── 1342.Number of Steps to Reduce a Number to Zero.c ├── 1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold.py ├── 1344.Angle Between Hands of a Clock.py ├── 1345.Jump Game IV.py ├── 1346.Check If N and Its Double Exist.py ├── 1347.Minimum Number of Steps to Make Two Strings Anagram.py ├── 1348.Tweet Counts Per Frequency.2.py ├── 1348.Tweet Counts Per Frequency.java ├── 1348.Tweet Counts Per Frequency.py ├── 1349.Maximum Students Taking Exam.py ├── 1351.Count Negative Numbers in a Sorted Matrix.c ├── 1351.Count Negative Numbers in a Sorted Matrix.py ├── 1352.Product of the Last K Numbers.py ├── 1353.Maximum Number of Events That Can Be Attended.md ├── 1353.Maximum Number of Events That Can Be Attended.py ├── 1354.Construct Target Array With Multiple Sums.2.py ├── 1354.Construct Target Array With Multiple Sums.md ├── 1354.Construct Target Array With Multiple Sums.py ├── 1356.Sort Integers by The Number of 1 Bits.py ├── 1357.Apply Discount Every n Orders.java ├── 1358.Number of Substrings Containing All Three Characters.c ├── 1358.Number of Substrings Containing All Three Characters.md ├── 1359.Count All Valid Pickup and Delivery Options.cpp ├── 1359.Count All Valid Pickup and Delivery Options.md ├── 1360.Number of Days Between Two Dates.py ├── 1361.Validate Binary Tree Nodes.py ├── 1361.Validate Binary Tree Nodes.rb ├── 1362.Closest Divisors.md ├── 1362.Closest Divisors.py ├── 1363.Largest Multiple of Three.py ├── 1365.How Many Numbers Are Smaller Than the Current Number.py ├── 1366.Rank Teams by Votes.py ├── 1367.Linked List in Binary Tree.py ├── 1368.Minimum Cost to Make at Least One Valid Path in a Grid.2.py ├── 1368.Minimum Cost to Make at Least One Valid Path in a Grid.py ├── 1370.Increasing Decreasing String.py ├── 1371.Find the Longest Substring Containing Vowels in Even Counts.py ├── 1372.Longest ZigZag Path in a Binary Tree.py ├── 1373.Maximum Sum BST in Binary Tree.py ├── 1374.Generate a String With Characters That Have Odd Counts.py ├── 1375.Number of Times Binary String Is Prefix-Aligned.py ├── 1376.Time Needed to Inform All Employees.md ├── 1376.Time Needed to Inform All Employees.py ├── 1377.Frog Position After T Seconds.md ├── 1377.Frog Position After T Seconds.py ├── 1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree.py ├── 1380.Lucky Numbers in a Matrix.py ├── 1381.Design a Stack With Increment Operation.py ├── 1382.Balance a Binary Search Tree.py ├── 1383.Maximum Performance of a Team.md ├── 1383.Maximum Performance of a Team.py ├── 1385.Find the Distance Value Between Two Arrays.py ├── 1386.Cinema Seat Allocation.py ├── 1387.Sort Integers by The Power Value.py ├── 1388.Pizza With 3n Slices.py ├── 1389.Create Target Array in the Given Order.py ├── 1390.Four Divisors.py ├── 1391.Check if There is a Valid Path in a Grid.py ├── 1392.Longest Happy Prefix.2.py ├── 1392.Longest Happy Prefix.py ├── 1394.Find Lucky Integer in an Array.py ├── 1395.Count Number of Teams.py ├── 1396.Design Underground System.py ├── 1399.Count Largest Group.rb ├── 1400.Construct K Palindrome Strings.py ├── 1400.Construct K Palindrome Strings.rb ├── 1401.Circle and Rectangle Overlapping.py ├── 1402.Reducing Dishes.py ├── 1403.Minimum Subsequence in Non-Increasing Order.py ├── 1404.Number of Steps to Reduce a Number in Binary Representation to One.2.py ├── 1404.Number of Steps to Reduce a Number in Binary Representation to One.py ├── 1405.Longest Happy String.2.py ├── 1405.Longest Happy String.md ├── 1405.Longest Happy String.py ├── 1406.Stone Game III.py ├── 1408.String Matching in an Array.py ├── 1408.String Matching in an Array.rb ├── 1409.Queries on a Permutation With Key.py ├── 1410.HTML Entity Parser.py ├── 1410.HTML Entity Parser.rb ├── 1411.Number of Ways to Paint N × 3 Grid.py ├── 1411.Number of Ways to Paint N × 3 Grid.rb ├── 1413.Minimum Value to Get Positive Step by Step Sum.rb ├── 1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K.py ├── 1415.The k-th Lexicographical String of All Happy Strings of Length n.py ├── 1416.Restore The Array.md ├── 1416.Restore The Array.rb ├── 1417.Reformat The String.py ├── 1418.Display Table of Food Orders in a Restaurant.py ├── 1419.Minimum Number of Frogs Croaking.py ├── 1420.Build Array Where You Can Find The Maximum Exactly K Comparisons.py ├── 1422.Maximum Score After Splitting a String.py ├── 1422.Maximum Score After Splitting a String.rb ├── 1423.Maximum Points You Can Obtain from Cards.py ├── 1424.Diagonal Traverse II.py ├── 1425.Constrained Subsequence Sum.py ├── 1426.Counting Elements.rb ├── 1427.Perform String Shifts.rb ├── 1428.Leftmost Column with at Least a One.rb ├── 1429.First Unique Number.rb ├── 1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree.rb ├── 1431.Kids With the Greatest Number of Candies.rb ├── 1432.Max Difference You Can Get From Changing an Integer.rb ├── 1433.Check If a String Can Break Another String.rb ├── 1434.Number of Ways to Wear Different Hats to Each Other.py ├── 1436.Destination City.py ├── 1437.Check If All 1's Are at Least Length K Places Away.py ├── 1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit.py ├── 1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows.2.py ├── 1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows.md ├── 1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows.py ├── 1441.Build an Array With Stack Operations.py ├── 1442.Count Triplets That Can Form Two Arrays of Equal XOR.2.py ├── 1442.Count Triplets That Can Form Two Arrays of Equal XOR.py ├── 1443.Minimum Time to Collect All Apples in a Tree.py ├── 1444.Number of Ways of Cutting a Pizza.md ├── 1444.Number of Ways of Cutting a Pizza.py ├── 1444.Number of Ways of Cutting a Pizza.rb ├── 1446.Consecutive Characters.rb ├── 1447.Simplified Fractions.rb ├── 1448.Count Good Nodes in Binary Tree.php ├── 1449.Form Largest Integer With Digits That Add up to Target.py ├── 1450.Number of Students Doing Homework at a Given Time.py ├── 1451.Rearrange Words in a Sentence.py ├── 1452.People Whose List of Favorite Companies Is Not a Subset of Another List.py ├── 1453.Maximum Number of Darts Inside of a Circular Dartboard.py ├── 1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence.py ├── 1456.Maximum Number of Vowels in a Substring of Given Length.py ├── 1457.Pseudo-Palindromic Paths in a Binary Tree.py ├── 1458.Max Dot Product of Two Subsequences.py ├── 1460.Make Two Arrays Equal by Reversing Subarrays.rb ├── 1461.Check If a String Contains All Binary Codes of Size K.rb ├── 1462.Course Schedule IV.rb ├── 1463.Cherry Pickup II.py ├── 1463.Cherry Pickup II.rb ├── 1464.Maximum Product of Two Elements in an Array.py ├── 1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.py ├── 1466.Reorder Routes to Make All Paths Lead to the City Zero.py ├── 1467.Probability of a Two Boxes Having The Same Number of Distinct Balls.py ├── 1470.Shuffle the Array.js ├── 1470.Shuffle the Array.py ├── 1470.Shuffle the Array.rb ├── 1471.The k Strongest Values in an Array.rb ├── 1472.Design Browser History.py ├── 1473.Paint House III.md ├── 1473.Paint House III.py ├── 1475.Final Prices With a Special Discount in a Shop.rb ├── 1476.Subrectangle Queries.rb ├── 1477.Find Two Non-overlapping Sub-arrays Each With Target Sum.rb ├── 1478.Allocate Mailboxes.py ├── 1480.Running Sum of 1d Array.py ├── 1481.Least Number of Unique Integers after K Removals.py ├── 1482.Minimum Number of Days to Make m Bouquets.md ├── 1482.Minimum Number of Days to Make m Bouquets.py ├── 1483.Kth Ancestor of a Tree Node.py ├── 1486.XOR Operation in an Array.py ├── 1487.Making File Names Unique.py ├── 1488.Avoid Flood in The City.py ├── 1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree.py ├── 1491.Average Salary Excluding the Minimum and Maximum Salary.rb ├── 1492.The kth Factor of n.rb ├── 1493.Longest Subarray of 1's After Deleting One Element.rb ├── 1494.Parallel Courses II.py ├── 1496.Path Crossing.py ├── 1497.Check If Array Pairs Are Divisible by k.py ├── 1498.Number of Subsequences That Satisfy the Given Sum Condition.py ├── 1499.Max Value of Equation.py └── README.md ├── 1501-2000 ├── 1502.Can Make Arithmetic Progression From Sequence.py ├── 1503.Last Moment Before All Ants Fall Out of a Plank.py ├── 1504.Count Submatrices With All Ones.py ├── 1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits.py ├── 1507.Reformat Date.md ├── 1507.Reformat Date.rb ├── 1508.Range Sum of Sorted Subarray Sums.rb ├── 1509.Minimum Difference Between Largest and Smallest Value in Three Moves.py ├── 1510.Stone Game IV.rb ├── 1512.Number of Good Pairs.py ├── 1513.Number of Substrings With Only 1s.py ├── 1514.Path with Maximum Probability.py ├── 1515.Best Position for a Service Centre.md ├── 1515.Best Position for a Service Centre.py ├── 1518.Water Bottles.py ├── 1519.Number of Nodes in the Sub-Tree With the Same Label.py ├── 1520.Maximum Number of Non-Overlapping Substrings.py ├── 1521.Find a Value of a Mysterious Function Closest to Target.py ├── 1523.Count Odd Numbers in an Interval Range.java ├── 1524.Number of Sub-arrays With Odd Sum.java ├── 1525.Number of Good Ways to Split a String.py ├── 1526.Minimum Number of Increments on Subarrays to Form a Target Array.java ├── 1528.Shuffle String.c ├── 1528.Shuffle String.md ├── 1528.Shuffle String.py ├── 1529.Minimum Suffix Flips.py ├── 1530.Number of Good Leaf Nodes Pairs.py ├── 1531.String Compression II.py ├── 1534.Count Good Triplets.py ├── 1535.Find the Winner of an Array Game.py ├── 1536.Minimum Swaps to Arrange a Binary Grid.py ├── 1537.Get the Maximum Score.py ├── 1539.Kth Missing Positive Number.py ├── 1540.Can Convert String in K Moves.py ├── 1541.Minimum Insertions to Balance a Parentheses String.py ├── 1542.Find Longest Awesome Substring.py ├── 1544.Make The String Great.py ├── 1545.Find Kth Bit in Nth Binary String.py ├── 1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target.py ├── 1547.Minimum Cost to Cut a Stick.py ├── 1550.Three Consecutive Odds.py ├── 1551.Minimum Operations to Make Array Equal.py ├── 1552.Magnetic Force Between Two Balls.py ├── 1553.Minimum Number of Days to Eat N Oranges.py ├── 1556.Thousand Separator.py ├── 1557.Minimum Number of Vertices to Reach All Nodes.py ├── 1558.Minimum Numbers of Function Calls to Make Target Array.2.java ├── 1558.Minimum Numbers of Function Calls to Make Target Array.java ├── 1559.Detect Cycles in 2D Grid.py ├── 1560.Most Visited Sector in a Circular Track.py ├── 1561.Maximum Number of Coins You Can Get.py ├── 1562.Find Latest Group of Size M.py ├── 1563.Stone Game V.java ├── 1563.Stone Game V.py ├── 1566.Detect Pattern of Length M Repeated K or More Times.py ├── 1567.Maximum Length of Subarray With Positive Product.py ├── 1568.Minimum Number of Days to Disconnect Island.py ├── 1569.Number of Ways to Reorder Array to Get Same BST.py ├── 1572.Matrix Diagonal Sum.py ├── 1573.Number of Ways to Split a String.py ├── 1574.Shortest Subarray to be Removed to Make Array Sorted.py ├── 1575.Count All Possible Routes.py ├── 1576.Replace All ?'s to Avoid Consecutive Repeating Characters.py ├── 1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers.py ├── 1578.Minimum Time to Make Rope Colorful.2.py ├── 1578.Minimum Time to Make Rope Colorful.py ├── 1579.Remove Max Number of Edges to Keep Graph Fully Traversable.py ├── 1582.Special Positions in a Binary Matrix.py ├── 1583.Count Unhappy Friends.py ├── 1584.Min Cost to Connect All Points.py ├── 1585.Check If String Is Transformable With Substring Sort Operations.py ├── 1588.Sum of All Odd Length Subarrays.py ├── 1589.Maximum Sum Obtained of Any Permutation.py ├── 1590.Make Sum Divisible by P.py ├── 1591.Strange Printer II.py ├── 1592.Rearrange Spaces Between Words.py ├── 1593.Split a String Into the Max Number of Unique Substrings.py ├── 1594.Maximum Non Negative Product in a Matrix.py ├── 1595.Minimum Cost to Connect Two Groups of Points.py ├── 1598.Crawler Log Folder.py ├── 1599.Maximum Profit of Operating a Centennial Wheel.py ├── 1600.Throne Inheritance.py ├── 1601.Maximum Number of Achievable Transfer Requests.py ├── 1603.Design Parking System.py ├── 1604.Alert Using Same Key-Card Three or More Times in a One Hour Period.py ├── 1605.Find Valid Matrix Given Row and Column Sums.py ├── 1606.Find Servers That Handled Most Number of Requests.java ├── 1608.Special Array With X Elements Greater Than or Equal X.py ├── 1609.Even Odd Tree.py ├── 1610.Maximum Number of Visible Points.py ├── 1611.Minimum One Bit Operations to Make Integers Zero.py ├── 1614.Maximum Nesting Depth of the Parentheses.py ├── 1615.Maximal Network Rank.py ├── 1616.Split Two Strings to Make Palindrome.py ├── 1617.Count Subtrees With Max Distance Between Cities.md ├── 1617.Count Subtrees With Max Distance Between Cities.py ├── 1619.Mean of Array After Removing Some Elements.py ├── 1620.Coordinate With Maximum Network Quality.py ├── 1621.Number of Sets of K Non-Overlapping Line Segments.py ├── 1622.Fancy Sequence.py ├── 1624.Largest Substring Between Two Equal Characters.py ├── 1625.Lexicographically Smallest String After Applying Operations.md ├── 1625.Lexicographically Smallest String After Applying Operations.py ├── 1626.Best Team With No Conflicts.py ├── 1627.Graph Connectivity With Threshold.py ├── 1629.Slowest Key.py ├── 1630.Arithmetic Subarrays.py ├── 1631.Path With Minimum Effort.py ├── 1632.Rank Transform of a Matrix.py ├── 1636.Sort Array by Increasing Frequency.py ├── 1637.Widest Vertical Area Between Two Points Containing No Points.py ├── 1638.Count Substrings That Differ by One Character.py ├── 1639.Number of Ways to Form a Target String Given a Dictionary.py ├── 1640.Check Array Formation Through Concatenation.py ├── 1641.Count Sorted Vowel Strings.py ├── 1642.Furthest Building You Can Reach.py ├── 1643.Kth Smallest Instructions.py ├── 1646.Get Maximum in Generated Array.py ├── 1647.Minimum Deletions to Make Character Frequencies Unique.py ├── 1648.Sell Diminishing-Valued Colored Balls.py ├── 1649.Create Sorted Array through Instructions.py ├── 1652.Defuse the Bomb.py ├── 1653.Minimum Deletions to Make String Balanced.py ├── 1654.Minimum Jumps to Reach Home.py ├── 1656.Design an Ordered Stream.py ├── 1657.Determine if Two Strings Are Close.py ├── 1658.Minimum Operations to Reduce X to Zero.py ├── 1659.Maximize Grid Happiness.md ├── 1659.Maximize Grid Happiness.py ├── 1662.Check If Two String Arrays are Equivalent.py ├── 1663.Smallest String With A Given Numeric Value.py ├── 1664.Ways to Make a Fair Array.2.py ├── 1664.Ways to Make a Fair Array.py ├── 1665.Minimum Initial Energy to Finish Tasks.py ├── 1668.Maximum Repeating Substring.py ├── 1669.Merge In Between Linked Lists.java ├── 1670.Design Front Middle Back Queue.java ├── 1671.Minimum Number of Removals to Make Mountain Array.py ├── 1672.Richest Customer Wealth.py ├── 1673.Find the Most Competitive Subsequence.py ├── 1674.Minimum Moves to Make Array Complementary.py ├── 1675.Minimize Deviation in Array.py ├── 1678.Goal Parser Interpretation.py ├── 1679.Max Number of K-Sum Pairs.py ├── 1680.Concatenation of Consecutive Binary Numbers.py ├── 1681.Minimum Incompatibility.py ├── 1684.Count the Number of Consistent Strings.py ├── 1685.Sum of Absolute Differences in a Sorted Array.py ├── 1686.Stone Game VI.py ├── 1687.Delivering Boxes from Storage to Ports.py ├── 1688.Count of Matches in Tournament.py ├── 1689.Partitioning Into Minimum Number Of Deci-Binary Numbers.py ├── 1690.Stone Game VII.(lru_cache).py ├── 1690.Stone Game VII.py ├── 1691.Maximum Height by Stacking Cuboids.py ├── 1694.Reformat Phone Number.py ├── 1695.Maximum Erasure Value.py ├── 1696.Jump Game VI.py ├── 1697.Checking Existence of Edge Length Limited Paths.py ├── 1700.Number of Students Unable to Eat Lunch.cpp ├── 1701.Average Waiting Time.java ├── 1702.Maximum Binary String After Change.java ├── 1704.Determine if String Halves Are Alike.py ├── 1705.Maximum Number of Eaten Apples.py ├── 1706.Where Will the Ball Fall.py ├── 1707.Maximum XOR With an Element From Array.py ├── 1710.Maximum Units on a Truck.py ├── 1711.Count Good Meals.py ├── 1712.Ways to Split Array Into Three Subarrays.py ├── 1713.Minimum Operations to Make a Subsequence.py ├── 1716.Calculate Money in Leetcode Bank.php ├── 1717.Maximum Score From Removing Substrings.py ├── 1718.Construct the Lexicographically Largest Valid Sequence.py ├── 1719.Number Of Ways To Reconstruct A Tree.py ├── 1720.Decode XORed Array.py ├── 1721.Swapping Nodes in a Linked List.py ├── 1722.Minimize Hamming Distance After Swap Operations.py ├── 1723.Find Minimum Time to Finish All Jobs.py ├── 1725.Number Of Rectangles That Can Form The Largest Square.py ├── 1726.Tuple with Same Product.py ├── 1727.Largest Submatrix With Rearrangements.py ├── 1728.Cat and Mouse II.py ├── 1732.Find the Highest Altitude.py ├── 1733.Minimum Number of People to Teach.py ├── 1734.Decode XORed Permutation.py ├── 1736.Latest Time by Replacing Hidden Digits.py ├── 1737.Change Minimum Characters to Satisfy One of Three Conditions.py ├── 1738.Find Kth Largest XOR Coordinate Value.py ├── 1739.Building Boxes.py ├── 1742.Maximum Number of Balls in a Box.py ├── 1743.Restore the Array From Adjacent Pairs.py ├── 1744.Can You Eat Your Favorite Candy on Your Favorite Day?.py ├── 1745.Palindrome Partitioning IV.py ├── 1748.Sum of Unique Elements.py ├── 1749.Maximum Absolute Sum of Any Subarray.py ├── 1750.Minimum Length of String After Deleting Similar Ends.py ├── 1751.Maximum Number of Events That Can Be Attended II.py ├── 1752.Check if Array Is Sorted and Rotated.py ├── 1753.Maximum Score From Removing Stones.(faster).py ├── 1753.Maximum Score From Removing Stones.py ├── 1754.Largest Merge Of Two Strings.py ├── 1755.Closest Subsequence Sum.py ├── 1758.Minimum Changes To Make Alternating Binary String.2.py ├── 1758.Minimum Changes To Make Alternating Binary String.py ├── 1759.Count Number of Homogenous Substrings.py ├── 1760.Minimum Limit of Balls in a Bag.py ├── 1761.Minimum Degree of a Connected Trio in a Graph.py ├── 1763.Longest Nice Substring.py ├── 1764.Form Array by Concatenating Subarrays of Another Array.py ├── 1765.Map of Highest Peak.py ├── 1766.Tree of Coprimes.py ├── 1768.Merge Strings Alternately.py ├── 1769.Minimum Number of Operations to Move All Balls to Each Box.py ├── 1770.Maximum Score from Performing Multiplication Operations.py ├── 1771.Maximize Palindrome Length From Subsequences.py ├── 1773.Count Items Matching a Rule.py ├── 1774.Closest Dessert Cost.py ├── 1775.Equal Sum Arrays With Minimum Number of Operations.2.py ├── 1775.Equal Sum Arrays With Minimum Number of Operations.py ├── 1776.Car Fleet II.py ├── 1779.Find Nearest Point That Has the Same X or Y Coordinate.java ├── 1780.Check if Number is a Sum of Powers of Three.py ├── 1781.Sum of Beauty of All Substrings.py ├── 1782.Count Pairs Of Nodes.py ├── 1784.Check if Binary String Has at Most One Segment of Ones.py ├── 1785.Minimum Elements to Add to Form a Given Sum.py ├── 1786.Number of Restricted Paths From First to Last Node.py ├── 1787.Make the XOR of All Segments Equal to Zero.py ├── 1790.Check if One String Swap Can Make Strings Equal.py ├── 1791.Find Center of Star Graph.2.py ├── 1791.Find Center of Star Graph.py ├── 1792.Maximum Average Pass Ratio.py ├── 1793.Maximum Score of a Good Subarray.py ├── 1796.Second Largest Digit in a String.java ├── 1797.Design Authentication Manager.py ├── 1798.Maximum Number of Consecutive Values You Can Make.java ├── 1799.Maximize Score After N Operations.py ├── 1800.Maximum Ascending Subarray Sum.py ├── 1801.Number of Orders in the Backlog.py ├── 1802.Maximum Value at a Given Index in a Bounded Array.py ├── 1803.Count Pairs With XOR in a Range.py ├── 1805.Number of Different Integers in a String.py ├── 1806.Minimum Number of Operations to Reinitialize a Permutation.py ├── 1807.Evaluate the Bracket Pairs of a String.py ├── 1808.Maximize Number of Nice Divisors.py ├── 1812.Determine Color of a Chessboard Square.java ├── 1813.Sentence Similarity III.py ├── 1814.Count Nice Pairs in an Array.py ├── 1816.Truncate Sentence.py ├── 1817.Finding the Users Active Minutes.py ├── 1818.Minimum Absolute Sum Difference.py ├── 1819.Number of Different Subsequences GCDs.py ├── 1822.Sign of the Product of an Array.py ├── 1823.Find the Winner of the Circular Game.1.py ├── 1823.Find the Winner of the Circular Game.2.py ├── 1824.Minimum Sideway Jumps.py ├── 1825.Finding MK Average.2.py ├── 1825.Finding MK Average.py ├── 1827.Minimum Operations to Make the Array Increasing.py ├── 1828.Queries on Number of Points Inside a Circle.py ├── 1829.Maximum XOR for Each Query.py ├── 1830.Minimum Number of Operations to Make String Sorted.py ├── 1832.Check if the Sentence Is Pangram.py ├── 1833.Maximum Ice Cream Bars.py ├── 1834.Single-Threaded CPU.py ├── 1835.Find XOR Sum of All Pairs Bitwise AND.py ├── 1837.Sum of Digits in Base K.py ├── 1838.Frequency of the Most Frequent Element.py ├── 1839.Longest Substring Of All Vowels in Order.py ├── 1840.Maximum Building Height.py ├── 1844.Replace All Digits with Characters.c ├── 1845.Seat Reservation Manager.py ├── 1846.Maximum Element After Decreasing and Rearranging.py ├── 1847.Closest Room.py ├── 1848.Minimum Distance to the Target Element.py ├── 1849.Splitting a String Into Descending Consecutive Values.py ├── 1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number.py ├── 1851.Minimum Interval to Include Each Query.py ├── 1854.Maximum Population Year.2.py ├── 1854.Maximum Population Year.py ├── 1855.Maximum Distance Between a Pair of Values.py ├── 1856.Maximum Subarray Min-Product.2.(monotonic stack).py ├── 1856.Maximum Subarray Min-Product.py ├── 1857.Largest Color Value in a Directed Graph.py ├── 1859.Sorting the Sentence.py ├── 1860.Incremental Memory Leak.py ├── 1861.Rotating the Box.py ├── 1862.Sum of Floored Pairs.py ├── 1863.Sum of All Subset XOR Totals.py ├── 1864.Minimum Number of Swaps to Make the Binary String Alternating.py ├── 1865.Finding Pairs With a Certain Sum.py ├── 1866.Number of Ways to Rearrange Sticks With K Sticks Visible.py ├── 1869.Longer Contiguous Segments of Ones than Zeros.py ├── 1870.Minimum Speed to Arrive on Time.py ├── 1871.Jump Game VII.py ├── 1872.Stone Game VIII.py ├── 1876.Substrings of Size Three with Distinct Characters.c ├── 1877.Minimize Maximum Pair Sum in Array.java ├── 1878.Get Biggest Three Rhombus Sums in a Grid.py ├── 1879.Minimum XOR Sum of Two Arrays.py ├── 1880.Check if Word Equals Summation of Two Words.py ├── 1881.Maximum Value after Insertion.py ├── 1882.Process Tasks Using Servers.py ├── 1883.Minimum Skips to Arrive at Meeting On Time.py ├── 1884.Egg Drop With 2 Eggs and N Floors.2.c ├── 1884.Egg Drop With 2 Eggs and N Floors.c ├── 1886.Determine Whether Matrix Can Be Obtained By Rotation.py ├── 1887.Reduction Operations to Make the Array Elements Equal.py ├── 1888.Minimum Number of Flips to Make the Binary String Alternating.py ├── 1889.Minimum Space Wasted From Packaging.py ├── 1893.Check if All the Integers in a Range Are Covered.ts ├── 1894.Find the Student that Will Replace the Chalk.ts ├── 1895.Largest Magic Square.py ├── 1896.Minimum Cost to Change the Final Value of Expression.ts ├── 1897.Redistribute Characters to Make All Strings Equal.py ├── 1898.Maximum Number of Removable Characters.py ├── 1899.Merge Triplets to Form Target Triplet.py ├── 1900.The Earliest and Latest Rounds Where Players Compete.py ├── 1901.Find a Peak Element II.py ├── 1903.Largest Odd Number in String.py ├── 1904.The Number of Full Rounds You Have Played.py ├── 1904.The Number of Full Rounds You Have Played.ts ├── 1905.Count Sub Islands.py ├── 1906.Minimum Absolute Difference Queries.py ├── 1909.Remove One Element to Make the Array Strictly Increasing.js ├── 1910.Remove All Occurrences of a Substring.js ├── 1911.Maximum Alternating Subsequence Sum.js ├── 1912.Design Movie Rental System.py ├── 1913.Maximum Product Difference Between Two Pairs.py ├── 1914.Cyclically Rotating a Grid.py ├── 1915.Number of Wonderful Substrings.py ├── 1920.Build Array from Permutation.py ├── 1921.Eliminate Maximum Number of Monsters.py ├── 1922.Count Good Numbers.py ├── 1923.Longest Common Subpath.py ├── 1925.Count Square Sum Triples.ts ├── 1926.Nearest Exit from Entrance in Maze.ts ├── 1927.Sum Game.ts ├── 1928.Minimum Cost to Reach Destination in Time.py ├── 1929.Concatenation of Array.py ├── 1930.Unique Length-3 Palindromic Subsequences.py ├── 1931.Painting a Grid With Three Different Colors.py ├── 1932.Merge BSTs to Create Single BST.py ├── 1933.Check if String Is Decomposable Into Value-Equal Substrings.ts ├── 1935.Maximum Number of Words You Can Type.ts ├── 1936.Add Minimum Number of Rungs.py ├── 1940.Longest Common Subsequence Between Sorted Arrays.py ├── 1941.Check if All Characters Have Equal Number of Occurrences.py ├── 1942.The Number of the Smallest Unoccupied Chair.py ├── 1950.Maximum of Minimum Values in All Subarrays.py ├── 1952.Three Divisors.1.py ├── 1952.Three Divisors.2.py ├── 1953.Maximum Number of Weeks for Which You Can Work.py ├── 1954.Minimum Garden Perimeter to Collect Enough Apples.py ├── 1955.Count Number of Special Subsequences.py ├── 1957.Delete Characters to Make Fancy String.py ├── 1958.Check if Move is Legal.py ├── 1960.Maximum Product of the Length of Two Palindromic Substrings.ts ├── 1961.Check If String Is a Prefix of Array.py ├── 1962.Remove Stones to Minimize the Total.py ├── 1963.Minimum Number of Swaps to Make the String Balanced.py ├── 1964.Find the Longest Valid Obstacle Course at Each Position.py ├── 1966.Binary Searchable Numbers in an Unsorted Array.py ├── 1967.Number of Strings That Appear as Substrings in Word.py ├── 1968.Array With Elements Not Equal to Average of Neighbors.py ├── 1969.Minimum Non-Zero Product of the Array Elements.py ├── 1970.Last Day Where You Can Still Cross.py ├── 1971.Find if Path Exists in Graph.py ├── 1973.Count Nodes Equal to Sum of Descendants.py ├── 1974.Minimum Time to Type Word Using Special Typewriter.c ├── 1975.Maximum Matrix Sum.java ├── 1976.Number of Ways to Arrive at Destination.py ├── 1979.Find Greatest Common Divisor of Array.py ├── 1980.Find Unique Binary String.py ├── 1981.Minimize the Difference Between Target and Chosen Elements.py ├── 1982.Find Array Given Subset Sums.py ├── 1984.Minimum Difference Between Highest and Lowest of K Scores.js ├── 1985.Find the Kth Largest Integer in the Array.py ├── 1986.Minimum Number of Work Sessions to Finish the Tasks.py ├── 1987.Number of Unique Good Subsequences.js ├── 1991.Find the Middle Index in Array.js ├── 1992.Find All Groups of Farmland.py ├── 1993.Operations on Tree.py ├── 1994.The Number of Good Subsets.py ├── 1995.Count Special Quadruplets.py ├── 1996.The Number of Weak Characters in the Game.py ├── 1997.First Day Where You Have Been in All the Rooms.py ├── 1998.GCD Sort of an Array.py ├── 2000.Reverse Prefix of Word.py └── README.md ├── 2001-2500 ├── 2001.Number of Pairs of Interchangeable Rectangles.py ├── 2002.Maximum Product of the Length of Two Palindromic Subsequences.py ├── 2006.Count Number of Pairs With Absolute Difference K.py ├── 2007.Find Original Array From Doubled Array.py ├── 2008.Maximum Earnings From Taxi.c ├── 2009.Minimum Number of Operations to Make Array Continuous.c ├── 2011.Final Value of Variable After Performing Operations.c ├── 2012.Sum of Beauty in the Array.c ├── 2013.Detect Squares.java ├── 2016.Maximum Difference Between Increasing Elements.py ├── 2017.Grid Game.py ├── 2018.Check if Word Can Be Placed In Crossword.py ├── 2019.The Score of Students Solving Math Expression.py ├── 2022.Convert 1D Array Into 2D Array.ts ├── 2023.Number of Pairs of Strings With Concatenation Equal to Target.py ├── 2024.Maximize the Confusion of an Exam.ts ├── 2027.Minimum Moves to Convert String.ts ├── 2028.Find Missing Observations.ts ├── 2029.Stone Game IX.ts ├── 2032.Two Out of Three.2.py ├── 2032.Two Out of Three.py ├── 2033.Minimum Operations to Make a Uni-Value Grid.py ├── 2034.Stock Price Fluctuation.py ├── 2035.Partition Array Into Two Arrays to Minimize Sum Difference.py ├── 2037.Minimum Number of Moves to Seat Everyone.rb ├── 2038.Remove Colored Pieces if Both Neighbors are the Same Color.ts ├── 2039.The Time When the Network Becomes Idle.py ├── 2040.Kth Smallest Product of Two Sorted Arrays.py ├── 2042.Check if Numbers Are Ascending in a Sentence.py ├── 2042.Check if Numbers Are Ascending in a Sentence.rb ├── 2043.Simple Bank System.java ├── 2044.Count Number of Maximum Bitwise-OR Subsets.ts ├── 2045.Second Minimum Time to Reach Destination.py ├── 2047.Number of Valid Words in a Sentence.py ├── 2047.Number of Valid Words in a Sentence.ts ├── 2048.Next Greater Numerically Balanced Number.py ├── 2049.Count Nodes With the Highest Score.py ├── 2050.Parallel Courses III.py ├── 2053.Kth Distinct String in an Array.ts ├── 2054.Two Best Non-Overlapping Events.py ├── 2055.Plates Between Candles.py ├── 2055.Plates Between Candles.ts ├── 2056.Number of Valid Move Combinations On Chessboard.py ├── 2057.Smallest Index With Equal Value.ts ├── 2058.Find the Minimum and Maximum Number of Nodes Between Critical Points.ts ├── 2059.Minimum Operations to Convert Number.ts ├── 2060.Check if an Original String Exists Given Two Encoded Strings.py ├── 2062.Count Vowel Substrings of a String.py ├── 2062.Count Vowel Substrings of a String.ts ├── 2063.Vowels of All Substrings.ts ├── 2064.Minimized Maximum of Products Distributed to Any Store.ts ├── 2065.Maximum Path Quality of a Graph.py ├── 2068.Check Whether Two Strings are Almost Equivalent.py ├── 2069.Walking Robot Simulation II.py ├── 2070.Most Beautiful Item for Each Query.py ├── 2071.Maximum Number of Tasks You Can Assign.py ├── 2073.Time Needed to Buy Tickets.ts ├── 2074.Reverse Nodes in Even Length Groups.ts ├── 2075.Decode the Slanted Ciphertext.ts ├── 2076.Process Restricted Friend Requests.ts ├── 2078.Two Furthest Houses With Different Colors.ts ├── 2079.Watering Plants.ts ├── 2080.Range Frequency Queries.py ├── 2081.Sum of k-Mirror Numbers.py ├── 2085.Count Common Words With One Occurrence.ts ├── 2086.Minimum Number of Food Buckets to Feed the Hamsters.ts ├── 2087.Minimum Cost Homecoming of a Robot in a Grid.ts ├── 2088.Count Fertile Pyramids in a Land.ts ├── 2089.Find Target Indices After Sorting Array.ts ├── 2090.K Radius Subarray Averages.ts ├── 2091.Removing Minimum and Maximum From Array.ts ├── 2092.Find All People With Secret.ts ├── 2094.Finding 3-Digit Even Numbers.ts ├── 2095.Delete the Middle Node of a Linked List.ts ├── 2096.Step-By-Step Directions From a Binary Tree Node to Another.ts ├── 2097.Valid Arrangement of Pairs.ts ├── 2099.Find Subsequence of Length K With the Largest Sum.ts ├── 2100.Find Good Days to Rob the Bank.ts ├── 2101.Detonate the Maximum Bombs.ts ├── 2102.Sequentially Ordinal Rank Tracker.java ├── 2103.Rings and Rods.ts ├── 2104.Sum of Subarray Ranges.ts ├── 2105.Watering Plants II.ts ├── 2106.Maximum Fruits Harvested After at Most K Steps.java ├── 2108.Find First Palindromic String in the Array.ts ├── 2109.Adding Spaces to a String.ts ├── 2110.Number of Smooth Descent Periods of a Stock.ts ├── 2111.Minimum Operations to Make the Array K-Increasing.py ├── 2114.Maximum Number of Words Found in Sentences.ts ├── 2115.Find All Possible Recipes from Given Supplies.ts ├── 2116.Check if a Parentheses String Can Be Valid.ts ├── 2117.Abbreviating the Product of a Range.(cheat).py ├── 2119.A Number After a Double Reversal.ts ├── 2120.Execution of All Suffix Instructions Staying in a Grid.ts ├── 2124.Check if All A's Appears Before All B's.ts ├── 2125.Number of Laser Beams in a Bank.py ├── 2125.Number of Laser Beams in a Bank.ts ├── 2126.Destroying Asteroids.java ├── 2127.Maximum Employees to Be Invited to a Meeting.py ├── 2129.Capitalize the Title.java ├── 2130.Maximum Twin Sum of a Linked List.ts ├── 2131.Longest Palindrome by Concatenating Two Letter Words.ts ├── 2133.Check if Every Row and Column Contains All Numbers.py ├── 2134.Minimum Swaps to Group All 1's Together II.py ├── 2135.Count Words Obtained After Adding a Letter.py ├── 2136.Earliest Possible Day of Full Bloom.py ├── 2138.Divide a String Into Groups of Size k.py ├── 2139.Minimum Moves to Reach Target Score.ts ├── 2140.Solving Questions With Brainpower.py ├── 2141.Maximum Running Time of N Computers.py ├── 2144.Minimum Cost of Buying Candies With Discount.ts ├── 2145.Count the Hidden Sequences.ts ├── 2146.K Highest Ranked Items Within a Price Range.ts ├── 2147.Number of Ways to Divide a Long Corridor.ts ├── 2148.Count Elements With Strictly Smaller and Greater Elements.ts ├── 2149.Rearrange Array Elements by Sign.2.ts ├── 2149.Rearrange Array Elements by Sign.ts ├── 2150.Find All Lonely Numbers in the Array.ts ├── 2151.Maximum Good People Based on Statements.py ├── 2154.Keep Multiplying Found Values by Two.ts ├── 2155.All Divisions With the Highest Score of a Binary Array.ts ├── 2156.Find Substring With Given Hash Value.ts ├── 2157.Groups of Strings.ts ├── 2160.Minimum Sum of Four Digit Number After Splitting Digits.ts ├── 2161.Partition Array According to Given Pivot.ts ├── 2162.Minimum Cost to Set Cooking Time.ts ├── 2163.Minimum Difference in Sums After Removal of Elements.java ├── 2164.Sort Even and Odd Indices Independently.py ├── 2165.Smallest Value of the Rearranged Number.py ├── 2166.Design Bitset.(BitMaps).java ├── 2166.Design Bitset.2.(HashSet).java ├── 2167.Minimum Time to Remove All Cars Containing Illegal Goods.2.(DP).java ├── 2167.Minimum Time to Remove All Cars Containing Illegal Goods.ts ├── 2169.Count Operations to Obtain Zero.java ├── 2170.Minimum Operations to Make the Array Alternating.py ├── 2171.Removing Minimum Number of Magic Beans.ts ├── 2172.Maximum AND Sum of Array.ts ├── 2176.Count Equal and Divisible Pairs in an Array.ts ├── 2177.Find Three Consecutive Integers That Sum to a Given Number.ts ├── 2178.Maximum Split of Positive Even Integers.ts ├── 2179.Count Good Triplets in an Array.ts ├── 2180.Count Integers With Even Digit Sum.ts ├── 2181.Merge Nodes in Between Zeros.ts ├── 2182.Construct String With Repeat Limit.ts ├── 2183.Count Array Pairs Divisible by K.ts ├── 2185.Counting Words With a Given Prefix.ts ├── 2186.Minimum Number of Steps to Make Two Strings Anagram II.py ├── 2187.Minimum Time to Complete Trips.ts ├── 2188.Minimum Time to Finish the Race.ts ├── 2190.Most Frequent Number Following Key In an Array.ts ├── 2191.Sort the Jumbled Numbers.ts ├── 2192.All Ancestors of a Node in a Directed Acyclic Graph.ts ├── 2193.Minimum Number of Moves to Make Palindrome.2.ts ├── 2193.Minimum Number of Moves to Make Palindrome.ts ├── 2194.Cells in a Range on an Excel Sheet.py ├── 2195.Append K Integers With Minimal Sum.py ├── 2196.Create Binary Tree From Descriptions.ts ├── 2197.Replace Non-Coprime Numbers in Array.py ├── 2200.Find All K-Distant Indices in an Array.ts ├── 2201.Count Artifacts That Can Be Extracted.py ├── 2202.Maximize the Topmost Element After K Moves.py ├── 2203.Minimum Weighted Subgraph With the Required Paths.py ├── 2206.Divide Array Into Equal Pairs.ts ├── 2207.Maximize Number of Subsequences in a String.ts ├── 2208.Minimum Operations to Halve Array Sum.ts ├── 2209.Minimum White Tiles After Covering With Carpets.ts ├── 2210.Count Hills and Valleys in an Array.py ├── 2211.Count Collisions on a Road.ts ├── 2212.Maximum Points in an Archery Competition.ts ├── 2213.Longest Substring of One Repeating Character.py ├── 2215.Find the Difference of Two Arrays.py ├── 2216.Minimum Deletions to Make Array Beautiful.ts ├── 2217.Find Palindrome With Fixed Length.ts ├── 2218.Maximum Value of K Coins From Piles.py ├── 2219.Maximum Sum Score of Array.ts ├── 2220.Minimum Bit Flips to Convert Number.ts ├── 2221.Find Triangular Sum of an Array.py ├── 2222.Number of Ways to Select Buildings.ts ├── 2224.Minimum Number of Operations to Convert Time.py ├── 2225.Find Players With Zero or One Losses.py ├── 2226.Maximum Candies Allocated to K Children.py ├── 2227.Encrypt and Decrypt Strings.py ├── 2231.Largest Number After Digit Swaps by Parity.ts ├── 2232.Minimize Result by Adding Parentheses to Expression.py ├── 2233.Maximum Product After K Increments.py ├── 2234.Maximum Total Beauty of the Gardens.py ├── 2235.Add Two Integers.ts ├── 2236.Root Equals Sum of Children.ts ├── 2239.Find Closest Number to Zero.ts ├── 2240.Number of Ways to Buy Pens and Pencils.ts ├── 2241.Design an ATM Machine.ts ├── 2242.Maximum Score of a Node Sequence.ts ├── 2243.Calculate Digit Sum of a String.ts ├── 2244.Minimum Rounds to Complete All Tasks.py ├── 2245.Maximum Trailing Zeros in a Cornered Path.py ├── 2246.Longest Path With Different Adjacent Characters.ts ├── 2248.Intersection of Multiple Arrays.py ├── 2249.Count Lattice Points Inside a Circle.py ├── 2250.Count Number of Rectangles Containing Each Point.py ├── 2251.Number of Flowers in Full Bloom.py ├── 2255.Count Prefixes of a Given String.ts ├── 2256.Minimum Average Difference.ts ├── 2257.Count Unguarded Cells in the Grid.ts ├── 2258.Escape the Spreading Fire.py ├── 2259.Remove Digit From Number to Maximize Result.ts ├── 2260.Minimum Consecutive Cards to Pick Up.ts ├── 2261.K Divisible Elements Subarrays.ts ├── 2262.Total Appeal of A String.ts ├── 2264.Largest 3-Same-Digit Number in String.py ├── 2265.Count Nodes Equal to Average of Subtree.ts ├── 2266.Count Number of Texts.py ├── 2267.Check if There Is a Valid Parentheses String Path.py ├── 2269.Find the K-Beauty of a Number.ts ├── 2270.Number of Ways to Split Array.ts ├── 2271.Maximum White Tiles Covered by a Carpet.ts ├── 2272.Substring With Largest Variance.ts ├── 2273.Find Resultant Array After Removing Anagrams.py ├── 2274.Maximum Consecutive Floors Without Special Floors.py ├── 2275.Largest Combination With Bitwise AND Greater Than Zero.py ├── 2276.Count Integers in Intervals.py ├── 2278.Percentage of Letter in String.py ├── 2279.Maximum Bags With Full Capacity of Rocks.py ├── 2280.Minimum Lines to Represent a Line Chart.py ├── 2281.Sum of Total Strength of Wizards.py ├── 2283.Check if Number Has Equal Digit Count and Digit Value.py ├── 2284.Sender With Largest Word Count.ts ├── 2285.Maximum Total Importance of Roads.ts ├── 2286.Booking Concert Tickets in Groups.ts ├── 2287.Rearrange Characters to Make Target String.py ├── 2288.Apply Discount to Prices.ts ├── 2289.Steps to Make Array Non-decreasing.js ├── 2289.Steps to Make Array Non-decreasing.py ├── 2290.Minimum Obstacle Removal to Reach Corner.py ├── 2293.Min Max Game.ts ├── 2294.Partition Array Such That Maximum Difference Is K.ts ├── 2295.Replace Elements in an Array.java ├── 2296.Design a Text Editor.java ├── 2299.Strong Password Checker II.ts ├── 2300.Successful Pairs of Spells and Potions.py ├── 2301.Match Substring After Replacement.ts ├── 2302.Count Subarrays With Score Less Than K.ts ├── 2303.Calculate Amount Paid in Taxes.ts ├── 2304.Minimum Path Cost in a Grid.py ├── 2305.Fair Distribution of Cookies.ts ├── 2306.Naming a Company.py ├── 2309.Greatest English Letter in Upper and Lower Case.py ├── 2310.Sum of Numbers With Units Digit K.ts ├── 2311.Longest Binary Subsequence Less Than or Equal to K.ts ├── 2312.Selling Pieces of Wood.py ├── 2315.Count Asterisks.ts ├── 2316.Count Unreachable Pairs of Nodes in an Undirected Graph.ts ├── 2317.Maximum XOR After Operations.ts ├── 2318.Number of Distinct Roll Sequences.py ├── 2319.Check if Matrix Is X-Matrix.ts ├── 2320.Count Number of Ways to Place Houses.c ├── 2321.Maximum Score Of Spliced Array.ts ├── 2325.Decode the Message.ts ├── 2326.Spiral Matrix IV.ts ├── 2327.Number of People Aware of a Secret.c ├── 2328.Number of Increasing Paths in a Grid.py ├── 2331.Evaluate Boolean Binary Tree.c ├── 2332.The Latest Time to Catch a Bus.c ├── 2333.Minimum Sum of Squared Difference.c ├── 2334.Subarray With Elements Greater Than Varying Threshold.(monotone stack).c ├── 2334.Subarray With Elements Greater Than Varying Threshold.(union find).py ├── 2341.Maximum Number of Pairs in Array.py ├── 2342.Max Sum of a Pair With Equal Sum of Digits.py ├── 2343.Query Kth Smallest Trimmed Number.py ├── 2344.Minimum Deletions to Make Array Divisible.py ├── 2347.Best Poker Hand.ts ├── 2348.Number of Zero-Filled Subarrays.ts ├── 2349.Design a Number Container System.py ├── 2350.Shortest Impossible Sequence of Rolls.ts ├── 2351.First Letter to Appear Twice.ts ├── 2352.Equal Row and Column Pairs.py ├── 2353.Design a Food Rating System.py ├── 2354.Number of Excellent Pairs.py ├── 2357.Make Array Zero by Subtracting Equal Amounts.ts ├── 2358.Maximum Number of Groups Entering a Competition.ts ├── 2359.Find Closest Node to Given Two Nodes.ts ├── 2360.Longest Cycle in a Graph.ts ├── 2363.Merge Similar Items.ts ├── 2364.Count Number of Bad Pairs.ts ├── 2365.Task Scheduler II.ts ├── 2366.Minimum Replacements to Sort the Array.ts ├── 2367.Number of Arithmetic Triplets.2.ts ├── 2367.Number of Arithmetic Triplets.ts ├── 2368.Reachable Nodes With Restrictions.py ├── 2369.Check if There is a Valid Partition For The Array.py ├── 2370.Longest Ideal Subsequence.py ├── 2373.Largest Local Values in a Matrix.py ├── 2374.Node With Highest Edge Score.py ├── 2375.Construct Smallest Number From DI String.py ├── 2376.Count Special Integers.py ├── 2379.Minimum Recolors to Get K Consecutive Black Blocks.ts ├── 2380.Time Needed to Rearrange a Binary String.ts ├── 2381.Shifting Letters II.ts ├── 2382.Maximum Segment Sum After Removals.(priority queue).py ├── 2382.Maximum Segment Sum After Removals.(union find).ts ├── 2383.Minimum Hours of Training to Win a Competition.ts ├── 2384.Largest Palindromic Number.ts ├── 2385.Amount of Time for Binary Tree to Be Infected.ts ├── 2386.Find the K-Sum of an Array.py ├── 2389.Longest Subsequence With Limited Sum.py ├── 2390.Removing Stars From a String.ts ├── 2391.Minimum Amount of Time to Collect Garbage.ts ├── 2392.Build a Matrix With Conditions.java ├── 2395.Find Subarrays With Equal Sum.java ├── 2396.Strictly Palindromic Number.java ├── 2397.Maximum Rows Covered by Columns.ts ├── 2398.Maximum Number of Robots Within Budget.java ├── 2399.Check Distances Between Same Letters.java ├── 2400.Number of Ways to Reach a Position After Exactly k Steps.py ├── 2401.Longest Nice Subarray.java ├── 2402.Meeting Rooms III.py ├── 2404.Most Frequent Even Element.py ├── 2405.Optimal Partition of String.c ├── 2406.Divide Intervals Into Minimum Number of Groups.java ├── 2407.Longest Increasing Subsequence II.java ├── 2409.Count Days Spent Together.c ├── 2410.Maximum Matching of Players With Trainers.java ├── 2411.Smallest Subarrays With Maximum Bitwise OR.java ├── 2412.Minimum Money Required Before Transactions.ts ├── 2413.Smallest Even Multiple.cpp ├── 2414.Length of the Longest Alphabetical Continuous Substring.c ├── 2415.Reverse Odd Levels of Binary Tree.py ├── 2415.Reverse Odd Levels of Binary Tree.ts ├── 2416.Sum of Prefix Scores of Strings.py ├── 2418.Sort the People.py ├── 2419.Longest Subarray With Maximum Bitwise AND.java ├── 2420.Find All Good Indices.java ├── 2421.Number of Good Paths.py ├── 2423.Remove Letter To Equalize Frequency.py ├── 2424.Longest Uploaded Prefix.java ├── 2425.Bitwise XOR of All Pairings.c ├── 2426.Number of Pairs Satisfying Inequality.py ├── 2427.Number of Common Factors.c ├── 2428.Maximum Sum of an Hourglass.c ├── 2429.Minimize XOR.c ├── 2430.Maximum Deletions on a String.py ├── 2432.The Employee That Worked on the Longest Task.ts ├── 2433.Find The Original Array of Prefix Xor.ts ├── 2434.Using a Robot to Print the Lexicographically Smallest String.ts ├── 2435.Paths in Matrix Whose Sum Is Divisible by K.py ├── 2437.Number of Valid Clock Times.ts ├── 2438.Range Product Queries of Powers.ts ├── 2439.Minimize Maximum of Array.ts ├── 2441.Largest Positive Integer That Exists With Its Negative.py ├── 2442.Count Number of Distinct Integers After Reverse Operations.py ├── 2443.Sum of Number and Its Reverse.ts ├── 2444.Count Subarrays With Fixed Bounds.ts ├── 2446.Determine if Two Events Have Conflict.ts ├── 2447.Number of Subarrays With GCD Equal to K.ts ├── 2448.Minimum Cost to Make Array Equal.c ├── 2448.Minimum Cost to Make Array Equal.py ├── 2449.Minimum Number of Operations to Make Arrays Similar.ts ├── 2451.Odd String Difference.ts ├── 2452.Words Within Two Edits of Dictionary.py ├── 2453.Destroy Sequential Targets.ts ├── 2454.Next Greater Element IV.ts ├── 2455.Average Value of Even Numbers That Are Divisible by Three.py ├── 2456.Most Popular Video Creator.py ├── 2457.Minimum Addition to Make Integer Beautiful.py ├── 2458.Height of Binary Tree After Subtree Removal Queries.py ├── 2460.Apply Operations to an Array.ts ├── 2461.Maximum Sum of Distinct Subarrays With Length K.ts ├── 2462.Total Cost to Hire K Workers.java ├── 2465.Number of Distinct Averages.ts ├── 2466.Count Ways To Build Good Strings.ts ├── 2467.Most Profitable Path in a Tree.ts ├── 2468.Split Message Based on Limit.ts ├── 2469.Convert the Temperature.ts ├── 2470.Number of Subarrays With LCM Equal to K.ts ├── 2471.Minimum Number of Operations to Sort a Binary Tree by Level.py ├── 2472.Maximum Number of Non-overlapping Palindrome Substrings.py ├── 2475.Number of Unequal Triplets in Array.py ├── 2476.Closest Nodes Queries in a Binary Search Tree.(timeout due to directly searching on BST).ts ├── 2476.Closest Nodes Queries in a Binary Search Tree.py ├── 2477.Minimum Fuel Cost to Report to the Capital.ts ├── 2478.Number of Beautiful Partitions.py ├── 2481.Minimum Cuts to Divide a Circle.ts ├── 2482.Difference Between Ones and Zeros in Row and Column.ts ├── 2483.Minimum Penalty for a Shop.ts ├── 2484.Count Palindromic Subsequences.py ├── 2484.Count Palindromic Subsequences.ts ├── 2485.Find the Pivot Integer.ts ├── 2486.Append Characters to String to Make Subsequence.ts ├── 2487.Remove Nodes From Linked List.ts ├── 2488.Count Subarrays With Median K.ts ├── 2490.Circular Sentence.py ├── 2491.Divide Players Into Teams of Equal Skill.ts ├── 2492.Minimum Score of a Path Between Two Cities.ts ├── 2493.Divide Nodes Into the Maximum Number of Groups.py ├── 2496.Maximum Value of a String in an Array.ts ├── 2497.Maximum Star Sum of a Graph.ts ├── 2498.Frog Jump II.ts ├── 2499.Minimum Total Cost to Make Arrays Unequal.ts ├── 2500.Delete Greatest Value in Each Row.ts └── README.md ├── 2501-3000 ├── 2501.Longest Square Streak in an Array.ts ├── 2502.Design Memory Allocator.ts ├── 2503.Maximum Number of Points From Grid Queries.ts ├── 2506.Count Pairs Of Similar Strings.ts ├── 2507.Smallest Value After Replacing With Sum of Prime Factors.ts ├── 2508.Add Edges to Make Degrees of All Nodes Even.ts ├── 2509.Cycle Length Queries in a Tree.ts ├── 2511.Maximum Enemy Forts That Can Be Captured.java ├── 2512.Reward Top K Students.rb ├── 2514.Count Anagrams.rb ├── 2515.Shortest Distance to Target String in a Circular Array.py ├── 2516.Take K of Each Character From Left and Right.py ├── 2517.Maximum Tastiness of Candy Basket.py ├── 2518.Number of Great Partitions.py ├── 2520.Count the Digits That Divide a Number.py ├── 2521.Distinct Prime Factors of Product of Array.py ├── 2522.Partition String Into Substrings With Values at Most K.py ├── 2523.Closest Prime Numbers in Range.py ├── 2525.Categorize Box According to Criteria.php ├── 2526.Find Consecutive Integers from a Data Stream.php ├── 2526.Find Consecutive Integers from a Data Stream.rb ├── 2527.Find Xor-Beauty of Array.php ├── 2528.Maximize the Minimum Powered City.php ├── 2529.Maximum Count of Positive Integer and Negative Integer.py ├── 2530.Maximal Score After Applying K Operations.py ├── 2531.Make Number of Distinct Characters Equal.py ├── 2532.Time to Cross a Bridge.py ├── 2535.Difference Between Element Sum and Digit Sum of an Array.php ├── 2536.Increment Submatrices by One.java ├── 2537.Count the Number of Good Subarrays.php ├── 2540.Minimum Common Value.php ├── 2541.Minimum Operations to Make Array Equal II.php ├── 2542.Maximum Subsequence Score.java ├── 2543.Check if Point Is Reachable.php ├── 2544.Alternating Digit Sum.php ├── 2549.Count Distinct Numbers on Board.php ├── 2550.Count Collisions of Monkeys on a Polygon.py ├── 2553.Separate the Digits in an Array.ts ├── 2554.Maximum Number of Integers to Choose From a Range I.rb ├── 2558.Take Gifts From the Richest Pile.py ├── 2559.Count Vowel Strings in Ranges.ts ├── 2560.House Robber IV.ts ├── 2561.Rearranging Fruits.py ├── 2561.Rearranging Fruits.ts ├── 2562.Find the Array Concatenation Value.py ├── 2563.Count the Number of Fair Pairs.py ├── 2564.Substring XOR Queries.py ├── 2565.Subsequence With the Minimum Score.py ├── 2574.Left and Right Sum Differences.ts ├── 2575.Find the Divisibility Array of a String.java ├── 2576.Find the Maximum Number of Marked Indices.py ├── 2577.Minimum Time to Visit a Cell In a Grid.py ├── 2582.Pass the Pillow.ts ├── 2583.Kth Largest Sum in a Binary Tree.py ├── 2584.Split the Array to Make Coprime Products.py ├── 2585.Number of Ways to Earn Points.py ├── 2586.Count the Number of Vowel Strings in Range.py ├── 2587.Rearrange Array to Maximize Prefix Score.cpp ├── 2588.Count the Number of Beautiful Subarrays.ts ├── 2589.Minimum Time to Complete All Tasks.py ├── 2591.Distribute Money to Maximum Children.c ├── 2592.Maximize Greatness of an Array.php ├── 2593.Find Score of an Array After Marking All Elements.py ├── 2594.Minimum Time to Repair Cars.py ├── 2595.Number of Even and Odd Bits.java ├── 2596.Check Knight Tour Configuration.c ├── 2597.The Number of Beautiful Subsets.py ├── 2598.Smallest Missing Non-negative Integer After Operations.rb ├── 2600.K Items With the Maximum Sum.c ├── 2601.Prime Subtraction Operation.py ├── 2602.Minimum Operations to Make All Array Elements Equal.py ├── 2603.Collect Coins in a Tree.py ├── 2609.Find the Longest Balanced Substring of a Binary String.py ├── 2610.Convert an Array Into a 2D Array With Conditions.py ├── 2611.Mice and Cheese.py ├── 2614.Prime In Diagonal.py ├── 2615.Sum of Distances.py ├── 2616.Minimize the Maximum Difference of Pairs.py ├── 2617.Minimum Number of Visited Cells in a Grid.(BFS).py ├── 2617.Minimum Number of Visited Cells in a Grid.(DP and Segment Tree).py ├── 2618.Check if Object Instance of Class.ts ├── 2619.Array Prototype Last.ts ├── 2620.Counter.ts ├── 2621.Sleep.ts ├── 2622.Cache With Time Limit.ts ├── 2623.Memoize.ts ├── 2624.Snail Traversal.ts ├── 2625.Flatten Deeply Nested Array.ts ├── 2626.Array Reduce Transformation.ts ├── 2627.Debounce.ts ├── 2628.JSON Deep Equal.ts ├── 2629.Function Composition.ts ├── 2630.Memoize II.ts ├── 2631.Group By.ts ├── 2632.Curry.ts ├── 2633.Convert Object to JSON String.ts ├── 2634.Filter Elements from Array.ts ├── 2635.Apply Transform Over Each Element in Array.ts ├── 2636.Promise Pool.ts ├── 2637.Promise Time Limit.ts ├── 2639.Find the Width of Columns of a Grid.ts ├── 2640.Find the Score of All Prefixes of an Array.ts ├── 2641.Cousins in Binary Tree II.ts ├── 2642.Design Graph With Shortest Path Calculator.py ├── 2643.Row With Maximum Ones.ts ├── 2644.Find the Maximum Divisibility Score.rb ├── 2645.Minimum Additions to Make Valid String.c ├── 2645.Minimum Additions to Make Valid String.py ├── 2646.Minimize the Total Price of the Trips.py ├── 2648.Generate Fibonacci Sequence.ts ├── 2649.Nested Array Generator.ts ├── 2650.Design Cancellable Function.ts ├── 2651.Calculate Delayed Arrival Time.c ├── 2652.Sum Multiples.ts ├── 2653.Sliding Subarray Beauty.ts ├── 2654.Minimum Number of Operations to Make All Array Elements Equal to 1.py ├── 2656.Maximum Sum With Exactly K Elements.ts ├── 2657.Find the Prefix Common Array of Two Arrays.ts ├── 2658.Maximum Number of Fish in a Grid.ts ├── 2659.Make Array Empty.py ├── 2660.Determine the Winner of a Bowling Game.ts ├── 2661.First Completely Painted Row or Column.ts ├── 2662.Minimum Cost of a Path With Special Roads.py ├── 2670.Find the Distinct Difference Array.py ├── 2671.Frequency Tracker.py ├── 2672.Number of Adjacent Elements With the Same Color.ts ├── 2673.Make Costs of Paths Equal in a Binary Tree.java ├── 2677.Chunk Array.ts ├── 2678.Number of Senior Citizens.c ├── 2679.Sum in a Matrix.py ├── 2682.Find the Losers of the Circular Game.php ├── 2683.Neighboring Bitwise XOR.ts ├── 2684.Maximum Number of Moves in a Grid.ts ├── 2685.Count the Number of Complete Components.ts ├── 2715.Timeout Cancellation.ts ├── 2716.Minimize String Length.rb ├── 2717.Semi-Ordered Permutation.rb ├── 2718.Sum of Matrix After Queries.py ├── 2719.Count of Integers.py ├── 2729.Check if The Number is Fascinating.py ├── 2730.Find the Longest Semi-Repetitive Substring.java ├── 2731.Movement of Robots.rb ├── 2732.Find a Good Subset of the Matrix.(DP).py ├── 2732.Find a Good Subset of the Matrix.(at most two).py ├── 2733.Neither Minimum nor Maximum.py ├── 2734.Lexicographically Smallest String After Substring Operation.py ├── 2735.Collecting Chocolates.py ├── 2736.Maximum Sum Queries.py ├── 2739.Total Distance Traveled.java ├── 2740.Find the Value of the Partition.ts ├── 2741.Special Permutations.py ├── 2742.Painting the Walls.py ├── 2748.Number of Beautiful Pairs.py ├── 2749.Minimum Operations to Make the Integer Zero.py ├── 2750.Ways to Split Array Into Good Subarrays.java ├── 2751.Robot Collisions.py ├── 2760.Longest Even Odd Subarray With Threshold.java ├── 2761.Prime Pairs With Target Sum.py ├── 2778.Sum of Squares of Special Elements.py ├── 2779.Maximum Beauty of an Array After Applying Operation.py ├── 2780.Minimum Index of a Valid Split.py ├── 2781.Length of the Longest Valid Substring.py ├── 2788.Split Strings by Separator.py ├── 2789.Largest Element in an Array after Merge Operations.py ├── 2791.Count Paths That Can Form a Palindrome in a Tree.md ├── 2798.Number of Employees Who Met the Target.ts ├── 2799.Count Complete Subarrays in an Array.py ├── 2800.Shortest String That Contains Three Strings.py ├── 2801.Count Stepping Numbers in Range.py ├── 2815.Max Pair Sum in an Array.py ├── 2816.Double a Number Represented as a Linked List.py ├── 2817.Minimum Absolute Difference Between Elements With Constraint.py ├── 2818.Apply Operations to Maximize Score.py ├── 2824.Count Pairs Whose Sum is Less than Target.py ├── 2825.Make String a Subsequence Using Cyclic Increments.py ├── 2826.Sorting Three Groups.java ├── 2827.Number of Beautiful Integers in the Range.py ├── 2828.Check if a String Is an Acronym of Words.ts ├── 2829.Determine the Minimum Sum of a k-avoiding Array.java ├── 2830.Maximize the Profit as the Salesman.py ├── 2831.Find the Longest Equal Subarray.py ├── 2833.Furthest Point From Origin.py ├── 2834.Find the Minimum Possible Sum of a Beautiful Array.py ├── 2835.Minimum Operations to Form Subsequence With Target Sum.py ├── 2836.Maximize Value of Function in a Ball Passing Game.py ├── 2839.Check if Strings Can be Made Equal With Operations I.py ├── 2840.Check if Strings Can be Made Equal With Operations II.py ├── 2841.Maximum Sum of Almost Unique Subarray.py ├── 2843.Count Symmetric Integers.py ├── 2844.Minimum Operations to Make a Special Number.py ├── 2848.Points That Intersect With Cars.py ├── 2849.Determine if a Cell Is Reachable at a Given Time.c ├── 2850.Minimum Moves to Spread Stones Over Grid.py ├── 2864.Maximum Odd Binary Number.py ├── 2865.Beautiful Towers I.py ├── 2866.Beautiful Towers II.py ├── 2867.Count Valid Paths in a Tree.py ├── 2873.Maximum Value of an Ordered Triplet I.py ├── 2874.Maximum Value of an Ordered Triplet II.py ├── 2875.Minimum Size Subarray in Infinite Array.py ├── 2876.Count Visited Nodes in a Directed Graph.py ├── 2894.Divisible and Non-divisible Sums Difference.py ├── 2895.Minimum Processing Time.py ├── 2896.Apply Operations to Make Two Strings Equal.py ├── 2897.Apply Operations on Array to Maximize Sum of Squares.py ├── 2903.Find Indices With Index and Value Difference I.py ├── 2904.Shortest and Lexicographically Smallest Beautiful String.py ├── 2905.Find Indices With Index and Value Difference II.py ├── 2906.Construct Product Matrix.py ├── 2908.Minimum Sum of Mountain Triplets I.py ├── 2909.Minimum Sum of Mountain Triplets II.py ├── 2910.Minimum Number of Groups to Create a Valid Assignment.py ├── 2911.Minimum Changes to Make K Semi-palindromes.py ├── 2917.Find the K-or of an Array.py ├── 2918.Minimum Equal Sum of Two Arrays After Replacing Zeros.py ├── 2919.Minimum Increment Operations to Make Array Beautiful.py ├── 2920.Maximum Points After Collecting Coins From All Nodes.py ├── 2923.Find Champion I.py ├── 2924.Find Champion II.py ├── 2925.Maximum Score After Applying Operations on a Tree.py ├── 2926.Maximum Balanced Subsequence Sum.py ├── 2932.Maximum Strong Pair XOR I.py ├── 2933.High-Access Employees.py ├── 2934.Minimum Operations to Maximize Last Elements in Arrays.py ├── 2935.Maximum Strong Pair XOR II.py ├── 2937.Make Three Strings Equal.py ├── 2938.Separate Black and White Balls.py ├── 2939.Maximum Xor Product.py ├── 2946.Matrix Similarity After Cyclic Shifts.py ├── 2947.Count Beautiful Substrings I.py ├── 2948.Make Lexicographically Smallest Array by Swapping Elements.py ├── 2949.Count Beautiful Substrings II.py ├── 2960.Count Tested Devices After Test Operations.py ├── 2961.Double Modular Exponentiation.py ├── 2962.Count Subarrays Where Max Element Appears at Least K Times.py ├── 2963.Count the Number of Good Partitions.py ├── 2974.Minimum Number Game.py ├── 2975.Maximum Square Area by Removing Fences From a Field.py ├── 2976.Minimum Cost to Convert String I.py ├── 2977.Minimum Cost to Convert String II.py ├── 2980.Check if Bitwise OR Has Trailing Zeros.py ├── 2981.Find Longest Special Substring That Occurs Thrice I.py ├── 2982.Find Longest Special Substring That Occurs Thrice II.py ├── 2983.Palindrome Rearrangement Queries.py ├── 3000.Maximum Area of Longest Diagonal Rectangle.py └── README.md ├── 3001-3500 ├── 3001.Minimum Moves to Capture The Queen.py ├── 3002.Maximum Size of a Set After Removals.py ├── 3003.Maximize the Number of Partitions After Operations.py ├── 3005.Count Elements With Maximum Frequency.py ├── 3006.Find Beautiful Indices in the Given Array I.py ├── 3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K.py ├── 3008.Find Beautiful Indices in the Given Array II.py ├── 3131.Find the Integer Added to Array I.ts ├── 3132.Find the Integer Added to Array II.py ├── 3133.Minimum Array End.c ├── 3136.Valid Word.py ├── 3137.Minimum Number of Operations to Make Word K-Periodic.py ├── 3138.Minimum Length of Anagram Concatenation.py ├── 3139.Minimum Cost to Equalize Array.py ├── 3146.Permutation Difference between Two Strings.py ├── 3147.Taking Maximum Energy From the Mystic Dungeon.py ├── 3148.Maximum Difference Score in a Grid.py ├── 3149.Find the Minimum Cost Array Permutation.py ├── 3168.Minimum Number of Chairs in a Waiting Room.py ├── 3169.Count Days Without Meetings.py ├── 3170.Lexicographically Minimum String After Removing Stars.py ├── 3171.Find Subarray With Bitwise OR Closest to K.py ├── 3174.Clear Digits.kt ├── 3178.Find the Child Who Has the Ball After K Seconds.kt ├── 3179.Find the N-th Value After K Seconds.py ├── 3180.Maximum Total Reward Using Operations I.py ├── 3181.Maximum Total Reward Using Operations II.(bitset).py ├── 3184.Count Pairs That Form a Complete Day I.py ├── 3185.Count Pairs That Form a Complete Day II.py ├── 3186.Maximum Total Damage With Spell Casting.py ├── 3187.Peaks in Array.py ├── 3200.Maximum Height of a Triangle.py ├── 3201.Find the Maximum Length of Valid Subsequence I.py ├── 3202.Find the Maximum Length of Valid Subsequence II.py ├── 3203.Find Minimum Diameter After Merging Two Trees.py ├── 3216.Lexicographically Smallest String After a Swap.py ├── 3217.Delete Nodes From Linked List Present in Array.py ├── 3218.Minimum Cost for Cutting Cake I.py ├── 3232.Find if Digit Game Can Be Won.py ├── 3233.Find the Count of Numbers Which Are Not Special.py ├── 3235.Check if the Rectangle Corner Is Reachable.py └── README.md ├── DD ├── DD-2019001.排列小球.py ├── DD-2020006.简单游戏.py └── README.md ├── LCP ├── LCP 01.Guess Numbers.py ├── LCP 02.Deep Dark Fraction.java ├── LCP 06.拿硬币.py ├── LCP 07.传递信息.py ├── LCP 18.早餐组合.py └── README.md ├── LCR ├── LCR 006.两数之和 II - 输入有序数组.ts ├── LCR 069.山脉数组的峰顶索引.ts ├── LCR 120.寻找文件副本.py ├── LCR 126.斐波那契数.rb ├── LCR 131.砍竹子 I.py ├── LCR 133.位 1 的个数.js ├── LCR 140.训练计划 II.js ├── LCR 150.彩灯装饰记录 II.ts ├── LCR 156.序列化与反序列化二叉树.js ├── LCR 157.套餐内商品的排列顺序.py ├── LCR 161.连续天数的最高销售额.ts ├── LCR 169.招式拆解 II.ts ├── LCR 171.训练计划 V.c ├── LCR 172.统计目标成绩的出现次数.ts └── README.md ├── LCS ├── LCS 01.下载插件.c ├── LCS 02.完成一半题目.py ├── LCS 03.主题空间.py └── README.md ├── README.md ├── others ├── 0.example of prime sieve of sundaram.py ├── 0.example of segment tree ├── LeetCode lauguage supports.md ├── api-cn.all.backup.json ├── api-cn.database.backup.json ├── full_table.md ├── janitor.py ├── longest common substring.py ├── reporter.js ├── todo questions.md └── 技巧总结.docx ├── 银联 ├── README.md ├── 银联-01.回文链表.ts ├── 银联-02.优惠活动系统.py ├── 银联-03.理财产品.ts └── 银联-04.合作开发.ts └── 面试题 ├── README.md ├── 面试题 01.01.Is Unique LCCI.py ├── 面试题 01.05.One Away LCCI.ts ├── 面试题 10.02.Group Anagrams LCCI.py ├── 面试题 17.01.Add Without Plus LCCI.c ├── 面试题 17.04.Missing Number LCCI.ts ├── 面试题 17.10.Find Majority Element LCCI.ts ├── 面试题 17.14.Smallest K LCCI.py ├── 面试题 17.16.The Masseuse LCCI.py ├── 面试题 17.16.The Masseuse LCCI.ts ├── 面试题 17.21.Volume of Histogram LCCI.java └── 面试题 17.26.Sparse Similarity LCCI.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .DS_Store 3 | #others/*.backup.json 4 | -------------------------------------------------------------------------------- /0001-0500/0035.Search Insert Position.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @param {Integer} target 3 | # @return {Integer} 4 | def search_insert(nums, target) 5 | lo, hi = 0, nums.size 6 | while lo < hi 7 | mid = (lo + hi) / 2 8 | if nums[mid] >= target 9 | hi = mid 10 | else 11 | lo = mid + 1 12 | end 13 | end 14 | lo 15 | end 16 | -------------------------------------------------------------------------------- /0001-0500/0049.Group Anagrams.rb: -------------------------------------------------------------------------------- 1 | # @param {String[]} strs 2 | # @return {String[][]} 3 | def group_anagrams(strs) 4 | hash = Hash.new { |h, k| h[k] = [] } 5 | strs.each { |str| hash[str.chars.sort.join] << str } 6 | hash.values 7 | end 8 | -------------------------------------------------------------------------------- /0001-0500/0050.Pow(x, n).c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiwensun/leetcode/980a22db643417e3782e40b3b47b12343b5bcc45/0001-0500/0050.Pow(x, n).c -------------------------------------------------------------------------------- /0001-0500/0053.Maximum Subarray.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxSubArray(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | res = pre = 0 8 | for n in nums: 9 | pre = max(pre + n, 0) 10 | res = max(res, pre) 11 | if res == 0: 12 | return max(nums) 13 | return res 14 | -------------------------------------------------------------------------------- /0001-0500/0053.Maximum Subarray.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def max_sub_array(nums) 4 | res = cur = 0 5 | mx = nums.max 6 | if mx < 0 7 | mx 8 | else 9 | nums.each do |n| 10 | cur = [cur + n, 0].max 11 | res = [res, cur].max 12 | end 13 | res 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /0001-0500/0055.Jump Game.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def canJump(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: bool 6 | """ 7 | reached = 0 8 | for i in xrange(len(nums)): 9 | if i > reached: 10 | return reached >= len(nums) - 1 11 | reached = max(reached, i + nums[i]) 12 | return True 13 | -------------------------------------------------------------------------------- /0001-0500/0055.Jump Game.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Boolean} 3 | def can_jump(nums) 4 | mx = 0 5 | for i in (0...nums.size) 6 | break if i > mx 7 | mx = [mx, i + nums[i]].max 8 | end 9 | mx >= nums.size - 1 10 | end 11 | -------------------------------------------------------------------------------- /0001-0500/0062.Unique Paths.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} m 2 | # @param {Integer} n 3 | # @return {Integer} 4 | def unique_paths(m, n) 5 | dp = Array.new(n, 1) 6 | for _ in (1...m) 7 | for j in (1...n) 8 | dp[j] += dp[j - 1] 9 | end 10 | end 11 | dp[-1] 12 | end 13 | -------------------------------------------------------------------------------- /0001-0500/0064.Minimum Path Sum.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} grid 2 | # @return {Integer} 3 | def min_path_sum(grid) 4 | dp = [1.0/0.0] * (grid[0].size + 1) 5 | dp[1] = 0 6 | grid.each do |row| 7 | new_dp = [1.0/0.0] * (grid[0].size + 1) 8 | (1..grid[0].size).each { |i| new_dp[i] = [dp[i], new_dp[i - 1]].min + row[i - 1] } 9 | dp = new_dp 10 | end 11 | dp[-1] 12 | end 13 | -------------------------------------------------------------------------------- /0001-0500/0066.Plus One.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} digits 2 | # @return {Integer[]} 3 | def plus_one(digits) 4 | carry = 1 5 | for i in (digits.size - 1).downto(0) 6 | digits[i] += carry 7 | carry = digits[i] / 10 8 | digits[i] %= 10 9 | end 10 | digits.insert(0, 1) if carry == 1 11 | return digits 12 | end 13 | -------------------------------------------------------------------------------- /0001-0500/0070.Climbing Stairs.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def climbStairs(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | yesterday, today = 0, 1 8 | for i in xrange(n): 9 | yesterday, today = today, yesterday + today 10 | return today 11 | 12 | -------------------------------------------------------------------------------- /0001-0500/0078.Subsets.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def subsets(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[List[int]] 6 | """ 7 | return sum([list(itertools.combinations(nums, i)) for i in xrange(len(nums) + 1)], []) 8 | -------------------------------------------------------------------------------- /0001-0500/0078.Subsets.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer[][]} 3 | def subsets(nums) 4 | res = [[]] 5 | for num in nums 6 | for i in 0...res.size 7 | res << (res[i].clone << num) 8 | end 9 | end 10 | res 11 | end 12 | -------------------------------------------------------------------------------- /0001-0500/0080.Remove Duplicates from Sorted Array II.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def removeDuplicates(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | i, j = 0, 0 8 | while j < len(nums): 9 | if i < 2 or nums[i - 2] != nums[j]: 10 | nums[i] = nums[j] 11 | i += 1 12 | j += 1 13 | return i 14 | -------------------------------------------------------------------------------- /0001-0500/0089.Gray Code.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def grayCode(self, n): 3 | """ 4 | :type n: int 5 | :rtype: List[int] 6 | """ 7 | res = [0] 8 | for i in xrange(n): 9 | res = [ele << 1 for ele in res] + [(ele << 1) | 1 for ele in reversed(res)] 10 | return res 11 | -------------------------------------------------------------------------------- /0001-0500/0089.Gray Code.3.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def grayCode(self, n): 3 | """ 4 | :type n: int 5 | :rtype: List[int] 6 | """ 7 | res = [0] 8 | for i in xrange(n): 9 | res += [(1 << i) | ele for ele in reversed(res)] 10 | shift = random.randint(0, n) 11 | return [((ele << shift) & ((1 << n) - 1)) | (ele >> (n - shift)) for ele in res] 12 | -------------------------------------------------------------------------------- /0001-0500/0089.Gray Code.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def grayCode(self, n): 3 | """ 4 | :type n: int 5 | :rtype: List[int] 6 | """ 7 | res = [0] 8 | for i in xrange(n): 9 | res += [(1 << i) | ele for ele in reversed(res)] 10 | return res 11 | -------------------------------------------------------------------------------- /0001-0500/0096.Unique Binary Search Trees.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | def num_trees(n) 4 | dp = Array.new(n + 1, 0) 5 | dp[0] = 1 6 | for treesize in (1..n) 7 | for lsize in (0..treesize - 1) 8 | rsize = treesize - lsize - 1 9 | dp[treesize] += dp[lsize] * dp[rsize] 10 | end 11 | end 12 | dp[-1] 13 | end 14 | -------------------------------------------------------------------------------- /0001-0500/0104.Maximum Depth of Binary Tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Basic idea: 3 | * recursion on subtree. 4 | * Result: 5 | * 38 / 38 test cases passed. 6 | * Status: Accepted 7 | * Runtime: 1 ms 8 | * Date: 9 | * 2/7/2016 10 | */ 11 | public class Solution { 12 | public int maxDepth(TreeNode root) { 13 | return root==null?0:1+Math.max(maxDepth(root.left),maxDepth(root.right)); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /0001-0500/0122.Best Time to Buy and Sell Stock II.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} prices 2 | # @return {Integer} 3 | def max_profit(prices) 4 | profit = 0 5 | (1...prices.size).each { |i| profit += [prices[i] - prices[i - 1], 0].max } 6 | profit 7 | end 8 | -------------------------------------------------------------------------------- /0001-0500/0125.Valid Palindrome.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Boolean} 3 | def is_palindrome(s) 4 | s = s.gsub(/[^0-9a-zA-Z]/, '') 5 | s.size < 2 || s[0 ... s.size / 2].downcase == s[-(s.size / 2)..s.size].downcase.reverse 6 | end 7 | -------------------------------------------------------------------------------- /0001-0500/0135.Candy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiwensun/leetcode/980a22db643417e3782e40b3b47b12343b5bcc45/0001-0500/0135.Candy.c -------------------------------------------------------------------------------- /0001-0500/0136.Single Number.java: -------------------------------------------------------------------------------- 1 | /** 2 | *Result: 3 | * 15 / 15 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 1 ms 6 | *Date: 7 | * 9/6/2016 8 | */ 9 | public class Solution { 10 | public int singleNumber(int[] nums) { 11 | int sum = 0; 12 | for(int e:nums) 13 | sum ^= e; 14 | return sum; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0001-0500/0136.Single Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def singleNumber(self, nums): 3 | return reduce(lambda a, b : a ^ b, nums) 4 | -------------------------------------------------------------------------------- /0001-0500/0136.Single Number.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def single_number(nums) 4 | nums.reduce(:^) 5 | end 6 | -------------------------------------------------------------------------------- /0001-0500/0169.Majority Element.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def majority_element(nums) 4 | res = nil 5 | cnt = 0 6 | nums.each do |num| 7 | if res == num || cnt == 0 8 | res = num 9 | cnt += 1 10 | else 11 | cnt -= 1 12 | end 13 | end 14 | res 15 | end 16 | -------------------------------------------------------------------------------- /0001-0500/0171.Excel Sheet Column Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def titleToNumber(self, s): 3 | """ 4 | :type s: str 5 | :rtype: int 6 | """ 7 | res = 0 8 | for c in s: 9 | res = res * 26 + ord(c) - ord('A') + 1 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /0001-0500/0172.Factorial Trailing Zeroes.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def trailingZeroes(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | res = 0 8 | while n: 9 | n /= 5 10 | res += n 11 | return res 12 | -------------------------------------------------------------------------------- /0001-0500/0175.Combine Two Tables.sql: -------------------------------------------------------------------------------- 1 | /* 2 | *Result: 3 | * 7 / 7 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 738 ms 6 | * Your runtime beats 6.13% of mysql submissions. 7 | *Date: 8 | * 10/20/2016 9 | */ 10 | 11 | SELECT 12 | FirstName, 13 | LastName, 14 | City, 15 | State 16 | FROM 17 | Person 18 | LEFT JOIN Address ON 19 | Person.PersonID=Address.PersonID; 20 | -------------------------------------------------------------------------------- /0001-0500/0179.Largest Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def largestNumber(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: str 6 | """ 7 | return str(int("".join(sorted(map(str, nums), reverse=True, cmp=lambda str1, str2: cmp(str1 + str2, str2 + str1))))) 8 | -------------------------------------------------------------------------------- /0001-0500/0181.Employees Earning More Than Their Managers.sql: -------------------------------------------------------------------------------- 1 | /** 2 | *Result: 3 | * 14 / 14 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 976 ms 6 | *Date: 7 | * 10/20/2016 8 | */ 9 | SELECT Emp.Name AS 'Employee' 10 | FROM Employee Emp, Employee Mgr 11 | WHERE Emp.ManagerId = Mgr.Id 12 | AND Emp.Salary>Mgr.Salary; 13 | 14 | -------------------------------------------------------------------------------- /0001-0500/0182.Duplicate Emails.sql: -------------------------------------------------------------------------------- 1 | /* 2 | *Result: 3 | * 14 / 14 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 598 ms 6 | * Your runtime beats 95.43% of mysql submissions. 7 | *Date: 8 | * 10/20/2016 9 | */ 10 | SELECT Email 11 | FROM Person 12 | GROUP BY Email 13 | HAVING COUNT(*)>1; 14 | -------------------------------------------------------------------------------- /0001-0500/0183.Customers Who Never Order.sql: -------------------------------------------------------------------------------- 1 | /** 2 | *Result: 3 | * 12 / 12 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 461 ms 6 | * Your runtime beats 87.03% of mysql submissions. 7 | *Date: 8 | * 10/20/2016 9 | */ 10 | SELECT Name AS 'Customers' 11 | FROM Customers 12 | WHERE Id not in ( 13 | SELECT CustomerId 14 | FROM Orders 15 | ); 16 | -------------------------------------------------------------------------------- /0001-0500/0190.Reverse Bits.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | // you need treat n as an unsigned value 3 | public int reverseBits(int n) { 4 | int res = 0; 5 | for (int i = 0; i < 32; i++) { 6 | res <<= 1; 7 | res |= n & 1; 8 | n >>= 1; 9 | } 10 | return res; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /0001-0500/0191.Number of 1 Bits.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *Result: 3 | * 600 / 600 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 3 ms 6 | * Your runtime beats 26.06% of cpp submissions. 7 | */ 8 | class Solution { 9 | public: 10 | int hammingWeight(uint32_t n) { 11 | int cnt = 0; 12 | while(n){ 13 | cnt++; 14 | n &= n-1; 15 | } 16 | return cnt; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /0001-0500/0192.Word Frequency.sh: -------------------------------------------------------------------------------- 1 | # Read from the file words.txt and output the word frequency list to stdout. 2 | tr -s ' ' '\n' < words.txt | sort | uniq -c | sort -nr | awk '{print $2, $1}' 3 | -------------------------------------------------------------------------------- /0001-0500/0193.Valid Phone Numbers.sh: -------------------------------------------------------------------------------- 1 | grep -oP '^((\(\d{3}\) \d{3}-\d{4})|(\d{3}-\d{3}-\d{4}))$' words.txt 2 | -------------------------------------------------------------------------------- /0001-0500/0194.Transpose File.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and print its transposed content to stdout. 2 | ncol=$(head -n1 file.txt | wc -w) 3 | for i in $(seq 1 $ncol); do 4 | echo $(cut -d ' ' -f $i file.txt) 5 | done 6 | -------------------------------------------------------------------------------- /0001-0500/0195.Tenth Line.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and output the tenth line to stdout. 2 | first_ten=`head -10 file.txt` 3 | if [ 10 -le "`echo "$first_ten" | wc -l | awk '{print $1}'`" ]; then 4 | echo "$first_ten" | tail -1 5 | fi 6 | -------------------------------------------------------------------------------- /0001-0500/0201.Bitwise AND of Numbers Range.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} m 2 | # @param {Integer} n 3 | # @return {Integer} 4 | def range_bitwise_and(m, n) 5 | res = num = m 6 | for i in (0...31) do 7 | next if (1 << i) & num == 0 8 | num += (1 << i) 9 | break if num > n 10 | res &= num 11 | end 12 | res 13 | end 14 | -------------------------------------------------------------------------------- /0001-0500/0202.Happy Number.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Boolean} 3 | def is_happy(n) 4 | seen = [n].to_set 5 | while n != 1 do 6 | m = 0 7 | s = n.to_s 8 | (0...s.size).each { |x| m += s[x].to_i ** 2 } 9 | if seen.include? m 10 | return false 11 | end 12 | seen << m 13 | n = m 14 | end 15 | true 16 | end 17 | -------------------------------------------------------------------------------- /0001-0500/0215.Kth Largest Element in an Array.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | class Solution: 3 | def findKthLargest(self, nums: List[int], k: int) -> int: 4 | queue = [float("-inf")] * k 5 | for num in nums: 6 | heapq.heappushpop(queue, num) 7 | return queue[0] 8 | -------------------------------------------------------------------------------- /0001-0500/0217.Contains Duplicate.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def containsDuplicate(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: bool 6 | """ 7 | return len(nums) != len(set(nums)) 8 | -------------------------------------------------------------------------------- /0001-0500/0231.Power of Two.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isPowerOfTwo(self, n): 3 | """ 4 | :type n: int 5 | :rtype: bool 6 | """ 7 | return n > 0 and n & (n - 1) == 0 8 | -------------------------------------------------------------------------------- /0001-0500/0231.Power of Two.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Boolean} 3 | def is_power_of_two(n) 4 | !n.zero? && n - 1 & n == 0 5 | end 6 | -------------------------------------------------------------------------------- /0001-0500/0233.Number of Digit One.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiwensun/leetcode/980a22db643417e3782e40b3b47b12343b5bcc45/0001-0500/0233.Number of Digit One.c -------------------------------------------------------------------------------- /0001-0500/0238.Product of Array Except Self.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiwensun/leetcode/980a22db643417e3782e40b3b47b12343b5bcc45/0001-0500/0238.Product of Array Except Self.cpp -------------------------------------------------------------------------------- /0001-0500/0238.Product of Array Except Self.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer[]} 3 | def product_except_self(nums) 4 | res = [1] * nums.size 5 | (1...nums.size).each { |i| res[i] = res[i - 1] * nums[i - 1] } 6 | right = nums[-1] 7 | (nums.size - 2).downto(0).each do |i| 8 | res[i] *= right 9 | right *= nums[i] 10 | end 11 | res 12 | end 13 | -------------------------------------------------------------------------------- /0001-0500/0252.Meeting Rooms.ts: -------------------------------------------------------------------------------- 1 | function canAttendMeetings(intervals: number[][]): boolean { 2 | intervals.sort((a, b) => a[0] - b[0]); 3 | for (let i = 1; i < intervals.length; i++) { 4 | if (intervals[i - 1][1] > intervals[i][0]) { 5 | return false; 6 | } 7 | } 8 | return true; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /0001-0500/0260.Single Number III.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def singleNumber(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | seen = set() 8 | for num in nums: 9 | if num in seen: 10 | seen.discard(num) 11 | else: 12 | seen.add(num) 13 | return list(seen) 14 | 15 | -------------------------------------------------------------------------------- /0001-0500/0260.Single Number III.ts: -------------------------------------------------------------------------------- 1 | function singleNumber(nums: number[]): number[] { 2 | const xor = nums.reduce((xor, num) => xor ^ num); 3 | const bit = xor & -xor; 4 | return nums.reduce((xors, num) => [xors[0] ^ (num & bit ? num : 0), xors[1] ^ (num & bit ? 0 : num)], [0, 0]); 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /0001-0500/0263.Ugly Number.c: -------------------------------------------------------------------------------- 1 | bool isUgly(int num){ 2 | if (num < 1) return false; 3 | int factors[] = {2, 3, 5}; 4 | for (int i = 0; i < 3; i++) { 5 | while (!(num % factors[i])) num /= factors[i]; 6 | } 7 | return num == 1; 8 | } 9 | -------------------------------------------------------------------------------- /0001-0500/0263.Ugly Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isUgly(self, num): 3 | """ 4 | :type num: int 5 | :rtype: bool 6 | """ 7 | if num<=0: 8 | return False 9 | for d in (2,3,5): 10 | while num/d*d==num: 11 | num=num/d 12 | if num==1: 13 | return True 14 | return False 15 | 16 | 17 | -------------------------------------------------------------------------------- /0001-0500/0268.Missing Number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function(nums) { 6 | let bits = 0; 7 | for (let i = 0; i < nums.length; i++) { 8 | bits ^= i ^ nums[i]; 9 | } 10 | return bits ^ nums.length; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /0001-0500/0275.H-Index II.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} citations 2 | # @return {Integer} 3 | def h_index(citations) 4 | lo, hi = 0, citations.size 5 | while lo < hi 6 | mid = (lo + hi) / 2 7 | if citations[mid] < citations.size - mid 8 | lo = mid + 1 9 | else 10 | hi = mid 11 | end 12 | end 13 | citations.size - hi 14 | end 15 | -------------------------------------------------------------------------------- /0001-0500/0283.Move Zeroes.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Void} Do not return anything, modify nums in-place instead. 3 | def move_zeroes(nums) 4 | l = r = 0 5 | (0...nums.size).each do |r| 6 | nums[r], nums[l] = 0, nums[r] 7 | l += nums[l] == 0 ? 0 : 1 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /0001-0500/0292.Nim Game.c: -------------------------------------------------------------------------------- 1 | bool canWinNim(int n) { 2 | return n&3; 3 | } 4 | 5 | -------------------------------------------------------------------------------- /0001-0500/0319.Bulb Switcher.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *Result: 3 | * 35 / 35 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 0 ms 6 | * Your runtime beats 6.19% of cpp submissions. 7 | *Date: 8 | * 10/16/2016 9 | */ 10 | class Solution { 11 | public: 12 | int bulbSwitch(int n) { 13 | return (int)sqrt(n); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /0001-0500/0324.Wiggle Sort II.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def wiggleSort(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: None Do not return anything, modify nums in-place instead. 6 | """ 7 | nums.sort(reverse=True) 8 | half = (len(nums) + 1) / 2 9 | nums[::2], nums[1::2] = nums[-half:], nums[:-half] 10 | return nums 11 | -------------------------------------------------------------------------------- /0001-0500/0330.Patching Array.c: -------------------------------------------------------------------------------- 1 | int minPatches(int* nums, int numsSize, int n){ 2 | int res = 0, i = 0; 3 | long x = 1; 4 | while (x <= n) { 5 | if (i < numsSize && nums[i] <= x) { 6 | x += nums[i++]; 7 | } else { 8 | res++; 9 | x *= 2; 10 | } 11 | } 12 | return res; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0001-0500/0338.Counting Bits.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} num 2 | # @return {Integer[]} 3 | def count_bits(num) 4 | res = Array.new(num + 1) 5 | (0..num).each do |i| 6 | if i <= 1 7 | res[i] = i 8 | else 9 | res[i] = res[i >> 1] + (i.odd? ? 1 : 0) 10 | end 11 | end 12 | res 13 | end 14 | -------------------------------------------------------------------------------- /0001-0500/0342.Power of Four.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isPowerOfFour(self, num): 3 | """ 4 | :type num: int 5 | :rtype: bool 6 | """ 7 | return (num - 1) & num == 0 and bin(num)[2:].count("0") % 2 == 0 8 | 9 | -------------------------------------------------------------------------------- /0001-0500/0342.Power of Four.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isPowerOfFour(self, num): 3 | """ 4 | :type num: int 5 | :rtype: bool 6 | """ 7 | if num in [1<<(2*i) for i in range(16)]: 8 | return True 9 | return False; 10 | 11 | -------------------------------------------------------------------------------- /0001-0500/0344.Reverse String.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Result: 3 | * 476 / 476 test cases passed. 4 | * Status: Accepted 5 | * Runtime: 4 ms 6 | * Date: 7 | * 5/1/2016 8 | */ 9 | char* reverseString(char* s) { 10 | if(s==NULL)return s; 11 | char* l = s; 12 | char* r = s+strlen(s)-1; 13 | while(l a + b, 0); 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /0001-0500/0383.Ransom Note.2.c: -------------------------------------------------------------------------------- 1 | bool canConstruct(char * ransomNote, char * magazine){ 2 | int counter[26] = {0}; 3 | while(*magazine) counter[*magazine++ - 'a']++; 4 | while(*ransomNote) counter[*ransomNote++ - 'a']--; 5 | for (int i = 0; i < 26; i++) 6 | if (counter[i] < 0) return false; 7 | return true; 8 | } 9 | -------------------------------------------------------------------------------- /0001-0500/0383.Ransom Note.rb: -------------------------------------------------------------------------------- 1 | # @param {String} ransom_note 2 | # @param {String} magazine 3 | # @return {Boolean} 4 | def can_construct(ransom_note, magazine) 5 | cntNote, cntMag = Hash.new(0), Hash.new(0) 6 | ransom_note.each_char { |c| cntNote[c] += 1 } 7 | magazine.each_char { |c| cntMag[c] += 1} 8 | cntNote.all? { |k, v| cntMag[k] >= v } 9 | end 10 | -------------------------------------------------------------------------------- /0001-0500/0387.First Unique Character in a String.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Integer} 3 | def first_uniq_char(s) 4 | cnt = Hash.new 0 5 | s.each_char { |c| cnt[c] += 1 } 6 | s.each_char.with_index { |c, index| return index if cnt[c] == 1 } 7 | -1 8 | end 9 | -------------------------------------------------------------------------------- /0001-0500/0389.Find the Difference.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def findTheDifference(self, s, t): 3 | """ 4 | :type s: str 5 | :type t: str 6 | :rtype: str 7 | """ 8 | ctr_s = collections.Counter(s) 9 | ctr_t = collections.Counter(t) 10 | return (ctr_t - ctr_s).most_common(1)[0][0] 11 | -------------------------------------------------------------------------------- /0001-0500/0392.Is Subsequence.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isSubsequence(self, s, t): 3 | """ 4 | :type s: str 5 | :type t: str 6 | :rtype: bool 7 | """ 8 | i = j = 0 9 | while i < len(s) and j < len(t): 10 | if s[i] == t[j]: 11 | i += 1 12 | j += 1 13 | return i == len(s) 14 | -------------------------------------------------------------------------------- /0001-0500/0392.Is Subsequence.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @param {String} t 3 | # @return {Boolean} 4 | def is_subsequence(s, t) 5 | sp = 0 6 | for c in t.each_char 7 | sp += 1 if s[sp] == c 8 | break if sp == s.size 9 | end 10 | sp == s.size 11 | end 12 | -------------------------------------------------------------------------------- /0001-0500/0400.Nth Digit.ts: -------------------------------------------------------------------------------- 1 | function findNthDigit(n: number): number { 2 | let length = 1; 3 | let search = 10; 4 | while (n >= search * length) { 5 | n += search; 6 | length++; 7 | search *= 10; 8 | } 9 | let i = Math.floor(n / length); 10 | let j = n % length; 11 | return parseInt(('' + i)[j]); 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /0001-0500/0405.Convert a Number to Hexadecimal.c: -------------------------------------------------------------------------------- 1 | char * toHex(int num){ 2 | char dec2hex[] = "0123456789abcdef"; 3 | unsigned int unum = (unsigned)num; 4 | char* str = calloc(9, sizeof(char)); 5 | char* p = str + 8; 6 | while (str != p) { 7 | *(--p) = dec2hex[unum & 0xF]; 8 | unum >>= 4; 9 | } 10 | while (*p == '0' && *(p + 1) !='\0') p++; 11 | return p; 12 | } 13 | -------------------------------------------------------------------------------- /0001-0500/0406.Queue Reconstruction by Height.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def reconstructQueue(self, people): 3 | """ 4 | :type people: List[List[int]] 5 | :rtype: List[List[int]] 6 | """ 7 | people = sorted(people, key=lambda p:(-p[0], p[1])) 8 | res = [] 9 | for p in people: 10 | res.insert(p[1], p) 11 | return res 12 | -------------------------------------------------------------------------------- /0001-0500/0406.Queue Reconstruction by Height.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} people 2 | # @return {Integer[][]} 3 | def reconstruct_queue(people) 4 | groups = people.group_by &:first 5 | res = [] 6 | for key in groups.keys.sort.reverse 7 | for person in groups[key].sort 8 | res.insert(person[1], person) 9 | end 10 | end 11 | res 12 | end 13 | -------------------------------------------------------------------------------- /0001-0500/0434.Number of Segments in a String.ts: -------------------------------------------------------------------------------- 1 | function countSegments(s: string): number { 2 | return s.split(' ').filter(w => w).length; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /0001-0500/0441.Arranging Coins.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | def arrange_coins(n) 4 | # (1 + x) * x / 2 == n + d 5 | # x ^ 2 + x - (n + d) * 2 == 0 6 | # x = (-1 + sqrt(1 + 4*(n + d) * 2))/(2) 7 | (Math.sqrt(1 + 8 * n) - 1).to_i / 2 8 | end 9 | -------------------------------------------------------------------------------- /0001-0500/0448.Find All Numbers Disappeared in an Array.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer[]} 3 | def find_disappeared_numbers(nums) 4 | mx = nums.max 5 | for num in nums 6 | nums[(num - 1) % mx] += mx 7 | end 8 | nums.each_with_index.select { |num, i| num <= mx } .map { |_, index| index + 1 } 9 | end 10 | 11 | -------------------------------------------------------------------------------- /0001-0500/0451.Sort Characters By Frequency.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {String} 3 | def frequency_sort(s) 4 | cnt = Hash.new 0 5 | s.chars { |c| cnt[c] += 1 } 6 | cnt.sort_by { |k, v| -v } .map { |c, n| c * n}.join 7 | end 8 | -------------------------------------------------------------------------------- /0001-0500/0459.Repeated Substring Pattern.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def repeatedSubstringPattern(self, s): 3 | """ 4 | :type s: str 5 | :rtype: bool 6 | """ 7 | for size in xrange(1, len(s)): 8 | if len(s) % size == 0: 9 | if s[:size] * (len(s) // size) == s: 10 | return True 11 | return False 12 | 13 | -------------------------------------------------------------------------------- /0001-0500/0461.Hamming Distance.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingDistance(int x, int y) { 4 | int exc = x^y; 5 | int dist = 0; 6 | while(exc){ 7 | dist++; 8 | exc &= (exc-1); 9 | } 10 | return dist; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /0001-0500/0470.Implement Rand10() Using Rand7().c: -------------------------------------------------------------------------------- 1 | // The rand7() API is already defined for you. 2 | // int rand7(); 3 | // @return a random integer in the range 1 to 7 4 | 5 | int rand10() { 6 | int res; 7 | do { 8 | res = (rand7() - 1) * 7 + rand7(); 9 | } while (res > 40); 10 | return res % 10 + 1; 11 | } 12 | -------------------------------------------------------------------------------- /0001-0500/0476.Number Complement.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} num 2 | # @return {Integer} 3 | def find_complement(num) 4 | mask = [1, 2, 4, 8, 16].reduce(num) { | mask, shift | mask | mask >> shift } 5 | ~num & mask 6 | end 7 | -------------------------------------------------------------------------------- /0001-0500/0477.Total Hamming Distance.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def totalHammingDistance(self, nums: List[int]) -> int: 3 | res = 0 4 | for shift in range(30): 5 | cnt = 0 6 | for num in nums: 7 | cnt += (num >> shift) & 1 8 | res += cnt * (len(nums) - cnt) 9 | return res 10 | -------------------------------------------------------------------------------- /0001-0500/0482.License Key Formatting.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def licenseKeyFormatting(self, S, K): 3 | """ 4 | :type S: str 5 | :type K: int 6 | :rtype: str 7 | """ 8 | s = "".join(S.split("-")).upper() 9 | return "-".join(reversed(tuple(s[-i - K:-i or None] for i in xrange(0, len(s), K)))) 10 | -------------------------------------------------------------------------------- /0001-0500/0485.Max Consecutive Ones.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def findMaxConsecutiveOnes(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | return max(map(len, "".join(map(str, nums)).split("0"))) 8 | 9 | -------------------------------------------------------------------------------- /0001-0500/0492.Construct the Rectangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] constructRectangle(int area) { 3 | int w = (int)Math.sqrt(area) + 1; 4 | while (true) { 5 | if (area % --w == 0) { 6 | return new int[] {area / w, w}; 7 | } 8 | } 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /0501-1000/0504.Base 7.ts: -------------------------------------------------------------------------------- 1 | function convertToBase7(num: number): string { 2 | const sign = num >= 0 ? "" : "-"; 3 | num = Math.abs(num); 4 | const res = []; 5 | while (num) { 6 | res.unshift(num % 7); 7 | num = Math.floor(num / 7); 8 | } 9 | if (!res.length) { 10 | res.unshift(0); 11 | } 12 | res.unshift(sign); 13 | return res.join(""); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /0501-1000/0509.Fibonacci Number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private int[] cache = new int[31]; 3 | public int fib(int n) { 4 | if (n <= 1) { 5 | return n; 6 | } 7 | if (cache[n] != 0) { 8 | return cache[n]; 9 | } 10 | cache[n] = fib(n -1) + fib(n - 2); 11 | return cache[n]; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0501-1000/0520.Detect Capital.c: -------------------------------------------------------------------------------- 1 | bool detectCapitalUse(char * word){ 2 | if (*(word + 1) == '\0') return true; 3 | bool isCap = *(word + 1) < 'a'; 4 | if (isCap && *word >= 'a') return false; 5 | char* p = word + 2; 6 | while (*p) if (*p++ < 'a' ^ isCap) return false; 7 | return true; 8 | } 9 | -------------------------------------------------------------------------------- /0501-1000/0521.Longest Uncommon Subsequence I.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findLUSlength(String a, String b) { 3 | return a.equals(b) ? -1 : Math.max(a.length(), b.length()); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /0501-1000/0541.Reverse String II.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseStr(self, s: str, k: int) -> str: 3 | res = [] 4 | for i in range(0, len(s), 2 * k): 5 | res.append(s[i + k - 1 : max(0, i - 1) or None : -1] + s[i + k: i + 2 * k]) 6 | return "".join(res) 7 | 8 | -------------------------------------------------------------------------------- /0501-1000/0553.Optimal Division.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def optimalDivision(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: str 6 | """ 7 | if len(nums) > 2: 8 | return str(nums[0]) + '/(' + '/'.join(map(str, nums[1:])) + ')' 9 | return '/'.join(map(str, nums)) 10 | -------------------------------------------------------------------------------- /0501-1000/0560.Subarray Sum Equals K.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @param {Integer} k 3 | # @return {Integer} 4 | def subarray_sum(nums, k) 5 | seen = Hash.new 0 6 | sum = res = 0 7 | seen[0] = 1 8 | nums.each do |num| 9 | sum += num 10 | res += seen[sum - k] 11 | seen[sum] += 1 12 | end 13 | res 14 | end 15 | -------------------------------------------------------------------------------- /0501-1000/0561.Array Partition.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def array_pair_sum(nums) 4 | nums.sort.values_at(*(0..nums.length - 1).step(2)).sum 5 | end 6 | -------------------------------------------------------------------------------- /0501-1000/0575.Distribute Candies.ts: -------------------------------------------------------------------------------- 1 | function distributeCandies(candyType: number[]): number { 2 | return Math.min(new Set(candyType).size, candyType.length / 2); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /0501-1000/0595.Big Countries.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name, population, area 3 | FROM World 4 | WHERE area > 3000000 OR population > 25000000; 5 | -------------------------------------------------------------------------------- /0501-1000/0598.Range Addition II.php: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | /** 4 | * @param Integer $m 5 | * @param Integer $n 6 | * @param Integer[][] $ops 7 | * @return Integer 8 | */ 9 | function maxCount($m, $n, $ops) { 10 | foreach($ops as list($x, $y)) { 11 | $m = min($m, $x); 12 | $n = min($n, $y); 13 | } 14 | return $m * $n; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /0501-1000/0605.Can Place Flowers.c: -------------------------------------------------------------------------------- 1 | bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n){ 2 | for (int i = 0; i < flowerbedSize && n > 0; i++) { 3 | if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) &&(i == flowerbedSize - 1 || flowerbed[i + 1] == 0)) { 4 | i++; 5 | n--; 6 | } 7 | } 8 | return n == 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /0501-1000/0628.Maximum Product of Three Numbers.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Solution(object): 4 | def maximumProduct(self, nums): 5 | """ 6 | :type nums: List[int] 7 | :rtype: int 8 | """ 9 | smallests = heapq.nsmallest(2, nums) 10 | biggest = heapq.nlargest(3, nums) 11 | return max(smallests[0] * smallests[1] * biggest[0], biggest[0] * biggest[1] * biggest[2]) 12 | 13 | -------------------------------------------------------------------------------- /0501-1000/0633.Sum of Square Numbers.py: -------------------------------------------------------------------------------- 1 | import math, bisect 2 | 3 | squares = [0] 4 | 5 | class Solution(object): 6 | def judgeSquareSum(self, c): 7 | """ 8 | :type c: int 9 | :rtype: bool 10 | """ 11 | for a in xrange(int(math.sqrt(c)) + 1): 12 | if math.sqrt(c - a * a).is_integer(): 13 | return True 14 | return False 15 | 16 | -------------------------------------------------------------------------------- /0501-1000/0686.Repeated String Match.ts: -------------------------------------------------------------------------------- 1 | function repeatedStringMatch(a: string, b: string): number { 2 | let repeat = Math.ceil(b.length * 2 / a.length); 3 | const aa = a.repeat(Math.max(repeat, 2)); 4 | const i = aa.indexOf(b); 5 | if (i === -1) { 6 | return -1; 7 | } 8 | return Math.ceil((i + b.length) / a.length); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /0501-1000/0692.Top K Frequent Words.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution(object): 4 | def topKFrequent(self, words, k): 5 | """ 6 | :type words: List[str] 7 | :type k: int 8 | :rtype: List[str] 9 | """ 10 | return [item[0] for item in heapq.nsmallest(k, Counter(words).items(), key=lambda item: (-item[1], item[0]))] 11 | 12 | -------------------------------------------------------------------------------- /0501-1000/0693.Binary Number with Alternating Bits.ts: -------------------------------------------------------------------------------- 1 | function hasAlternatingBits(n: number): boolean { 2 | let cur = 1 - (n & 1); 3 | while (n) { 4 | if (!(n & 1 ^ cur)) return false; 5 | cur = n & 1; 6 | n >>= 1; 7 | } 8 | return true; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /0501-1000/0704.Binary Search.c: -------------------------------------------------------------------------------- 1 | int search(int* nums, int numsSize, int target){ 2 | int *left = nums, *right = nums + numsSize; 3 | while (left < right) { 4 | int *mid = left + (right - left) / 2; 5 | if (*mid < target) left = mid + 1; 6 | else right = mid; 7 | } 8 | return left < nums + numsSize && *left == target ? left - nums : -1; 9 | } 10 | -------------------------------------------------------------------------------- /0501-1000/0709.To Lower Case.ts: -------------------------------------------------------------------------------- 1 | function toLowerCase(s: string): string { 2 | return s.toLowerCase(); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /0501-1000/0717.1-bit and 2-bit Characters.ts: -------------------------------------------------------------------------------- 1 | function isOneBitCharacter(bits: number[]): boolean { 2 | let i = bits.length - 1; 3 | while (bits[--i]); 4 | return !((bits.length - i) % 2); 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /0501-1000/0724.Find Pivot Index.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def pivotIndex(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | sm = sum(nums) 8 | prefix = 0 9 | for i in xrange(len(nums)): 10 | if prefix == sm - prefix - nums[i]: 11 | return i 12 | prefix += nums[i] 13 | return -1 14 | 15 | -------------------------------------------------------------------------------- /0501-1000/0746.Min Cost Climbing Stairs.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minCostClimbingStairs(self, cost): 3 | """ 4 | :type cost: List[int] 5 | :rtype: int 6 | """ 7 | return min(reduce(lambda (c1, c2), c: (c2, c + min(c1, c2)), cost, (0, 0))) 8 | 9 | -------------------------------------------------------------------------------- /0501-1000/0760.Find Anagram Mappings.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution: 3 | def anagramMappings(self, A, B): 4 | mapping = collections.defaultdict(list) 5 | for i, num in enumerate(B): 6 | mapping[num].append(i) 7 | res = [] 8 | for num in A: 9 | res.append(mapping[num].pop()) 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /0501-1000/0766.Toeplitz Matrix.2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isToeplitzMatrix(int[][] matrix) { 3 | for (int i = 1; i < matrix.length; i++) { 4 | for (int j = 1; j < matrix[0].length; j++) { 5 | if (matrix[i][j] != matrix[i - 1][j - 1]) { 6 | return false; 7 | } 8 | } 9 | } 10 | return true; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /0501-1000/0769.Max Chunks To Make Sorted.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxChunksToSorted(self, arr): 3 | """ 4 | :type arr: List[int] 5 | :rtype: int 6 | """ 7 | rval = 0 8 | maximal = 0 9 | for i in xrange(len(arr)): 10 | maximal = max(maximal, arr[i]) 11 | if maximal == i: 12 | rval += 1 13 | return rval 14 | -------------------------------------------------------------------------------- /0501-1000/0771.Jewels and Stones.rb: -------------------------------------------------------------------------------- 1 | # @param {String} j 2 | # @param {String} s 3 | # @return {Integer} 4 | def num_jewels_in_stones(j, s) 5 | res = 0 6 | j = Set.new(j.chars) 7 | s.each_char { |c| res += (j.include?(c) ? 1 : 0) } 8 | res 9 | end 10 | -------------------------------------------------------------------------------- /0501-1000/0781.Rabbits in Forest.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution(object): 4 | def numRabbits(self, answers): 5 | """ 6 | :type answers: List[int] 7 | :rtype: int 8 | """ 9 | cnt = Counter(answers) 10 | res = 0 11 | for ans, reporters in cnt.items(): 12 | res += (reporters + ans) // (ans + 1) * (ans + 1) 13 | return res 14 | 15 | -------------------------------------------------------------------------------- /0501-1000/0791.Custom Sort String.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def customSortString(self, S, T): 3 | cnt = collections.Counter(T) 4 | res = ''.join(c * cnt[c] for c in S) 5 | cnt -= collections.Counter(res) 6 | return res + ''.join(c * v for c, v in cnt.items()) 7 | -------------------------------------------------------------------------------- /0501-1000/0791.Custom Sort String.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def customSortString(self, S, T): 3 | """ 4 | :type S: str 5 | :type T: str 6 | :rtype: str 7 | """ 8 | d = {c:i for i, c in enumerate(S)} 9 | return ''.join(sorted(T, key=lambda c: d.get(c, -1))) 10 | -------------------------------------------------------------------------------- /0501-1000/0796.Rotate String.ts: -------------------------------------------------------------------------------- 1 | function rotateString(s: string, goal: string): boolean { 2 | return s.length == goal.length && (s + s).includes(goal); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /0501-1000/0810.Chalkboard XOR Game.c: -------------------------------------------------------------------------------- 1 | bool xorGame(int* nums, int numsSize){ 2 | if (numsSize & 1) { 3 | int xor = 0; 4 | for (int i = 0; i < numsSize; i++) { 5 | xor ^= nums[i]; 6 | } 7 | return xor == 0; 8 | } 9 | return true; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /0501-1000/0822.Card Flipping Game.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def flipgame(self, fronts, backs): 3 | """ 4 | :type fronts: List[int] 5 | :type backs: List[int] 6 | :rtype: int 7 | """ 8 | same = {x for x, y in zip(fronts, backs) if x == y} 9 | return min((set(fronts) | set(backs)) - same or [0]) 10 | -------------------------------------------------------------------------------- /0501-1000/0836.Rectangle Overlap.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isRectangleOverlap(int[] rec1, int[] rec2) { 3 | int x1 = Math.max(rec1[0], rec2[0]); 4 | int y1 = Math.max(rec1[1], rec2[1]); 5 | int x2 = Math.min(rec1[2], rec2[2]); 6 | int y2 = Math.min(rec1[3], rec2[3]); 7 | return y1 < y2 && x1 < x2; 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /0501-1000/0858.Mirror Reflection.py: -------------------------------------------------------------------------------- 1 | from fractions import gcd 2 | class Solution(object): 3 | def mirrorReflection(self, p, q): 4 | """ 5 | :type p: int 6 | :type q: int 7 | :rtype: int 8 | """ 9 | g = gcd(p, q) 10 | x = p // g 11 | y = q // g 12 | return (~x & 1) << 1 or y & 1 13 | 14 | -------------------------------------------------------------------------------- /0501-1000/0867.Transpose Matrix.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} a 2 | # @return {Integer[][]} 3 | def transpose(a) 4 | res = [] 5 | a.each_with_index do |row, i| 6 | row.each_with_index do |col, j| 7 | res << [] if i == 0 8 | res[j] << a[i][j] 9 | end 10 | end 11 | res 12 | end 13 | -------------------------------------------------------------------------------- /0501-1000/0868.Binary Gap.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def binaryGap(self, N): 3 | """ 4 | :type N: int 5 | :rtype: int 6 | """ 7 | res = 0 8 | last = None 9 | for i in xrange(30): 10 | if N & 1: 11 | res = res if last is None else max(res, i - last) 12 | last = i 13 | N >>= 1 14 | return res 15 | -------------------------------------------------------------------------------- /0501-1000/0869.Reordered Power of 2.2.ts: -------------------------------------------------------------------------------- 1 | function reorderedPowerOf2(n: number): boolean { 2 | return squares.has(hash(n)); 3 | }; 4 | 5 | function hash(n: number) { 6 | return ('' + n).split('').sort().join(''); 7 | } 8 | 9 | const squares = new Set(); 10 | for (let square = 1; square <= 10e9 && square > 0; square <<= 1) { 11 | squares.add(hash(square)); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /0501-1000/0877.Stone Game.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def stoneGame(self, piles): 3 | """ 4 | :type piles: List[int] 5 | :rtype: bool 6 | """ 7 | return True 8 | -------------------------------------------------------------------------------- /0501-1000/0898.Bitwise ORs of Subarrays.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def subarrayBitwiseORs(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | prefixes = set() 8 | res = set() 9 | for num in A: 10 | prefixes = {num | prefix for prefix in prefixes} | {num} 11 | res |= prefixes 12 | return len(res) 13 | -------------------------------------------------------------------------------- /0501-1000/0905.Sort Array By Parity.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} a 2 | # @return {Integer[]} 3 | def sort_array_by_parity(a) 4 | i, j = 0, a.size - 1 5 | while i < j 6 | if a[i].even? 7 | i += 1 8 | else 9 | a[i], a[j] = a[j], a[i] 10 | j -= 1 11 | end 12 | end 13 | a 14 | end 15 | -------------------------------------------------------------------------------- /0501-1000/0908.Smallest Range I.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def smallestRangeI(self, A, K): 3 | """ 4 | :type A: List[int] 5 | :type K: int 6 | :rtype: int 7 | """ 8 | return max(max(A) - min(A) - 2 * K, 0) 9 | 10 | -------------------------------------------------------------------------------- /0501-1000/0912.Sort an Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def sortArray(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | return sorted(nums) 8 | -------------------------------------------------------------------------------- /0501-1000/0914.X of a Kind in a Deck of Cards.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasGroupsSizeX(self, deck: List[int]) -> bool: 3 | if len(deck) <= 1: 4 | return False 5 | c = collections.Counter(deck) 6 | gcd = c[deck[0]] 7 | for k, v in c.items(): 8 | gcd = math.gcd(gcd, v) 9 | if gcd == 1: 10 | return False 11 | return True 12 | -------------------------------------------------------------------------------- /0501-1000/0930.Binary Subarrays With Sum.ts: -------------------------------------------------------------------------------- 1 | function numSubarraysWithSum(nums: number[], goal: number): number { 2 | const seen = { 0: 1 }; 3 | let sum = 0, res = 0; 4 | for (let num of nums) { 5 | sum += num; 6 | res += seen[sum - goal] || 0; 7 | seen[sum] ||= 0; 8 | seen[sum]++; 9 | } 10 | return res; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /0501-1000/0961.N-Repeated Element in Size 2N Array.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def repeatedNTimes(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | for i in xrange(1, len(A)): 8 | if A[i - 1] == A[i]: 9 | return A[i] 10 | if A[0] in A[-2:]: 11 | return A[0] 12 | return A[1] 13 | -------------------------------------------------------------------------------- /0501-1000/0961.N-Repeated Element in Size 2N Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def repeatedNTimes(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | s = set() 8 | for a in A: 9 | if a in s: 10 | return a 11 | s.add(a) 12 | -------------------------------------------------------------------------------- /0501-1000/0976.Largest Perimeter Triangle.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def largestPerimeter(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | a = b = c = float("-inf") 8 | res = 0 9 | for d in sorted(A): 10 | a, b, c = b, c, d 11 | if a + b > c: 12 | res = a + b + c 13 | return res 14 | 15 | -------------------------------------------------------------------------------- /0501-1000/0991.Broken Calculator.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int brokenCalc(int X, int Y) { 3 | int res = 0; 4 | while (X < Y) { 5 | res += 1 + (Y & 1); 6 | Y = (Y + 1) / 2; 7 | } 8 | res += X - Y; 9 | return res; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /0501-1000/0997.Find the Town Judge.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @param {Integer[][]} trust 3 | # @return {Integer} 4 | def find_judge(n, trust) 5 | trusters = trust.map(&:first).to_set 6 | if trusters.size != n - 1 7 | return -1 8 | end 9 | judge = ((1..n).to_set - trusters).first 10 | trust.select { |src, tar| tar == judge } .map(&:first).to_set.size == n - 1 ? judge : -1 11 | end 12 | -------------------------------------------------------------------------------- /1001-1500/1014.Best Sightseeing Pair.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxScoreSightseeingPair(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | offer = A[0] 8 | rval = float('-inf') 9 | for i in xrange(1, len(A)): 10 | rval = max(rval, offer + A[i] - i) 11 | offer = max(offer, A[i] + i) 12 | return rval 13 | -------------------------------------------------------------------------------- /1001-1500/1017.Convert to Base -2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def baseNeg2(self, N): 3 | """ 4 | :type N: int 5 | :rtype: str 6 | """ 7 | rval = '' 8 | while N != 0: 9 | remainder = -N % 2 10 | N = (N - remainder) / -2 11 | rval = str(remainder) + rval 12 | return rval if rval else '0' 13 | -------------------------------------------------------------------------------- /1001-1500/1018.Binary Prefix Divisible By 5.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def prefixesDivBy5(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: List[bool] 6 | """ 7 | rval = [None] * len(A) 8 | n = 0 9 | for i, a in enumerate(A): 10 | n = ((n << 1) + a) % 5 11 | rval[i] = n == 0 12 | return rval 13 | -------------------------------------------------------------------------------- /1001-1500/1025.Divisor Game.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def divisorGame(self, N): 3 | """ 4 | :type N: int 5 | :rtype: bool 6 | """ 7 | return N % 2 == 0 8 | -------------------------------------------------------------------------------- /1001-1500/1029.Two City Scheduling.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def twoCitySchedCost(self, costs): 3 | """ 4 | :type costs: List[List[int]] 5 | :rtype: int 6 | """ 7 | diff = [(cost[0] - cost[1], cost) for cost in costs] 8 | diff.sort() 9 | N = len(costs) / 2 10 | return sum(pair[1][0] for pair in diff[:N]) + sum(pair[1][1] for pair in diff[N:]) 11 | -------------------------------------------------------------------------------- /1001-1500/1029.Two City Scheduling.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} costs 2 | # @return {Integer} 3 | def two_city_sched_cost(costs) 4 | costs.sort_by { |cost| cost[0] - cost[1] } 5 | .each_with_index 6 | .map { |cost, index| index < costs.size / 2 ? cost[0] : cost[1] } 7 | .sum 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1051.Height Checker.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def heightChecker(self, heights): 3 | """ 4 | :type heights: List[int] 5 | :rtype: int 6 | """ 7 | return sum(a != b for a, b in zip(sorted(heights), heights)) 8 | -------------------------------------------------------------------------------- /1001-1500/1071.Greatest Common Divisor of Strings.py: -------------------------------------------------------------------------------- 1 | import fractions 2 | class Solution(object): 3 | def gcdOfStrings(self, str1, str2): 4 | """ 5 | :type str1: str 6 | :type str2: str 7 | :rtype: str 8 | """ 9 | gcd = fractions.gcd(len(str1), len(str2)) 10 | if str1[:gcd] == str2[:gcd]: 11 | return str1[:gcd] 12 | return '' 13 | -------------------------------------------------------------------------------- /1001-1500/1108.Defanging an IP Address.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def defangIPaddr(self, address): 3 | """ 4 | :type address: str 5 | :rtype: str 6 | """ 7 | return address.replace('.', '[.]') 8 | -------------------------------------------------------------------------------- /1001-1500/1128.Number of Equivalent Domino Pairs.2.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def numEquivDominoPairs(self, dominoes): 3 | """ 4 | :type dominoes: List[List[int]] 5 | :rtype: int 6 | """ 7 | counter = collections.Counter(map(tuple, map(sorted, dominoes))) 8 | print counter 9 | return sum(x * (x - 1) / 2 for x in counter.values()) 10 | -------------------------------------------------------------------------------- /1001-1500/1137.N-th Tribonacci Number.py: -------------------------------------------------------------------------------- 1 | 2 | import functools 3 | class Solution: 4 | @functools.lru_cache(None) 5 | def tribonacci(self, n: int) -> int: 6 | if n == 0: 7 | return 0 8 | if n == 1: 9 | return 1 10 | if n == 2: 11 | return 1 12 | return self.tribonacci(n - 1) + self.tribonacci(n - 2) + self.tribonacci(n - 3) 13 | -------------------------------------------------------------------------------- /1001-1500/1165.Single-Row Keyboard.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def calculateTime(self, keyboard, word): 3 | dic = dict(map(reversed, enumerate(keyboard))) 4 | posi = map(dic.__getitem__, word) 5 | return sum(map( 6 | lambda (a, b): abs(a - b), 7 | zip(posi, [0] + posi[:-1]) 8 | )) 9 | -------------------------------------------------------------------------------- /1001-1500/1185.Day of the Week.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | class Solution(object): 3 | def dayOfTheWeek(self, day, month, year): 4 | """ 5 | :type day: int 6 | :type month: int 7 | :type year: int 8 | :rtype: str 9 | """ 10 | return date(year, month, day).strftime("%A") 11 | -------------------------------------------------------------------------------- /1001-1500/1189.Maximum Number of Balloons.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution(object): 3 | def maxNumberOfBalloons(self, text): 4 | """ 5 | :type text: str 6 | :rtype: int 7 | """ 8 | c = collections.Counter(text) 9 | #balloon 10 | return min(c['b'], c['a'], c['l'] / 2, c['o'] / 2, c['n']) 11 | -------------------------------------------------------------------------------- /1001-1500/1196.How Many Apples Can You Put into the Basket.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution(object): 3 | def maxNumberOfApples(self, arr): 4 | """ 5 | :type arr: List[int] 6 | :rtype: int 7 | """ 8 | s = cnt = 0 9 | for a in sorted(arr): 10 | s += a 11 | if s > 5000: 12 | break 13 | cnt += 1 14 | return cnt 15 | -------------------------------------------------------------------------------- /1001-1500/1207.Unique Number of Occurrences.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution(object): 3 | def uniqueOccurrences(self, arr): 4 | """ 5 | :type arr: List[int] 6 | :rtype: bool 7 | """ 8 | counter = collections.Counter(arr) 9 | cntOfCnt = collections.Counter(counter.values()) 10 | return all(map(lambda cnt: cnt == 1, cntOfCnt.values())) 11 | -------------------------------------------------------------------------------- /1001-1500/1217.Minimum Cost to Move Chips to The Same Position.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution(object): 3 | def minCostToMoveChips(self, chips): 4 | """ 5 | :type chips: List[int] 6 | :rtype: int 7 | """ 8 | counter = collections.Counter(map(lambda posi: posi%2, chips)) 9 | return min(counter[0], counter[1]) 10 | -------------------------------------------------------------------------------- /1001-1500/1227.Airplane Seat Assignment Probability.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double nthPersonGetsNthSeat(int n) { 3 | return n == 1 ? 1 : 0.5; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /1001-1500/1232.Check If It Is a Straight Line.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} coordinates 2 | # @return {Boolean} 3 | def check_straight_line(coordinates) 4 | ref = coordinates[0] 5 | slopes = coordinates[1..-1].map { |cord| cord.zip(ref).map { |x| x[0] - x[1] } }.map { |cord| cord[1].to_f / cord[0] } 6 | slopes = Set.new(slopes) 7 | slopes.size == 1 || slopes == Set.new([1.0/0, -1.0/0]) 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1238.Circular Permutation in Binary Representation.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def circularPermutation(self, n, start): 3 | """ 4 | :type n: int 5 | :type start: int 6 | :rtype: List[int] 7 | """ 8 | gray = [(b >> 1) ^ b for b in xrange(1 << n)] 9 | index = gray.index(start) 10 | return gray[index:] + gray[:index] 11 | -------------------------------------------------------------------------------- /1001-1500/1243.Array Transformation.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def transformArray(self, arr): 3 | """ 4 | :type arr: List[int] 5 | :rtype: List[int] 6 | """ 7 | for _ in xrange(min(arr), max(arr) + 2): 8 | arr = arr[:1] + [b + (a > b < c) - (a < b > c) for a, b, c in zip(arr[:-2], arr[1:len(arr) - 1], arr[2:])] + arr[-1:] 9 | return arr 10 | -------------------------------------------------------------------------------- /1001-1500/1250.Check If It Is a Good Array.py: -------------------------------------------------------------------------------- 1 | import fractions 2 | class Solution(object): 3 | def isGoodArray(self, nums): 4 | return reduce(fractions.gcd, nums, nums[0]) == 1 5 | -------------------------------------------------------------------------------- /1001-1500/1260.Shift 2D Grid.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def shiftGrid(self, grid, k): 3 | """ 4 | :type grid: List[List[int]] 5 | :type k: int 6 | :rtype: List[List[int]] 7 | """ 8 | m, n = len(grid), len(grid[0]) 9 | k %= m * n 10 | line = sum(grid, []) 11 | line = line[-k:] + line[:-k] 12 | return [line[i * n: (i + 1) * n]for i in range(m)] 13 | -------------------------------------------------------------------------------- /1001-1500/1266.Minimum Time Visiting All Points.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minTimeToVisitAllPoints(self, points): 3 | """ 4 | :type points: List[List[int]] 5 | :rtype: int 6 | """ 7 | return sum(max(abs(src[0] - dst[0]), abs(src[1] - dst[1])) for src, dst in zip(points[:-1], points[1:])) 8 | -------------------------------------------------------------------------------- /1001-1500/1271.Hexspeak.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def toHexspeak(self, num): 3 | """ 4 | :type num: str 5 | :rtype: str 6 | """ 7 | s = hex(int(num)).replace("0", "O").replace("1", "I")[2:].upper() 8 | return "ERROR" if set("23456789") & set(s) else s 9 | -------------------------------------------------------------------------------- /1001-1500/1281.Subtract the Product and Sum of Digits of an Integer.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def subtractProductAndSum(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | p = 1 8 | s = 0 9 | for c in str(n): 10 | p *= int(c) 11 | s += int(c) 12 | return p - s 13 | -------------------------------------------------------------------------------- /1001-1500/1290.Convert Binary Number in a Linked List to Integer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * struct ListNode *next; 6 | * }; 7 | */ 8 | 9 | 10 | int getDecimalValue(struct ListNode* head){ 11 | int res = 0; 12 | do { 13 | res <<= 1; 14 | res |= head->val; 15 | } while(head = head->next); 16 | return res; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /1001-1500/1295.Find Numbers with Even Number of Digits.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def findNumbers(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | return len(filter(lambda x : x % 2 == 0, map(len, map(str, nums)))) 8 | -------------------------------------------------------------------------------- /1001-1500/1297.Maximum Number of Occurrences of a Substring.2.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution: 3 | def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: 4 | res = collections.Counter(filter(lambda w: len(set(w)) <= maxLetters, (s[i:i + minSize] for i in range(len(s) - minSize + 1)))).most_common(1) 5 | return res[0][1] if res else 0 6 | -------------------------------------------------------------------------------- /1001-1500/1299.Replace Elements with Greatest Element on Right Side.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def replaceElements(self, arr): 3 | """ 4 | :type arr: List[int] 5 | :rtype: List[int] 6 | """ 7 | mx = -1 8 | for i in xrange(-1, -len(arr) - 1, -1): 9 | arr[i], mx = mx, max(mx, arr[i]) 10 | return arr 11 | -------------------------------------------------------------------------------- /1001-1500/1304.Find N Unique Integers Sum up to Zero.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer[]} 3 | def sum_zero(n) 4 | half = n / 2 5 | (1..half).to_a + (-half..-1).to_a + (n.odd? ? [0] : []) 6 | end 7 | -------------------------------------------------------------------------------- /1001-1500/1306.Jump Game III.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canReach(int[] arr, int index) { 3 | if (0 <= index && index < arr.length && arr[index] != -1) { 4 | int val = arr[index]; 5 | arr[index] = -1; 6 | return val == 0 || canReach(arr, index + val) || canReach(arr, index - val); 7 | } 8 | return false; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /1001-1500/1312.Minimum Insertion Steps to Make a String Palindrome.py: -------------------------------------------------------------------------------- 1 | import functools 2 | class Solution: 3 | def minInsertions(self, s: str) -> int: 4 | @functools.lru_cache(None) 5 | def dp(i, j): 6 | if j - i <= 1: return 0 7 | return dp(i + 1, j - 1) if s[i] == s[j - 1] else min(dp(i + 1, j), dp(i, j - 1)) + 1 8 | return dp(0, len(s)) 9 | -------------------------------------------------------------------------------- /1001-1500/1313.Decompress Run-Length Encoded List.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def decompressRLElist(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | res = [] 8 | for i in xrange(0, len(nums), 2): 9 | res += [nums[i + 1]] * nums[i] 10 | return res 11 | -------------------------------------------------------------------------------- /1001-1500/1317.Convert Integer to the Sum of Two No-Zero Integers.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def getNoZeroIntegers(self, n): 3 | """ 4 | :type n: int 5 | :rtype: List[int] 6 | """ 7 | for i in xrange(1, n): 8 | if "0" not in str(i) and "0" not in str(n - i): 9 | return [i, n - i] 10 | -------------------------------------------------------------------------------- /1001-1500/1323.Maximum 69 Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maximum69Number (self, num): 3 | """ 4 | :type num: int 5 | :rtype: int 6 | """ 7 | num = list(str(num)) 8 | for i, n in enumerate(num): 9 | if n == "6": 10 | num[i] = "9" 11 | break 12 | return int("".join(num)) 13 | -------------------------------------------------------------------------------- /1001-1500/1337.The K Weakest Rows in a Matrix.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def kWeakestRows(self, mat, k): 3 | """ 4 | :type mat: List[List[int]] 5 | :type k: int 6 | :rtype: List[int] 7 | """ 8 | return [ele[1] for ele in sorted((sum(row), index) for index, row in enumerate(mat))[:k]] 9 | 10 | -------------------------------------------------------------------------------- /1001-1500/1342.Number of Steps to Reduce a Number to Zero.c: -------------------------------------------------------------------------------- 1 | int numberOfSteps (int num){ 2 | int res; 3 | for (res = 0; num; res ++) { 4 | if (num & 1) num -= 1; 5 | else num >>= 1; 6 | } 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /1001-1500/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def numOfSubarrays(self, arr, k, threshold): 3 | res, s = 0, sum(arr[: k - 1]) 4 | threshold *= k 5 | t = k - 1 6 | for i in xrange(t, len(arr)): 7 | s += arr[i] 8 | res += s >= threshold 9 | s -= arr[i - t] 10 | return res 11 | -------------------------------------------------------------------------------- /1001-1500/1344.Angle Between Hands of a Clock.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def angleClock(self, hour, minutes): 3 | """ 4 | :type hour: int 5 | :type minutes: int 6 | :rtype: float 7 | """ 8 | ma = minutes * 6 9 | ha = minutes / 2.0 + (hour % 12) * 30 10 | return min(abs(ma - ha), 360 - abs(ma - ha)) 11 | -------------------------------------------------------------------------------- /1001-1500/1351.Count Negative Numbers in a Sorted Matrix.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def countNegatives(self, grid): 3 | """ 4 | :type grid: List[List[int]] 5 | :rtype: int 6 | """ 7 | cnt = 0 8 | for row in grid: 9 | for a in row: 10 | if a < 0: 11 | cnt += 1 12 | return cnt 13 | -------------------------------------------------------------------------------- /1001-1500/1360.Number of Days Between Two Dates.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | class Solution(object): 3 | def daysBetweenDates(self, date1, date2): 4 | """ 5 | :type date1: str 6 | :type date2: str 7 | :rtype: int 8 | """ 9 | return abs((date(*map(int, date1.split("-"))) - date(*map(int, date2.split("-")))).days) 10 | -------------------------------------------------------------------------------- /1001-1500/1374.Generate a String With Characters That Have Odd Counts.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def generateTheString(self, n): 3 | """ 4 | :type n: int 5 | :rtype: str 6 | """ 7 | if n % 2: 8 | return 'a' * n 9 | else: 10 | return 'a' + 'b' * (n - 1) 11 | -------------------------------------------------------------------------------- /1001-1500/1375.Number of Times Binary String Is Prefix-Aligned.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def numTimesAllBlue(self, light): 3 | """ 4 | :type light: List[int] 5 | :rtype: int 6 | """ 7 | mx = cnt = 0 8 | for i in xrange(len(light)): 9 | mx = max(mx, light[i]) 10 | if mx == i + 1: 11 | cnt += 1 12 | return cnt 13 | -------------------------------------------------------------------------------- /1001-1500/1387.Sort Integers by The Power Value.py: -------------------------------------------------------------------------------- 1 | import functools 2 | @functools.lru_cache(None) 3 | def power(x): 4 | if x == 1: 5 | return 0 6 | if x % 2: 7 | return power(x * 3 + 1) + 1 8 | else: 9 | return power(x / 2) + 1 10 | 11 | class Solution: 12 | def getKth(self, lo: int, hi: int, k: int) -> int: 13 | return sorted(range(lo, hi + 1), key=power)[k - 1] 14 | -------------------------------------------------------------------------------- /1001-1500/1389.Create Target Array in the Given Order.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def createTargetArray(self, nums, index): 3 | """ 4 | :type nums: List[int] 5 | :type index: List[int] 6 | :rtype: List[int] 7 | """ 8 | target = [] 9 | for num, i in zip(nums, index): 10 | target.insert(i, num) 11 | return target 12 | -------------------------------------------------------------------------------- /1001-1500/1399.Count Largest Group.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | def count_largest_group(n) 4 | group = Hash.new 0 5 | (1..n).each { |x| group[x.to_s.split("").map(&:to_i).sum] += 1 } 6 | mx = group.values.max 7 | group.values.select { |value| value == mx }.size 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1400.Construct K Palindrome Strings.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution(object): 3 | def canConstruct(self, s, k): 4 | """ 5 | :type s: str 6 | :type k: int 7 | :rtype: bool 8 | """ 9 | return sum(x & 1 for x in Counter(s).values()) <= k <= len(s) 10 | -------------------------------------------------------------------------------- /1001-1500/1400.Construct K Palindrome Strings.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @param {Integer} k 3 | # @return {Boolean} 4 | def can_construct(s, k) 5 | counter = Hash.new 0 6 | s.each_char { |c| counter[c] ^= 1 } 7 | k <= s.size and counter.values.sum <= k 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1408.String Matching in an Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def stringMatching(self, words): 3 | """ 4 | :type words: List[str] 5 | :rtype: List[str] 6 | """ 7 | res = [] 8 | for w1 in words: 9 | for w2 in words: 10 | if w1 != w2 and w1 in w2: 11 | res.append(w1) 12 | break 13 | return res 14 | -------------------------------------------------------------------------------- /1001-1500/1410.HTML Entity Parser.rb: -------------------------------------------------------------------------------- 1 | # @param {String} text 2 | # @return {String} 3 | def entity_parser(text) 4 | trans = [ 5 | [""", '"'], 6 | ["'", "'"], 7 | [">", ">"], 8 | ["<", "<"], 9 | ["⁄", "/"], 10 | ["&", "&"] 11 | ] 12 | trans.each { |tr| text.gsub! tr[0], tr[1] } 13 | text 14 | end 15 | -------------------------------------------------------------------------------- /1001-1500/1413.Minimum Value to Get Positive Step by Step Sum.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def min_start_value(nums) 4 | res = 1.0/0.0 5 | nums.reduce(0) { |sum, n| res = [sum + n, res].min; sum + n } 6 | [-res + 1, 1].max 7 | end 8 | -------------------------------------------------------------------------------- /1001-1500/1426.Counting Elements.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} arr 2 | # @return {Integer} 3 | def count_elements(arr) 4 | s = arr.to_set 5 | arr.reduce(0) { |cnt, a| (s.include? a + 1) ? cnt + 1 : cnt } 6 | end 7 | -------------------------------------------------------------------------------- /1001-1500/1427.Perform String Shifts.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @param {Integer[][]} shift 3 | # @return {String} 4 | def string_shift(s, shift) 5 | sft = shift.reduce(0) { |acc, sft| acc + (sft[0].zero? ? sft[1] : -sft[1]) } 6 | sft %= s.size 7 | s[sft..-1] + s[0...sft] 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1431.Kids With the Greatest Number of Candies.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} candies 2 | # @param {Integer} extra_candies 3 | # @return {Boolean[]} 4 | def kids_with_candies(candies, extra_candies) 5 | min = candies.max - extra_candies 6 | candies.map { |candy| candy >= min } 7 | end 8 | -------------------------------------------------------------------------------- /1001-1500/1432.Max Difference You Can Get From Changing an Integer.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} num 2 | # @return {Integer} 3 | def max_diff(num) 4 | s = num.to_s 5 | mx = s.gsub(s.chars.detect(->{"-"}) { |c| c != "9" }, "9") 6 | if s[0] == "1" 7 | mn = s.gsub(s.chars.detect(->{"-"}) { |c| c != "0" && c != "1" }, "0") 8 | else 9 | mn = s.gsub(s[0], "1") 10 | end 11 | mx.to_i - mn.to_i 12 | end 13 | -------------------------------------------------------------------------------- /1001-1500/1433.Check If a String Can Break Another String.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s1 2 | # @param {String} s2 3 | # @return {Boolean} 4 | def check_if_can_break(s1, s2) 5 | s1 = s1.chars.sort.join 6 | s2 = s2.chars.sort.join 7 | s1, s2 = s2, s1 if s1 > s2 8 | s1.chars.zip(s2.chars).all? { |c1, c2| c1 <= c2 } 9 | end 10 | -------------------------------------------------------------------------------- /1001-1500/1436.Destination City.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def destCity(self, paths): 3 | """ 4 | :type paths: List[List[str]] 5 | :rtype: str 6 | """ 7 | src = set() 8 | dst = set() 9 | for path in paths: 10 | src.add(path[0]) 11 | dst.add(path[1]) 12 | return (dst - src).pop() 13 | -------------------------------------------------------------------------------- /1001-1500/1446.Consecutive Characters.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Integer} 3 | def max_power(s) 4 | cnt = res = 0 5 | p = nil 6 | for c in s.each_char 7 | if c == p 8 | cnt += 1 9 | else 10 | p = c 11 | cnt = 1 12 | end 13 | res = [res, cnt].max 14 | end 15 | res 16 | end 17 | -------------------------------------------------------------------------------- /1001-1500/1447.Simplified Fractions.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {String[]} 3 | def simplified_fractions(n) 4 | res = [] 5 | for num in (1...n) 6 | for den in (num + 1 .. n) 7 | res << "#{num}/#{den}" if num.gcd(den) == 1 8 | end 9 | end 10 | res 11 | end 12 | -------------------------------------------------------------------------------- /1001-1500/1450.Number of Students Doing Homework at a Given Time.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def busyStudent(self, startTime, endTime, queryTime): 3 | """ 4 | :type startTime: List[int] 5 | :type endTime: List[int] 6 | :type queryTime: int 7 | :rtype: int 8 | """ 9 | return sum(s <= queryTime <= e for s, e in zip(startTime, endTime)) 10 | 11 | -------------------------------------------------------------------------------- /1001-1500/1451.Rearrange Words in a Sentence.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def arrangeWords(self, text): 3 | """ 4 | :type text: str 5 | :rtype: str 6 | """ 7 | return " ".join(t[1].lower() for t in sorted(enumerate(text.split(" ")), cmp=lambda a, b: len(a[1]) - len(b[1]) or a[0] - b[0])).capitalize() 8 | -------------------------------------------------------------------------------- /1001-1500/1460.Make Two Arrays Equal by Reversing Subarrays.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} target 2 | # @param {Integer[]} arr 3 | # @return {Boolean} 4 | def can_be_equal(target, arr) 5 | target.sort == arr.sort 6 | end 7 | -------------------------------------------------------------------------------- /1001-1500/1461.Check If a String Contains All Binary Codes of Size K.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @param {Integer} k 3 | # @return {Boolean} 4 | def has_all_codes(s, k) 5 | set = Set.new 6 | mask = (1 << k) - 1 7 | base = s[0...(k - 1)].to_i 8 | for i in (k - 1)...s.size 9 | base = ((base << 1) | s[i].to_i) & mask 10 | set << base 11 | end 12 | set.size == 2 ** k 13 | end 14 | -------------------------------------------------------------------------------- /1001-1500/1470.Shuffle the Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def shuffle(self, nums, n): 3 | """ 4 | :type nums: List[int] 5 | :type n: int 6 | :rtype: List[int] 7 | """ 8 | res = [] 9 | for i in xrange(n): 10 | res.append(nums[i]) 11 | res.append(nums[n + i]) 12 | return res 13 | -------------------------------------------------------------------------------- /1001-1500/1471.The k Strongest Values in an Array.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} arr 2 | # @param {Integer} k 3 | # @return {Integer[]} 4 | def get_strongest(arr, k) 5 | m = (arr.size - 1) / 2 6 | median = arr.sort[m] 7 | arr.sort { |a, b| (a - median).abs == (b - median).abs ? (b - a) : ((b - median).abs - (a - median).abs) } [0...k] 8 | end 9 | -------------------------------------------------------------------------------- /1001-1500/1475.Final Prices With a Special Discount in a Shop.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} prices 2 | # @return {Integer[]} 3 | def final_prices(prices) 4 | stack = [0] 5 | res = [] 6 | for price in prices.reverse 7 | stack.pop while stack[-1] > price 8 | res << [price - stack.last, 0].max 9 | stack << price if price != stack.last 10 | end 11 | res.reverse 12 | end 13 | -------------------------------------------------------------------------------- /1001-1500/1480.Running Sum of 1d Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def runningSum(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | for i in xrange(1, len(nums)): 8 | nums[i] += nums[i - 1] 9 | return nums 10 | -------------------------------------------------------------------------------- /1001-1500/1486.XOR Operation in an Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def xorOperation(self, n, start): 3 | """ 4 | :type n: int 5 | :type start: int 6 | :rtype: int 7 | """ 8 | nums = list(start + 2 * i for i in xrange(n)) 9 | res = 0 10 | for num in nums: 11 | res ^= num 12 | return res 13 | -------------------------------------------------------------------------------- /1001-1500/1491.Average Salary Excluding the Minimum and Maximum Salary.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} salary 2 | # @return {Float} 3 | def average(salary) 4 | (salary.sum - salary.min - salary.max) / (salary.size - 2).to_f 5 | end 6 | -------------------------------------------------------------------------------- /1001-1500/1492.The kth Factor of n.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @param {Integer} k 3 | # @return {Integer} 4 | def kth_factor(n, k) 5 | return -1 if k > n 6 | cnt = 0 7 | for i in 1..n 8 | cnt += 1 if (n % i).zero? 9 | return i if cnt == k 10 | end 11 | return -1 12 | end 13 | -------------------------------------------------------------------------------- /1501-2000/1503.Last Moment Before All Ants Fall Out of a Plank.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def getLastMoment(self, n, left, right): 3 | """ 4 | :type n: int 5 | :type left: List[int] 6 | :type right: List[int] 7 | :rtype: int 8 | """ 9 | l = max(left or [0]) 10 | r = min(right or [n]) 11 | return max([n - r, l]) 12 | -------------------------------------------------------------------------------- /1501-2000/1507.Reformat Date.md: -------------------------------------------------------------------------------- 1 | # Ruby 1-liner cheat 2 | 3 | > Source: [732064](https://leetcode.com/problems/reformat-date/discuss/732064/ruby-1-liner-cheat) 4 | > 5 | > Created at: 2020-07-12 07:43:40 6 | > 7 | > Updated at: 2020-07-12 08:36:56 8 | 9 | ---- 10 | 11 | ``` 12 | require \'date\' 13 | # @param {String} date 14 | # @return {String} 15 | def reformat_date(date) 16 | Date.parse(date).to_s 17 | end 18 | ``` -------------------------------------------------------------------------------- /1501-2000/1507.Reformat Date.rb: -------------------------------------------------------------------------------- 1 | require 'date' 2 | # @param {String} date 3 | # @return {String} 4 | def reformat_date(date) 5 | Date.parse(date).to_s 6 | end 7 | -------------------------------------------------------------------------------- /1501-2000/1512.Number of Good Pairs.py: -------------------------------------------------------------------------------- 1 | import collections 2 | class Solution(object): 3 | def numIdenticalPairs(self, nums): 4 | """ 5 | :type nums: List[int] 6 | :rtype: int 7 | """ 8 | cnt = collections.Counter() 9 | res = 0 10 | for num in nums: 11 | res += cnt[num] 12 | cnt[num] += 1 13 | return res 14 | -------------------------------------------------------------------------------- /1501-2000/1523.Count Odd Numbers in an Interval Range.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countOdds(int low, int high) { 3 | return (high + 1) / 2 - low / 2; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /1501-2000/1526.Minimum Number of Increments on Subarrays to Form a Target Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minNumberOperations(int[] target) { 3 | int left = 0, res = 0; 4 | for (int num : target) { 5 | res += Math.max(left - num, 0); 6 | left = num; 7 | } 8 | res += left; 9 | return res; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /1501-2000/1528.Shuffle String.c: -------------------------------------------------------------------------------- 1 | char * restoreString(char * s, int* indices, int indicesSize){ 2 | for (int i = 0; i < indicesSize; i++) { 3 | int j = i; 4 | while (indices[j] >= 0) 5 | { 6 | char tmp = s[i]; s[i] = s[indices[j]]; s[indices[j]] = tmp; 7 | indices[j] = ~indices[j]; 8 | j = ~indices[j]; 9 | } 10 | } 11 | return s; 12 | } -------------------------------------------------------------------------------- /1501-2000/1528.Shuffle String.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def restoreString(self, s, indices): 3 | """ 4 | :type s: str 5 | :type indices: List[int] 6 | :rtype: str 7 | """ 8 | res = [None] * len(s) 9 | for i, target in enumerate(indices): 10 | res[target] = s[i] 11 | return "".join(res) -------------------------------------------------------------------------------- /1501-2000/1529.Minimum Suffix Flips.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minFlips(self, target): 3 | """ 4 | :type target: str 5 | :rtype: int 6 | """ 7 | state = '0' 8 | res = 0 9 | for b in target: 10 | if state != b: 11 | state = b 12 | res += 1 13 | return res -------------------------------------------------------------------------------- /1501-2000/1551.Minimum Operations to Make Array Equal.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minOperations(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | if n % 2 == 1: 8 | return (n + 1) // 2 * (n // 2) 9 | else: 10 | return n * n // 4 11 | -------------------------------------------------------------------------------- /1501-2000/1561.Maximum Number of Coins You Can Get.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxCoins(self, piles): 3 | """ 4 | :type piles: List[int] 5 | :rtype: int 6 | """ 7 | piles.sort(reverse=True) 8 | return sum(piles[i] for i in xrange(1, len(piles) / 3 * 2, 2)) 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1572.Matrix Diagonal Sum.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def diagonalSum(self, mat): 3 | """ 4 | :type mat: List[List[int]] 5 | :rtype: int 6 | """ 7 | n = len(mat) 8 | res = sum(mat[i][i] + mat[i][n - 1 - i] for i in xrange(n)) 9 | return res - mat[n // 2][n // 2] if n % 2 else res 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1619.Mean of Array After Removing Some Elements.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution(object): 3 | def trimMean(self, arr): 4 | """ 5 | :type arr: List[int] 6 | :rtype: float 7 | """ 8 | size = len(arr) // 20 9 | print(list(sorted(arr))[size:-size-1]) 10 | return sum(list(sorted(arr))[size:-size]) / (len(arr) * 0.9) 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1637.Widest Vertical Area Between Two Points Containing No Points.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxWidthOfVerticalArea(self, points): 3 | """ 4 | :type points: List[List[int]] 5 | :rtype: int 6 | """ 7 | xs = sorted(map(lambda p:p[0], points)) 8 | return max(b - a for a, b in zip(xs[:-1], xs[1:])) 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1641.Count Sorted Vowel Strings.py: -------------------------------------------------------------------------------- 1 | from functools import lru_cache 2 | class Solution: 3 | @lru_cache(None) 4 | def countVowelStrings(self, n: int, charset=5) -> int: 5 | if charset == 1: 6 | return 1 7 | if n == 1: 8 | return charset 9 | return sum(self.countVowelStrings(n - 1, new_charset) for new_charset in range(1, charset + 1)) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1662.Check If Two String Arrays are Equivalent.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def arrayStringsAreEqual(self, word1, word2): 3 | """ 4 | :type word1: List[str] 5 | :type word2: List[str] 6 | :rtype: bool 7 | """ 8 | return "".join(word1) == "".join(word2) 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1664.Ways to Make a Fair Array.2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def waysToMakeFair(self, nums: List[int]) -> int: 3 | l = [0, 0] 4 | r = [sum(nums[0::2]), sum(nums[1::2])] 5 | res = 0 6 | for i, num in enumerate(nums): 7 | r[i % 2] -= num 8 | res += int(l[1] + r[0] == l[0] + r[1]) 9 | l[i % 2] += num 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1665.Minimum Initial Energy to Finish Tasks.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minimumEffort(self, tasks): 3 | """ 4 | :type tasks: List[List[int]] 5 | :rtype: int 6 | """ 7 | energy = 0 8 | for task in sorted(tasks, key=lambda t: (t[1] - t[0], t[1])): 9 | energy = max(energy + task[0], task[1]) 10 | return energy 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1668.Maximum Repeating Substring.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxRepeating(self, sequence, word): 3 | """ 4 | :type sequence: str 5 | :type word: str 6 | :rtype: int 7 | """ 8 | for res in xrange(1, len(sequence) + 2): 9 | if word * res not in sequence: 10 | return res - 1 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1672.Richest Customer Wealth.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maximumWealth(self, accounts): 3 | """ 4 | :type accounts: List[List[int]] 5 | :rtype: int 6 | """ 7 | return max(map(sum, accounts)) 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1684.Count the Number of Consistent Strings.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def countConsistentStrings(self, allowed, words): 3 | """ 4 | :type allowed: str 5 | :type words: List[str] 6 | :rtype: int 7 | """ 8 | allowed = set(allowed) 9 | return sum(int(set(word).issubset(allowed)) for word in words) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1688.Count of Matches in Tournament.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def numberOfMatches(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | res = 0 8 | while n != 1: 9 | res += n / 2 10 | n = n / 2 + n % 2 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minPartitions(self, n): 3 | """ 4 | :type n: str 5 | :rtype: int 6 | """ 7 | return int(max(n)) 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1716.Calculate Money in Leetcode Bank.php: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | /** 4 | * @param Integer $n 5 | * @return Integer 6 | */ 7 | function totalMoney($n) { 8 | $week = floor($n / 7); 9 | $day = $n % 7; 10 | return 28 * $week + ($week - 1) * $week / 2 * 7 + ($week + $week + $day + 1) * $day / 2; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /1501-2000/1720.Decode XORed Array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def decode(self, encoded, first): 3 | """ 4 | :type encoded: List[int] 5 | :type first: int 6 | :rtype: List[int] 7 | """ 8 | res = [first] 9 | for item in encoded: 10 | res.append(res[-1] ^ item) 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1725.Number Of Rectangles That Can Form The Largest Square.py: -------------------------------------------------------------------------------- 1 | iclass Solution(object): 2 | def countGoodRectangles(self, rectangles): 3 | """ 4 | :type rectangles: List[List[int]] 5 | :rtype: int 6 | """ 7 | maxLen = max(min(r) for r in rectangles) 8 | return len([r for r in rectangles if min(r) >= maxLen]) 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1732.Find the Highest Altitude.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def largestAltitude(self, gain): 3 | """ 4 | :type gain: List[int] 5 | :rtype: int 6 | """ 7 | return reduce(lambda acc, g: (acc[0] + g, max(acc[1], acc[0] + g)), gain, (0, 0))[1] 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1748.Sum of Unique Elements.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def sumOfUnique(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | return sum(num for num, cnt in Counter(nums).iteritems() if cnt == 1) 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1758.Minimum Changes To Make Alternating Binary String.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minOperations(self, s): 3 | """ 4 | :type s: str 5 | :rtype: int 6 | """ 7 | s1, s2 = s[0:len(s):2], s[1:len(s):2] 8 | c1, c2 = s1.count("0"), s2.count("0") 9 | return min(len(s1) - c1 + c2, len(s2) - c2 + c1) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1784.Check if Binary String Has at Most One Segment of Ones.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def checkOnesSegment(self, s): 3 | """ 4 | :type s: str 5 | :rtype: bool 6 | """ 7 | return Counter(zip(s[:-1], s[1:]))[tuple("01")] < 1 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1785.Minimum Elements to Add to Form a Given Sum.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minElements(self, nums, limit, goal): 3 | """ 4 | :type nums: List[int] 5 | :type limit: int 6 | :type goal: int 7 | :rtype: int 8 | """ 9 | return (abs(goal - sum(nums)) + limit - 1) // limit 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1791.Find Center of Star Graph.2.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | class Solution(object): 4 | def findCenter(self, edges): 5 | """ 6 | :type edges: List[List[int]] 7 | :rtype: int 8 | """ 9 | for u in edges[0]: 10 | if u in edges[1]: 11 | return u 12 | assert(False) 13 | 14 | -------------------------------------------------------------------------------- /1501-2000/1798.Maximum Number of Consecutive Values You Can Make.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int getMaximumConsecutive(int[] coins) { 3 | Arrays.sort(coins); 4 | int res = 0; 5 | for (int coin : coins) { 6 | if (coin > res + 1) break; 7 | res += coin; 8 | } 9 | return res + 1; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1800.Maximum Ascending Subarray Sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxAscendingSum(self, nums: List[int]) -> int: 3 | res = sm = 0 4 | nums.append(-1) 5 | for i in range(len(nums) - 1): 6 | if nums[i] > nums[i - 1]: 7 | sm += nums[i] 8 | else: 9 | sm = nums[i] 10 | res = max(res, sm) 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1805.Number of Different Integers in a String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numDifferentIntegers(self, word: str) -> int: 3 | res = [""] 4 | for c in word: 5 | if c.isdigit(): 6 | res[-1] += c 7 | elif res[-1]: 8 | res.append("") 9 | s = set(int(num) for num in res if num) 10 | return len(s) 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1806.Minimum Number of Operations to Reinitialize a Permutation.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reinitializePermutation(self, n: int) -> int: 3 | arr = list(range(n)) 4 | arr2 = list(arr) 5 | t = 1 6 | arr2 = arr2[0::2] + arr2[1::2] 7 | while arr != arr2: 8 | t += 1 9 | arr2 = arr2[0::2] + arr2[1::2] 10 | return t 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1812.Determine Color of a Chessboard Square.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean squareIsWhite(String coordinates) { 3 | return (coordinates.charAt(0) - 'a' + coordinates.charAt(1) - '1') % 2 != 0; 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1816.Truncate Sentence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def truncateSentence(self, s: str, k: int) -> str: 3 | return " ".join(s.split(" ")[:k]) 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1819.Number of Different Subsequences GCDs.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | class Solution: 4 | def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int: 5 | num = set(nums) 6 | mx = max(nums) 7 | return sum(candidate == math.gcd( 8 | *(multi for multi in range(candidate, mx + 1, candidate) if multi in num) 9 | ) for candidate in range(1, mx + 1)) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1822.Sign of the Product of an Array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arraySign(self, nums: List[int]) -> int: 3 | sign = 1 4 | for num in nums: 5 | if num == 0: 6 | return 0 7 | if num < 0: 8 | sign = -sign 9 | return sign 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1827.Minimum Operations to Make the Array Increasing.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minOperations(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | res = 0 8 | for i in xrange(1, len(nums)): 9 | res += max(0, nums[i - 1] + 1 - nums[i]) 10 | nums[i] = max(nums[i], nums[i - 1] + 1) 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1832.Check if the Sentence Is Pangram.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfPangram(self, sentence: str) -> bool: 3 | return len(set(sentence)) == 26 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1833.Maximum Ice Cream Bars.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxIceCream(self, costs: List[int], coins: int) -> int: 3 | costs.sort() 4 | res = 0 5 | for cost in costs: 6 | if coins < cost: 7 | break 8 | res += 1 9 | coins -= cost 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1837.Sum of Digits in Base K.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumBase(self, n: int, k: int) -> int: 3 | res = 0 4 | while n: 5 | res += n % k 6 | n //= k 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1844.Replace All Digits with Characters.c: -------------------------------------------------------------------------------- 1 | char shift(char c, char x) { 2 | return 'a' + (c - 'a' + x - '0') % 26; 3 | } 4 | 5 | char * replaceDigits(char * s){ 6 | for (char* p = s; *p != '\0' && *(p + 1) != '\0'; p += 2) { 7 | *(p + 1) = shift(*p, *(p + 1)); 8 | } 9 | return s; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1846.Maximum Element After Decreasing and Rearranging.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maximumElementAfterDecrementingAndRearranging(self, arr): 3 | """ 4 | :type arr: List[int] 5 | :rtype: int 6 | """ 7 | arr.sort() 8 | arr.append(0) 9 | for i in range(len(arr) - 1): 10 | arr[i] = min(arr[i], arr[i - 1] + 1) 11 | return arr[-2] 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1848.Minimum Distance to the Target Element.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getMinDistance(self, nums: List[int], target: int, start: int) -> int: 3 | res = float("inf") 4 | for i in range(len(nums)): 5 | if nums[i] == target: 6 | res = min(res, abs(i - start)) 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1859.Sorting the Sentence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortSentence(self, s: str) -> str: 3 | return " ".join(word for (_, word) in sorted((word[-1], word[:-1]) for word in s.split())) 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1860.Incremental Memory Leak.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def memLeak(self, memory1: int, memory2: int) -> List[int]: 3 | memories = [memory1, memory2] 4 | t = 1 5 | while True: 6 | i = 0 if memories[0] >= memories[1] else 1 7 | if memories[i] - t < 0: 8 | break 9 | memories[i] -= t 10 | t += 1 11 | return [t] + memories 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1863.Sum of All Subset XOR Totals.py: -------------------------------------------------------------------------------- 1 | from itertools import chain, combinations 2 | 3 | class Solution: 4 | def subsetXORSum(self, nums: List[int]) -> int: 5 | xors = [] 6 | for num in nums: 7 | xors.extend([num ^ xor for xor in xors]) 8 | xors.append(num) 9 | return sum(xors) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1869.Longer Contiguous Segments of Ones than Zeros.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkZeroOnes(self, s: str) -> bool: 3 | ones = max(len(word) for word in s.split("0")) 4 | zeros = max(len(word) for word in s.split("1")) 5 | return ones > zeros 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1872.Stone Game VIII.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def stoneGameVIII(self, stones: List[int]) -> int: 3 | diff = prefix = sum(stones) 4 | for i in range(len(stones) - 2, 0, -1): 5 | prefix -= stones[i + 1] 6 | diff = max(prefix - diff, diff) 7 | return diff 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1876.Substrings of Size Three with Distinct Characters.c: -------------------------------------------------------------------------------- 1 | int countGoodSubstrings(char * s){ 2 | int len = strlen(s); 3 | int res = 0; 4 | for (int i = 0; i < len - 2; i++) { 5 | if (s[i] != s[i + 1] && s[i] != s[i + 2] && s[i + 1] != s[i + 2]) res++; 6 | } 7 | return res; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1877.Minimize Maximum Pair Sum in Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPairSum(int[] nums) { 3 | Arrays.sort(nums); 4 | int res = 0; 5 | for (int i = 0; i < nums.length / 2; i++) { 6 | res = Math.max(res, nums[i] + nums[nums.length - 1 - i]); 7 | } 8 | return res; 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /1501-2000/1880.Check if Word Equals Summation of Two Words.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: 3 | def translate(s): 4 | return int("".join(str(ord(c) - ord('a')) for c in s)) 5 | return translate(firstWord) + translate(secondWord) == translate(targetWord) 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1884.Egg Drop With 2 Eggs and N Floors.2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int twoEggDrop(int n){ 4 | return ceil((sqrt(1 + 8 * n) - 1) / 2); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1884.Egg Drop With 2 Eggs and N Floors.c: -------------------------------------------------------------------------------- 1 | int twoEggDrop(int n){ 2 | int sum = 0, res = 0; 3 | while ((sum += res++) < n); 4 | return res - 1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1886.Determine Whether Matrix Can Be Obtained By Rotation.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: 3 | target = tuple(map(tuple, target)) 4 | for i in range(4): 5 | if (mat := tuple(zip(*reversed(mat)))) == target: 6 | return True 7 | return False 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1894.Find the Student that Will Replace the Chalk.ts: -------------------------------------------------------------------------------- 1 | function chalkReplacer(chalk: number[], k: number): number { 2 | const sum = chalk.reduce((a, b) => a + b); 3 | k %= sum; 4 | for (let i = 0; i < chalk.length; i++) { 5 | k -= chalk[i]; 6 | if (k < 0) return i; 7 | } 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1897.Redistribute Characters to Make All Strings Equal.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution(object): 4 | def makeEqual(self, words): 5 | """ 6 | :type words: List[str] 7 | :rtype: bool 8 | """ 9 | return all(value % len(words) == 0 for value in sum(map(Counter, words), Counter()).values()) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1903.Largest Odd Number in String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestOddNumber(self, num: str) -> str: 3 | for i in range(len(num) - 1, -1, -1): 4 | if num[i] in "13579": 5 | return num[:i + 1] 6 | return "" 7 | 8 | -------------------------------------------------------------------------------- /1501-2000/1910.Remove All Occurrences of a Substring.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} part 4 | * @return {string} 5 | */ 6 | var removeOccurrences = function(s, part) { 7 | let i = s.indexOf(part); 8 | while (i >= 0) { 9 | s = s.slice(0, i) + s.slice(i + part.length); 10 | i = s.indexOf(part); 11 | } 12 | return s; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /1501-2000/1911.Maximum Alternating Subsequence Sum.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var maxAlternatingSum = function (nums) { 6 | let res = 0; 7 | let sm1 = sm2 = 0; 8 | for (let num of nums) { 9 | [sm1, sm2] = [Math.max(sm1, sm2 - num, 0), Math.max(sm2, sm1 + num)]; 10 | res = Math.max(res, sm2); 11 | } 12 | return res; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /1501-2000/1913.Maximum Product Difference Between Two Pairs.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Solution(object): 4 | def maxProductDifference(self, nums): 5 | """ 6 | :type nums: List[int] 7 | :rtype: int 8 | """ 9 | return int.__mul__(*heapq.nlargest(2, nums)) - int.__mul__(*heapq.nsmallest(2, nums)) 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1920.Build Array from Permutation.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def buildArray(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | return [nums[nums[i]] for i in xrange(len(nums))] 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1921.Eliminate Maximum Number of Monsters.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int: 3 | for i, minute in enumerate(sorted(dist[i]/speed[i] for i in range(len(dist)))): 4 | if i >= minute: 5 | return i 6 | return len(dist) 7 | 8 | -------------------------------------------------------------------------------- /1501-2000/1922.Count Good Numbers.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def countGoodNumbers(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | MOD = 10 ** 9 + 7 8 | return (pow(5, (n + 1) // 2, MOD) * pow(4, n // 2, MOD)) % MOD 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1929.Concatenation of Array.py: -------------------------------------------------------------------------------- 1 | iclass Solution: 2 | def getConcatenation(self, nums: List[int]) -> List[int]: 3 | return nums + nums 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1935.Maximum Number of Words You Can Type.ts: -------------------------------------------------------------------------------- 1 | function canBeTypedWords(text: string, brokenLetters: string): number { 2 | const broken = new Set(brokenLetters); 3 | return text.split(" ").filter(word => ![].some.call(word, broken.has.bind(broken))).length; 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /1501-2000/1936.Add Minimum Number of Rungs.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addRungs(self, rungs: List[int], dist: int) -> int: 3 | rungs.append(0) 4 | res = 0 5 | for i in range(len(rungs) - 1): 6 | res += (rungs[i] - 1 - rungs[i - 1]) // dist 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /1501-2000/1941.Check if All Characters Have Equal Number of Occurrences.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def areOccurrencesEqual(self, s: str) -> bool: 5 | return len(set(Counter(s).values())) <= 1 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1952.Three Divisors.1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isThree(self, n: int) -> bool: 3 | res = 1 4 | for i in range(1, n): 5 | if n % i == 0: 6 | res += 1 7 | if res > 3: 8 | break 9 | return res == 3 10 | 11 | -------------------------------------------------------------------------------- /1501-2000/1953.Maximum Number of Weeks for Which You Can Work.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfWeeks(self, milestones: List[int]) -> int: 3 | mx = max(milestones) 4 | sm = sum(milestones) 5 | return (sm - mx) * 2 + 1 if mx > sm - mx else sm 6 | 7 | -------------------------------------------------------------------------------- /1501-2000/1954.Minimum Garden Perimeter to Collect Enough Apples.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumPerimeter(self, neededApples: int) -> int: 3 | edge = 0 4 | apples = 0 5 | while apples < neededApples: 6 | edge += 1 7 | apples += edge * edge * 12 8 | return edge * 8 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1957.Delete Characters to Make Fancy String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def makeFancyString(self, s: str) -> str: 3 | res = [] 4 | for c in s: 5 | if len(res) >= 2 and res[-1] == res[-2] == c: 6 | continue 7 | res.append(c) 8 | return ''.join(res) 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/1961.Check If String Is a Prefix of Array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPrefixString(self, s: str, words: List[str]) -> bool: 3 | i = 0 4 | for word in words: 5 | for c in word: 6 | if i == len(s) or c != s[i]: 7 | return False 8 | i += 1 9 | if i == len(s): 10 | return True 11 | return False 12 | 13 | -------------------------------------------------------------------------------- /1501-2000/1967.Number of Strings That Appear as Substrings in Word.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numOfStrings(self, patterns: List[str], word: str) -> int: 3 | return sum(pattern in word for pattern in patterns) 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1969.Minimum Non-Zero Product of the Array Elements.py: -------------------------------------------------------------------------------- 1 | MOD = 10 ** 9 + 7 2 | 3 | class Solution: 4 | def minNonZeroProduct(self, p: int) -> int: 5 | all_1s = (1 << p) - 1 6 | return (pow(all_1s - 1, all_1s >> 1, MOD) * all_1s) % MOD 7 | 8 | -------------------------------------------------------------------------------- /1501-2000/1974.Minimum Time to Type Word Using Special Typewriter.c: -------------------------------------------------------------------------------- 1 | #define min(a,b) (a > b) ? (b) : (a); 2 | 3 | int minTimeToType(char * word){ 4 | char last = 'a'; 5 | int res = 0; 6 | char* p; 7 | for (p = word; *p != '\0'; p++) { 8 | int step = (*p - last + 26) % 26; 9 | res += min(step, 26 - step); 10 | last = *p; 11 | } 12 | return p - word + res; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /1501-2000/1979.Find Greatest Common Divisor of Array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findGCD(self, nums: List[int]) -> int: 3 | return math.gcd(min(nums), max(nums)) 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1985.Find the Kth Largest Integer in the Array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kthLargestNumber(self, nums: List[str], k: int) -> str: 3 | return sorted(nums, key=lambda num: (len(num), num))[-k] 4 | 5 | -------------------------------------------------------------------------------- /1501-2000/1991.Find the Middle Index in Array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var findMiddleIndex = function (nums) { 6 | let l = 0; 7 | let r = nums.reduce((acc, num) => acc + num, 0); 8 | for (let i in nums) { 9 | r -= nums[i]; 10 | if (l === r) return i; 11 | l += nums[i]; 12 | 13 | } 14 | return -1; 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /1501-2000/1996.The Number of Weak Characters in the Game.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfWeakCharacters(self, properties: List[List[int]]) -> int: 3 | max_defense = float("-inf") 4 | res = 0 5 | for _, defense in sorted(properties, key=lambda prop: (-prop[0], prop[1])): 6 | res += defense < max_defense 7 | max_defense = max(max_defense, defense) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /1501-2000/2000.Reverse Prefix of Word.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reversePrefix(self, word: str, ch: str) -> str: 3 | i = word.find(ch) 4 | return word if i == -1 else word[i::-1] + word[i + 1:] 5 | 6 | -------------------------------------------------------------------------------- /2001-2500/2006.Count Number of Pairs With Absolute Difference K.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def countKDifference(self, nums: List[int], k: int) -> int: 5 | cnt = Counter() 6 | res = 0 7 | for num in nums: 8 | res += cnt[num - k] + cnt[num + k] 9 | cnt[num] += 1 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2011.Final Value of Variable After Performing Operations.c: -------------------------------------------------------------------------------- 1 | int finalValueAfterOperations(char ** operations, int operationsSize){ 2 | int x = 0; 3 | for (int i = 0; i < operationsSize; i++) { 4 | x += operations[i][1] == '+' ? 1 : -1; 5 | } 6 | return x; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2016.Maximum Difference Between Increasing Elements.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumDifference(self, nums: List[int]) -> int: 3 | res = float("-inf") 4 | mn = float("inf") 5 | for num in nums: 6 | res = max(res, num - mn) 7 | mn = min(mn, num) 8 | return -1 if res <= 0 else res 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2022.Convert 1D Array Into 2D Array.ts: -------------------------------------------------------------------------------- 1 | function construct2DArray(original: number[], m: number, n: number): number[][] { 2 | if (m * n !== original.length) { 3 | return []; 4 | } 5 | const result = []; 6 | for (let i = 0; i < original.length; i += n) { 7 | result.push(original.slice(i, i + n)); 8 | } 9 | return result; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2027.Minimum Moves to Convert String.ts: -------------------------------------------------------------------------------- 1 | function minimumMoves(s: string): number { 2 | let res = 0, i = 0; 3 | while (i < s.length) { 4 | if (s[i] === 'X') { 5 | i += 3; 6 | res++; 7 | } else { 8 | i += 1; 9 | } 10 | } 11 | return res; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /2001-2500/2029.Stone Game IX.ts: -------------------------------------------------------------------------------- 1 | function stoneGameIX(stones: number[]): boolean { 2 | const cnt = [0, 0, 0]; 3 | 4 | for (const stone of stones) { 5 | cnt[stone % 3]++; 6 | } 7 | if (cnt[0] % 2) { 8 | return Math.abs(cnt[1] - cnt[2]) > 2; 9 | } 10 | return Math.min(cnt[1], cnt[2]) >= 1; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2032.Two Out of Three.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoOutOfThree(self, *nums_list) -> List[int]: 3 | s1, s2, s3 = sets = list(map(set, nums_list)) 4 | all_nums = s1 | s2 | s3 5 | res = [] 6 | for num in all_nums: 7 | if sum(num in s for s in sets) >= 2: 8 | res.append(num) 9 | return res 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2037.Minimum Number of Moves to Seat Everyone.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} seats 2 | # @param {Integer[]} students 3 | # @return {Integer} 4 | def min_moves_to_seat(seats, students) 5 | seats.sort.zip(students.sort).map{ |x, y| (x - y).abs }.sum 6 | end 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2038.Remove Colored Pieces if Both Neighbors are the Same Color.ts: -------------------------------------------------------------------------------- 1 | function winnerOfGame(colors: string): boolean { 2 | const res = {A: 0, B: 0}; 3 | for (let i = 0; i < colors.length; i++) { 4 | if (i >= 2 && colors[i] == colors[i - 1] && colors[i] == colors[i - 2]) { 5 | res[colors[i]]++; 6 | } 7 | } 8 | return res.A > res.B; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2042.Check if Numbers Are Ascending in a Sentence.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Boolean} 3 | def are_numbers_ascending(s) 4 | s.split.select { |token| '0' <= token[0] && token[0] <= '9' }.reduce([true, -1]) { |acc, num| [acc[0] && (acc[1] < num.to_i), num.to_i] }[0] 5 | end 6 | 7 | -------------------------------------------------------------------------------- /2001-2500/2047.Number of Valid Words in a Sentence.ts: -------------------------------------------------------------------------------- 1 | const reg = /^([a-z]+(-?[a-z]+)?)?[!,.]?$/; 2 | 3 | function countValidWords(sentence: string): number { 4 | return sentence.match(/\S+/g).filter(word => reg.test(word)).length; 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /2001-2500/2057.Smallest Index With Equal Value.ts: -------------------------------------------------------------------------------- 1 | function smallestEqual(nums: number[]): number { 2 | for (let i = 0; i < nums.length; i++) { 3 | if (nums[i] == i % 10) { 4 | return i; 5 | } 6 | } 7 | return -1; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2063.Vowels of All Substrings.ts: -------------------------------------------------------------------------------- 1 | function countVowels(word: string): number { 2 | let res = 0; 3 | for (let i = 0; i < word.length; i++) { 4 | if ('aeiou'.includes(word[i])) { 5 | res += (i + 1) * (word.length - i); 6 | } 7 | } 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2073.Time Needed to Buy Tickets.ts: -------------------------------------------------------------------------------- 1 | function timeRequiredToBuy(tickets: number[], k: number): number { 2 | let res = 0; 3 | tickets.forEach((ticket, i) => { 4 | res += Math.min(tickets[k] - (i <= k ? 0 : 1), ticket);; 5 | }); 6 | return res; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2078.Two Furthest Houses With Different Colors.ts: -------------------------------------------------------------------------------- 1 | function maxDistance(colors: number[]): number { 2 | const n = colors.length; 3 | for (let i = 0; i < n - 1; i++) { 4 | if (colors[i] !== colors[n - 1] || colors[n - 1 - i] !== colors[0]) { 5 | return n - 1 - i; 6 | } 7 | } 8 | return -1; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2079.Watering Plants.ts: -------------------------------------------------------------------------------- 1 | function wateringPlants(plants: number[], capacity: number): number { 2 | let water = capacity, steps = plants.length; 3 | for (let i = 0; i < plants.length; i++) { 4 | if (water < plants[i]) { 5 | steps += i * 2; 6 | water = capacity; 7 | } 8 | water -= plants[i]; 9 | } 10 | return steps; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2099.Find Subsequence of Length K With the Largest Sum.ts: -------------------------------------------------------------------------------- 1 | function maxSubsequence(nums: number[], k: number): number[] { 2 | return nums.map((num, i) => [num, i]).sort((a, b) => b[0] - a[0]).slice(0, k).sort((a, b) => a[1] - b[1]).map(([num, i]) => num); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2103.Rings and Rods.ts: -------------------------------------------------------------------------------- 1 | function countPoints(rings: string): number { 2 | const counter: {[key : string]:{[key : string]: boolean}} = {}; 3 | for (let i = 0; i < rings.length; i += 2) { 4 | counter[rings[i + 1]] ||= {}; 5 | counter[rings[i + 1]][rings[i]] = true; 6 | } 7 | return Object.values(counter).reduce((acc, value) => Object.keys(value).length === 3 ? acc + 1 : acc, 0); 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2109.Adding Spaces to a String.ts: -------------------------------------------------------------------------------- 1 | function addSpaces(s: string, spaces: number[]): string { 2 | spaces.push(s.length); 3 | let i = 0; 4 | const res = []; 5 | for (let j of spaces) { 6 | res.push(s.substring(i, j)); 7 | i = j; 8 | } 9 | return res.join(" "); 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2114.Maximum Number of Words Found in Sentences.ts: -------------------------------------------------------------------------------- 1 | function mostWordsFound(sentences: string[]): number { 2 | return Math.max(...sentences.map(sentence => Array.prototype.filter.call(sentence, l => l === ' ').length)) + 1; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2119.A Number After a Double Reversal.ts: -------------------------------------------------------------------------------- 1 | function isSameAfterReversals(num: number): boolean { 2 | return num === 0 || num % 10 !== 0; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2124.Check if All A's Appears Before All B's.ts: -------------------------------------------------------------------------------- 1 | function checkString(s: string): boolean { 2 | return /^a*b*$/.test(s); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2125.Number of Laser Beams in a Bank.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def numberOfBeams(self, bank: List[str]) -> int: 5 | res = prev = 0 6 | for row in bank: 7 | cnt = Counter(row) 8 | if cnt['1']: 9 | res += prev * cnt['1'] 10 | prev = cnt['1'] 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2125.Number of Laser Beams in a Bank.ts: -------------------------------------------------------------------------------- 1 | function numberOfBeams(bank: string[]): number { 2 | let res = 0, prev = 0; 3 | for (const row of bank) { 4 | const cnt = [].filter.call(row, c => c == '1') .length; 5 | if (cnt) { 6 | res += prev * cnt; 7 | prev = cnt; 8 | } 9 | } 10 | return res; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2126.Destroying Asteroids.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean asteroidsDestroyed(long mass, int[] asteroids) { 3 | Arrays.sort(asteroids); 4 | for (int asteroid : asteroids) { 5 | if (mass >= asteroid) { 6 | mass += asteroid; 7 | } else { 8 | return false; 9 | } 10 | } 11 | return true; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /2001-2500/2133.Check if Every Row and Column Contains All Numbers.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkValid(self, matrix: List[List[int]]) -> bool: 3 | def isValid(matrix): 4 | for row in matrix: 5 | if sorted(row) != list(range(1, len(row) + 1)): 6 | return False 7 | return True 8 | return isValid(matrix) and isValid(zip(*matrix)) 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2136.Earliest Possible Day of Full Bloom.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: 3 | res = cur = 0 4 | for grow, plant in sorted(zip(growTime, plantTime), reverse=True): 5 | cur += plant 6 | res = max(res, cur + grow) 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2139.Minimum Moves to Reach Target Score.ts: -------------------------------------------------------------------------------- 1 | function minMoves(target: number, maxDoubles: number): number { 2 | let res = 0; 3 | while (target && maxDoubles) { 4 | maxDoubles--; 5 | res += (target & 1) + 1; 6 | target >>= 1; 7 | } 8 | return res + (target === 0 ? -1 : target) - 1; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2145.Count the Hidden Sequences.ts: -------------------------------------------------------------------------------- 1 | function numberOfArrays(differences: number[], lower: number, upper: number): number { 2 | let val = 0, min = 0, max = 0; 3 | for (let diff of differences) { 4 | val += diff; 5 | min = Math.min(min, val); 6 | max = Math.max(max, val); 7 | } 8 | return Math.max(0, (upper - lower) - (max - min) + 1); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2150.Find All Lonely Numbers in the Array.ts: -------------------------------------------------------------------------------- 1 | function findLonely(nums: number[]): number[] { 2 | const counter = {}; 3 | for (const num of nums) { 4 | counter[num] ||= 0; 5 | counter[num]++; 6 | } 7 | return nums.filter(num => counter[num] === 1 && !counter[num - 1] && !counter[num + 1]); 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2154.Keep Multiplying Found Values by Two.ts: -------------------------------------------------------------------------------- 1 | function findFinalValue(nums: number[], original: number): number { 2 | const set = new Set(nums); 3 | while (set.has(original)) { 4 | original *= 2; 5 | } 6 | return original; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2160.Minimum Sum of Four Digit Number After Splitting Digits.ts: -------------------------------------------------------------------------------- 1 | function minimumSum(num: number): number { 2 | const digits = ('' + num).split('').sort().map(d => parseInt(d)); 3 | let res = 0, i = 0; 4 | while (i < digits.length) { 5 | res *= 10; 6 | res += digits[i++]; 7 | res += digits[i++]; 8 | } 9 | return res; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2164.Sort Even and Odd Indices Independently.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def sortEvenOdd(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: List[int] 6 | """ 7 | nums[::2], nums[1::2] = sorted(nums[::2]), sorted(nums[1::2], reverse=True) 8 | return nums 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2176.Count Equal and Divisible Pairs in an Array.ts: -------------------------------------------------------------------------------- 1 | function countPairs(nums: number[], k: number): number { 2 | let cnt = 0; 3 | for (let i = 0; i < nums.length; i++) { 4 | for (let j = i + 1; j < nums.length; j++) { 5 | if (nums[i] === nums[j] && i * j % k === 0) { 6 | cnt++; 7 | } 8 | } 9 | } 10 | return cnt; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2177.Find Three Consecutive Integers That Sum to a Given Number.ts: -------------------------------------------------------------------------------- 1 | function sumOfThree(num: number): number[] { 2 | if (num % 3 === 0) { 3 | num /= 3; 4 | return [num - 1, num, num + 1] 5 | } 6 | return []; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2180.Count Integers With Even Digit Sum.ts: -------------------------------------------------------------------------------- 1 | function countEven(num: number): number { 2 | let cnt = 0; 3 | for (let i = 1; i <= num; i++) { 4 | if (("" + i).split('').map(d => parseInt(d)).reduce((a, b) => a + b, 0) % 2 === 0) { 5 | cnt++; 6 | } 7 | } 8 | return cnt; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2185.Counting Words With a Given Prefix.ts: -------------------------------------------------------------------------------- 1 | function prefixCount(words: string[], pref: string): number { 2 | return words.filter(word => word.startsWith(pref)).length; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2186.Minimum Number of Steps to Make Two Strings Anagram II.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def minSteps(self, s: str, t: str) -> int: 5 | c1, c2 = Counter(s), Counter(t) 6 | diff1, diff2 = c1 - c2, c2 - c1 7 | return sum(diff1.values()) + sum(diff2.values()) 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2194.Cells in a Range on an Excel Sheet.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def cellsInRange(self, s: str) -> List[str]: 3 | col1, row1, _, col2, row2 = list(s) 4 | return [chr(col) + chr(row) for col in range(ord(col1), ord(col2) + 1) for row in range(ord(row1), ord(row2) + 1)] 5 | 6 | -------------------------------------------------------------------------------- /2001-2500/2202.Maximize the Topmost Element After K Moves.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumTop(self, nums: List[int], k: int) -> int: 3 | if k == 0: 4 | return nums[0] 5 | if len(nums) == 1: 6 | return -1 if k % 2 == 1 else nums[0] 7 | if len(nums) == 2: 8 | return nums[k % 2] if k <= 2 else max(nums) 9 | return max(nums[:k - 1] + nums[k: k + 1]) 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2206.Divide Array Into Equal Pairs.ts: -------------------------------------------------------------------------------- 1 | function divideArray(nums: number[]): boolean { 2 | nums.sort(); 3 | for (let i = 0; i < nums.length; i += 2) { 4 | if (nums[i] !== nums[i + 1]) return false; 5 | } 6 | return true; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2211.Count Collisions on a Road.ts: -------------------------------------------------------------------------------- 1 | function countCollisions(directions: string): number { 2 | const arr = []; 3 | for (const dir of directions) { 4 | if (!arr.length && dir === 'L') continue; 5 | arr.push(dir); 6 | } 7 | while (arr.length && arr[arr.length - 1] === 'R') { 8 | arr.pop(); 9 | } 10 | return arr.filter(item => item !== 'S').length; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2215.Find the Difference of Two Arrays.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: 3 | s1, s2 = set(nums1), set(nums2) 4 | return [list(s1 - s2), list(s2 - s1)] 5 | 6 | -------------------------------------------------------------------------------- /2001-2500/2216.Minimum Deletions to Make Array Beautiful.ts: -------------------------------------------------------------------------------- 1 | function minDeletion(nums: number[]): number { 2 | let res = 0, i = 0; 3 | while (i < nums.length) { 4 | while (i + 1 < nums.length && nums[i] === nums[i + 1]) { 5 | i++; 6 | res++; 7 | } 8 | i += 2; 9 | } 10 | if (i !== nums.length) { 11 | res++; 12 | } 13 | return res; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /2001-2500/2220.Minimum Bit Flips to Convert Number.ts: -------------------------------------------------------------------------------- 1 | function minBitFlips(start: number, goal: number): number { 2 | let xor = start ^ goal; 3 | let res = 0; 4 | while (xor) { 5 | res++; 6 | xor &= (xor - 1); 7 | } 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2225.Find Players With Zero or One Losses.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findWinners(self, matches: List[List[int]]) -> List[List[int]]: 3 | players = set(m[0] for m in matches) | set(m[1] for m in matches) 4 | loser_cnt = Counter([m[1] for m in matches]) 5 | return sorted(players - set(loser_cnt.keys())), sorted(k for k, v in loser_cnt.items() if v == 1) 6 | 7 | -------------------------------------------------------------------------------- /2001-2500/2235.Add Two Integers.ts: -------------------------------------------------------------------------------- 1 | function sum(num1: number, num2: number): number { 2 | return num1 + num2; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2239.Find Closest Number to Zero.ts: -------------------------------------------------------------------------------- 1 | function findClosestNumber(nums: number[]): number { 2 | return nums.reduce(([diff, res], num) => { 3 | const abs = Math.abs(num); 4 | return abs < diff || (abs === diff && res < num) ? [abs, num] : [diff, res] 5 | }, [Infinity, undefined])[1]; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2240.Number of Ways to Buy Pens and Pencils.ts: -------------------------------------------------------------------------------- 1 | function waysToBuyPensPencils(total: number, cost1: number, cost2: number): number { 2 | const c1 = Math.max(cost1, cost2); 3 | const c2 = Math.min(cost1, cost2); 4 | let res = 0; 5 | for (let remain = total; remain >= 0; remain -= c1) { 6 | res += Math.floor(remain / c2) + 1; 7 | } 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2243.Calculate Digit Sum of a String.ts: -------------------------------------------------------------------------------- 1 | function digitSum(s: string, k: number): string { 2 | while (s.length > k) { 3 | const res = []; 4 | for (let i = 0; i < s.length; i += k) { 5 | res.push([...s.substr(i, k)].map(d => parseInt(d)).reduce((acc, num) => acc + num, 0)); 6 | } 7 | s = res.join(""); 8 | } 9 | return s; 10 | }; 11 | 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2248.Intersection of Multiple Arrays.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersection(self, nums: List[List[int]]) -> List[int]: 3 | res = set(nums[0]) 4 | for s in map(set, nums[1:]): 5 | res &= s 6 | return sorted(res) 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2255.Count Prefixes of a Given String.ts: -------------------------------------------------------------------------------- 1 | function countPrefixes(words: string[], s: string): number { 2 | return words.filter(word => s.startsWith(word)).length; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2260.Minimum Consecutive Cards to Pick Up.ts: -------------------------------------------------------------------------------- 1 | function minimumCardPickup(cards: number[]): number { 2 | const seen = {}; 3 | let res = Infinity; 4 | cards.forEach((num, i) => { 5 | if (seen[num] !== undefined) { 6 | res = Math.min(res, i - seen[num]) 7 | } 8 | seen[num] = i; 9 | }); 10 | return Infinity === res ? -1 : res + 1; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2264.Largest 3-Same-Digit Number in String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestGoodInteger(self, num: str) -> str: 3 | for c in "9876543210": 4 | if c * 3 in num: 5 | return c * 3 6 | return "" 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2270.Number of Ways to Split Array.ts: -------------------------------------------------------------------------------- 1 | function waysToSplitArray(nums: number[]): number { 2 | const sum = nums.reduce((acc, num) => acc + num, 0); 3 | let res = 0, prefix = 0; 4 | for (let i = 0; i < nums.length - 1; i++) { 5 | prefix += nums[i]; 6 | if (prefix >= sum - prefix) { 7 | res++; 8 | } 9 | } 10 | return res; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2273.Find Resultant Array After Removing Anagrams.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeAnagrams(self, words: List[str]) -> List[str]: 3 | res = [] 4 | for word in words: 5 | if res and sorted(res[-1]) == sorted(word): 6 | continue 7 | res.append(word) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2274.Maximum Consecutive Floors Without Special Floors.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int: 3 | special.extend([top + 1, bottom - 1]) 4 | special.sort() 5 | res = 0 6 | for a, b in zip(special[: - 1], special[1:]): 7 | res = max(res, b - a - 1) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2275.Largest Combination With Bitwise AND Greater Than Zero.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestCombination(self, candidates: List[int]) -> int: 3 | 4 | MAX = 10 ** 7 5 | mask = 1 6 | res = 0 7 | while mask <= MAX: 8 | res = max(res, sum(1 for _ in filter(lambda cand: cand & mask, candidates))) 9 | mask <<= 1 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2278.Percentage of Letter in String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def percentageLetter(self, s: str, letter: str) -> int: 3 | return len([c for c in s if c == letter]) * 100 // len(s) 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2283.Check if Number Has Equal Digit Count and Digit Value.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def digitCount(self, num: str) -> bool: 5 | cnt = Counter(num) 6 | return all(cnt[str(i)] == int(num[i]) for i in range(len(num))) 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2287.Rearrange Characters to Make Target String.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def rearrangeCharacters(self, s: str, target: str) -> int: 4 | tc = Counter(target) 5 | sc = Counter(s) 6 | return min(sc[c] // tc[c] for c in tc.keys()) 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2288.Apply Discount to Prices.ts: -------------------------------------------------------------------------------- 1 | function discountPrices(sentence: string, discount: number): string { 2 | const arr = sentence.split(' '); 3 | for (let i = 0; i < arr.length; i++) { 4 | if (/^\$\d+$/.test(arr[i])) { 5 | arr[i] = `$${(parseInt(arr[i].substr(1)) * (100 - discount) / 100).toFixed(2)}` 6 | } 7 | } 8 | return arr.join(' '); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2293.Min Max Game.ts: -------------------------------------------------------------------------------- 1 | function minMaxGame(nums: number[]): number { 2 | let len = nums.length / 2; 3 | while (len >= 1) { 4 | for (let i = 0; i < len; i++) { 5 | const func = i % 2 ? Math.max : Math.min; 6 | nums[i] = func(nums[i * 2], nums[i * 2 + 1]); 7 | } 8 | len /= 2; 9 | } 10 | return nums[0]; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2294.Partition Array Such That Maximum Difference Is K.ts: -------------------------------------------------------------------------------- 1 | function partitionArray(nums: number[], k: number): number { 2 | let start = -Infinity, res = 0; 3 | for (let num of nums.sort((a, b) => a - b)) { 4 | if (num > start + k) { 5 | start = num; 6 | res++; 7 | } 8 | } 9 | return res; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2300.Successful Pairs of Spells and Potions.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | 3 | class Solution: 4 | def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: 5 | potions.sort() 6 | return [len(potions) - bisect.bisect_left(potions, success / spell) for spell in spells] 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2309.Greatest English Letter in Upper and Lower Case.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def greatestLetter(self, s: str) -> str: 3 | s = set(s) 4 | for A, a in reversed(list(zip(string.ascii_uppercase, string.ascii_lowercase))): 5 | if a in s and A in s: 6 | return A 7 | return "" 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2315.Count Asterisks.ts: -------------------------------------------------------------------------------- 1 | function countAsterisks(s: string): number { 2 | let res = 0, count = true; 3 | for (const c of s) { 4 | if (c === '|') { 5 | count = !count; 6 | } else if (c === '*' && count) { 7 | res++; 8 | } 9 | } 10 | return res; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2317.Maximum XOR After Operations.ts: -------------------------------------------------------------------------------- 1 | function maximumXOR(nums: number[]): number { 2 | return nums.reduce((acc, num) => acc | num, 0); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2319.Check if Matrix Is X-Matrix.ts: -------------------------------------------------------------------------------- 1 | function checkXMatrix(grid: number[][]): boolean { 2 | for (let i = 0; i < grid.length; i++) { 3 | for (let j = 0; j < grid.length; j++) { 4 | if ((i === j || grid.length - 1 - i === j) === !grid[i][j]) { 5 | return false; 6 | } 7 | } 8 | } 9 | return true; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2320.Count Number of Ways to Place Houses.c: -------------------------------------------------------------------------------- 1 | unsigned long long MOD = 1000000007; 2 | int countHousePlacements(int n){ 3 | unsigned long long taken = 0, not_taken = 1; 4 | for (int i = 0; i <= n; i++) { 5 | unsigned long long tmp = (taken + not_taken) % MOD; 6 | taken = not_taken; 7 | not_taken = tmp; 8 | } 9 | return (not_taken * not_taken) % MOD; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2325.Decode the Message.ts: -------------------------------------------------------------------------------- 1 | function decodeMessage(key: string, message: string): string { 2 | const map = {' ': ' '}; 3 | let i = 97; 4 | for (let c of key) { 5 | if (!map[c]) { 6 | map[c] = String.fromCharCode(i++); 7 | } 8 | } 9 | return [...message].map(c => map[c] || c).join(''); 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2341.Maximum Number of Pairs in Array.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def numberOfPairs(self, nums: List[int]) -> List[int]: 5 | cnt = Counter(nums).values() 6 | return [sum(item // 2 for item in cnt), len([item for item in cnt if item % 2])] 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2344.Minimum Deletions to Make Array Divisible.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | class Solution: 4 | def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: 5 | gcd = math.gcd(*numsDivide) 6 | for i, num in enumerate(sorted(nums)): 7 | if gcd % num == 0: 8 | return i 9 | return -1 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2348.Number of Zero-Filled Subarrays.ts: -------------------------------------------------------------------------------- 1 | function zeroFilledSubarray(nums: number[]): number { 2 | nums.push(-1); 3 | let acc = 0, res = 0; 4 | for (const num of nums) { 5 | if (num) { 6 | res += (1 + acc) * acc / 2; 7 | acc = 0; 8 | } else { 9 | acc++; 10 | } 11 | } 12 | return res; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /2001-2500/2351.First Letter to Appear Twice.ts: -------------------------------------------------------------------------------- 1 | function repeatedCharacter(s: string): string { 2 | const seen = {}; 3 | for (let c of [...s]) { 4 | if (seen[c]) return c; 5 | seen[c] = true; 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /2001-2500/2352.Equal Row and Column Pairs.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def equalPairs(self, grid: List[List[int]]) -> int: 5 | rows = Counter(map(tuple, grid)) 6 | columns = Counter(map(tuple, zip(*grid))) 7 | return sum(rows[key] * columns[key] for key in set(rows.keys())) 8 | 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2357.Make Array Zero by Subtracting Equal Amounts.ts: -------------------------------------------------------------------------------- 1 | function minimumOperations(nums: number[]): number { 2 | return (new Set(nums.filter(_ => _))).size; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2364.Count Number of Bad Pairs.ts: -------------------------------------------------------------------------------- 1 | function countBadPairs(nums: number[]): number { 2 | const diff: {[key : number]: number} = {}; 3 | let good = 0; 4 | nums.forEach((num, i) => { 5 | good += diff[num - i] ||= 0; 6 | diff[num - i]++; 7 | }); 8 | const N = nums.length; 9 | return N * (N - 1) / 2 - good; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2365.Task Scheduler II.ts: -------------------------------------------------------------------------------- 1 | function taskSchedulerII(tasks: number[], space: number): number { 2 | const workedAt: {[key : number]: number} = {}; 3 | let day = 0; 4 | tasks.forEach(task => { 5 | const taskWorkedAt = workedAt[task] || -Infinity; 6 | day = Math.max(day, taskWorkedAt + space) + 1; 7 | workedAt[task] = day; 8 | }); 9 | return day; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2366.Minimum Replacements to Sort the Array.ts: -------------------------------------------------------------------------------- 1 | function minimumReplacement(nums: number[]): number { 2 | let res = 0; 3 | nums.push(nums[nums.length - 1]); 4 | for (let i = nums.length - 2; i >= 0; i--) { 5 | const parts = Math.ceil(nums[i] / nums[i + 1]); 6 | res += parts - 1; 7 | nums[i] = Math.floor(nums[i] / parts); 8 | } 9 | return res; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2367.Number of Arithmetic Triplets.2.ts: -------------------------------------------------------------------------------- 1 | function arithmeticTriplets(nums: number[], diff: number): number { 2 | const seen = {}; 3 | let res = 0; 4 | nums.forEach(num => { 5 | res += seen[num - diff] && seen[num - diff * 2] || 0; 6 | seen[num] = 1; 7 | }); 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2373.Largest Local Values in a Matrix.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: 3 | M, N = len(grid), len(grid[0]) 4 | res = [[None] * (N - 2) for _ in range(M - 2)] 5 | for i in range(M - 2): 6 | for j in range(N - 2): 7 | res[i][j] = max(max(grid[k][j: j + 3]) for k in range(i, i + 3)) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2374.Node With Highest Edge Score.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def edgeScore(self, edges: List[int]) -> int: 5 | res = Counter() 6 | for src, dst in enumerate(edges): 7 | res[dst] += src 8 | return -max([score, -node] for node, score in res.items())[1] 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2380.Time Needed to Rearrange a Binary String.ts: -------------------------------------------------------------------------------- 1 | function secondsToRemoveOccurrences(s: string): number { 2 | let res = 0, cnt0 = 0; 3 | for (const c of s) { 4 | if (c === '0') { 5 | cnt0++; 6 | } else if (cnt0) { 7 | res = Math.max(res + 1, cnt0); 8 | } 9 | } 10 | return res; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /2001-2500/2389.Longest Subsequence With Limited Sum.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | 3 | class Solution: 4 | def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: 5 | nums.sort() 6 | for i in range(1, len(nums)): 7 | nums[i] += nums[i - 1] 8 | return [bisect.bisect_right(nums, query) for query in queries] 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2404.Most Frequent Even Element.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Solution: 4 | def mostFrequentEven(self, nums: List[int]) -> int: 5 | common = heapq.nlargest(1, ((cnt, -num) for num, cnt in Counter(num for num in nums if not num % 2).items())) 6 | return -common[0][1] if common else -1 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2405.Optimal Partition of String.c: -------------------------------------------------------------------------------- 1 | int partitionString(char * s){ 2 | bool seen[26] = {false}; 3 | int res = 1; 4 | while (*s) { 5 | if (seen[*s - 97]) { 6 | res++; 7 | memset(seen, false, sizeof(bool) * 26); 8 | } 9 | seen[*s++ - 97] = true; 10 | } 11 | return res; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /2001-2500/2413.Smallest Even Multiple.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int smallestEvenMultiple(int n) { 4 | return n << (n & 1); 5 | } 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2414.Length of the Longest Alphabetical Continuous Substring.c: -------------------------------------------------------------------------------- 1 | int longestContinuousSubstring(char * s){ 2 | int res = 1, cur = 1; 3 | char c = *s; 4 | while (c = *s++) { 5 | cur = *s == c + 1 ? cur : 0; 6 | res = res > ++cur ? res : cur; 7 | } 8 | return res; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2418.Sort the People.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: 3 | return [pair[1] for pair in sorted(zip(heights, names), reverse=True)] 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2433.Find The Original Array of Prefix Xor.ts: -------------------------------------------------------------------------------- 1 | function findArray(pref: number[]): number[] { 2 | const res = []; 3 | let acc = 0; 4 | for (const target of pref) { 5 | const cur = target ^ acc; 6 | res.push(cur); 7 | acc ^= cur; 8 | } 9 | return res; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2439.Minimize Maximum of Array.ts: -------------------------------------------------------------------------------- 1 | function minimizeArrayValue(nums: number[]): number { 2 | let res = 0, sum = 0; 3 | nums.forEach((num, i) => { 4 | sum += num; 5 | res = Math.max(res, Math.ceil(sum / (i + 1))); 6 | }); 7 | return res; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2441.Largest Positive Integer That Exists With Its Negative.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMaxK(self, nums: List[int]) -> int: 3 | s = set(nums) | {0} 4 | return -1 if (res := max(num for num in s if num >= 0 and -num in s)) == 0 else res 5 | 6 | -------------------------------------------------------------------------------- /2001-2500/2442.Count Number of Distinct Integers After Reverse Operations.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countDistinctIntegers(self, nums: List[int]) -> int: 3 | return len(set(nums) | set(int(''.join(reversed(str(num)))) for num in nums)) 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2443.Sum of Number and Its Reverse.ts: -------------------------------------------------------------------------------- 1 | const everything = new Set(); 2 | for (let i = 0; i < 100000; i++) { 3 | const j = parseInt([...(i + '')].reverse().join('')); 4 | everything.add(i + j); 5 | } 6 | 7 | function sumOfNumberAndReverse(num: number): boolean { 8 | return everything.has(num); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2001-2500/2446.Determine if Two Events Have Conflict.ts: -------------------------------------------------------------------------------- 1 | function haveConflict(event1: string[], event2: string[]): boolean { 2 | function toMinutes(time: string) { 3 | return parseInt(time.substring(0, 2)) * 60 + parseInt(time.substring(3, 5)); 4 | } 5 | return Math.min(toMinutes(event1[1]), toMinutes(event2[1])) >= Math.max(toMinutes(event1[0]), toMinutes(event2[0])) 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2455.Average Value of Even Numbers That Are Divisible by Three.py: -------------------------------------------------------------------------------- 1 | from statistics import mean 2 | 3 | class Solution: 4 | def averageValue(self, nums: List[int]) -> int: 5 | arr = [num for num in nums if num % 6 == 0] 6 | return int(mean(arr)) if arr else 0 7 | 8 | -------------------------------------------------------------------------------- /2001-2500/2465.Number of Distinct Averages.ts: -------------------------------------------------------------------------------- 1 | function distinctAverages(nums: number[]): number { 2 | const set = new Set(); 3 | nums.sort((a, b) => a - b); 4 | for (let i = 0; i < nums.length / 2; i++) { 5 | set.add(nums[i] + nums[nums.length - 1 - i]); 6 | } 7 | return set.size; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2001-2500/2469.Convert the Temperature.ts: -------------------------------------------------------------------------------- 1 | function convertTemperature(celsius: number): number[] { 2 | return [celsius + 273.15, celsius * 1.80 + 32.00]; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2481.Minimum Cuts to Divide a Circle.ts: -------------------------------------------------------------------------------- 1 | function numberOfCuts(n: number): number { 2 | if (n === 1) return 0; 3 | if (n % 2) return n; 4 | return n / 2; 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /2001-2500/2485.Find the Pivot Integer.ts: -------------------------------------------------------------------------------- 1 | function pivotInteger(n: number): number { 2 | let sum = 0; 3 | const total = (1 + n) * n / 2; 4 | for (let i = 1; i <= n; i++) { 5 | sum += i; 6 | if (sum === total - sum + i) return i; 7 | if (sum > total - sum + i) return -1; 8 | } 9 | return -1; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2001-2500/2490.Circular Sentence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isCircularSentence(self, sentence: str) -> bool: 3 | words = sentence.split() 4 | return all(words[i - 1][-1] == words[i][0] for i in range(len(words))) 5 | 6 | -------------------------------------------------------------------------------- /2001-2500/2496.Maximum Value of a String in an Array.ts: -------------------------------------------------------------------------------- 1 | function maximumValue(strs: string[]): number { 2 | return strs.reduce((acc, str) => Math.max(acc, [...str].filter(c => '0' > c || c > '9').length ? str.length : parseInt(str)), -Infinity); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2001-2500/2498.Frog Jump II.ts: -------------------------------------------------------------------------------- 1 | function maxJump(stones: number[]): number { 2 | let res = 0; 3 | for (let i = 1; i < stones.length; i++) { 4 | res = Math.max(res, stones[i] - stones[Math.max(0, i - 2)]); 5 | } 6 | return res; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2520.Count the Digits That Divide a Number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countDigits(self, num: int) -> int: 3 | return sum(num % int(c) == 0 for c in str(num)) 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2529.Maximum Count of Positive Integer and Negative Integer.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | 3 | class Solution: 4 | def maximumCount(self, nums: List[int]) -> int: 5 | return max(bisect.bisect_left(nums, 0), len(nums) - bisect.bisect_right(nums, 0)) 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2544.Alternating Digit Sum.php: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | /** 4 | * @param Integer $n 5 | * @return Integer 6 | */ 7 | function alternateDigitSum($n) { 8 | $s = strval($n); 9 | $res = 0; 10 | for ($i = 0; $i < strlen($s); $i++) { 11 | $res += ($i % 2 == 0 ? 1 : -1) * intval($s[$i]); 12 | } 13 | return $res; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /2501-3000/2549.Count Distinct Numbers on Board.php: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | /** 4 | * @param Integer $n 5 | * @return Integer 6 | */ 7 | function distinctIntegers($n) { 8 | return max(1, $n - 1); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2501-3000/2550.Count Collisions of Monkeys on a Polygon.py: -------------------------------------------------------------------------------- 1 | MOD = 10 ** 9 + 7 2 | 3 | class Solution: 4 | def monkeyMove(self, n: int) -> int: 5 | return (pow(2, n, MOD) - 2) % MOD 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2553.Separate the Digits in an Array.ts: -------------------------------------------------------------------------------- 1 | function separateDigits(nums: number[]): number[] { 2 | const res: number[] = []; 3 | nums.forEach(num => [...("" + num)].forEach(c => res.push(parseInt(c)))); 4 | return res; 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2558.Take Gifts From the Richest Pile.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Solution: 4 | def pickGifts(self, gifts: List[int], k: int) -> int: 5 | gifts = [-g for g in gifts] 6 | heapq.heapify(gifts) 7 | for _ in range(k): 8 | g = heapq.heappop(gifts) 9 | g = -int(math.sqrt(-g)) 10 | heapq.heappush(gifts, g) 11 | return sum(-g for g in gifts) 12 | 13 | -------------------------------------------------------------------------------- /2501-3000/2559.Count Vowel Strings in Ranges.ts: -------------------------------------------------------------------------------- 1 | function vowelStrings(words: string[], queries: number[][]): number[] { 2 | const prefix = [0] 3 | words.forEach((word, i) => { 4 | prefix.push(('aeiou'.includes(word[0]) && 'aeiou'.includes(word[word.length - 1]) ? 1 : 0) + prefix[i]); 5 | }); 6 | return queries.map(q => prefix[q[1] + 1] - prefix[q[0]]); 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2562.Find the Array Concatenation Value.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findTheArrayConcVal(self, nums: List[int]) -> int: 3 | i, j = 0, len(nums) - 1 4 | res = 0 5 | while i < j: 6 | res += int(str(nums[i]) + str(nums[j])) 7 | i += 1 8 | j -= 1 9 | if i == j: 10 | res += nums[i] 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /2501-3000/2574.Left and Right Sum Differences.ts: -------------------------------------------------------------------------------- 1 | function leftRigthDifference(nums: number[]): number[] { 2 | const prefix = [0]; 3 | for (const num of nums) { 4 | prefix.push(prefix[prefix.length - 1] + num); 5 | } 6 | const sum = prefix[prefix.length - 1]; 7 | return nums.map((_, i) => Math.abs(prefix[i] - (sum - prefix[i + 1]))); 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2501-3000/2582.Pass the Pillow.ts: -------------------------------------------------------------------------------- 1 | function passThePillow(n: number, time: number): number { 2 | time %= (n - 1) * 2; 3 | return Math.min(time, (n - 1) * 2 - time) + 1; 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /2501-3000/2586.Count the Number of Vowel Strings in Range.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def vowelStrings(self, words: List[str], left: int, right: int) -> int: 3 | aeiou = "aeiou" 4 | return len([word for word in words[left : right + 1] if word[0] in aeiou and word[-1] in aeiou]) 5 | 6 | -------------------------------------------------------------------------------- /2501-3000/2588.Count the Number of Beautiful Subarrays.ts: -------------------------------------------------------------------------------- 1 | function beautifulSubarrays(nums: number[]): number { 2 | let xor = 0; 3 | let res = 0; 4 | const cnt = {0: 1}; 5 | for (const num of nums) { 6 | xor ^= num; 7 | cnt[xor] ||= 0; 8 | res += cnt[xor]; 9 | cnt[xor] += 1; 10 | } 11 | return res; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /2501-3000/2591.Distribute Money to Maximum Children.c: -------------------------------------------------------------------------------- 1 | int distMoney(int money, int children){ 2 | if (money < children) { 3 | return -1; 4 | } else if (children * 8 < money) { 5 | return children - 1; 6 | } else if (children * 8 - 4 == money) { 7 | return children - 2; 8 | } else { 9 | return (money - children) / 7; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /2501-3000/2595.Number of Even and Odd Bits.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] evenOddBit(int n) { 3 | int[] res = new int[2]; 4 | while (n != 0) { 5 | res[0] += n & 1; 6 | n >>= 1; 7 | res[1] += n & 1; 8 | n >>= 1; 9 | } 10 | return res; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /2501-3000/2600.K Items With the Maximum Sum.c: -------------------------------------------------------------------------------- 1 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 2 | 3 | int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k){ 4 | int res = 0; 5 | res += MIN(numOnes, k); 6 | k -= MIN(numOnes, k); 7 | k -= MIN(numZeros, k); 8 | res -= MIN(numNegOnes, k); 9 | return res; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2501-3000/2619.Array Prototype Last.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | interface Array { 3 | last(): T | -1; 4 | } 5 | } 6 | 7 | Array.prototype.last = function() { 8 | return this.length ? this[this.length - 1] : -1; 9 | }; 10 | 11 | /** 12 | * const arr = [1, 2, 3]; 13 | * arr.last(); // 3 14 | */ 15 | 16 | -------------------------------------------------------------------------------- /2501-3000/2620.Counter.ts: -------------------------------------------------------------------------------- 1 | function createCounter(n: number): () => number { 2 | return function() { 3 | return n++; 4 | } 5 | } 6 | 7 | 8 | /** 9 | * const counter = createCounter(10) 10 | * counter() // 10 11 | * counter() // 11 12 | * counter() // 12 13 | */ 14 | 15 | -------------------------------------------------------------------------------- /2501-3000/2621.Sleep.ts: -------------------------------------------------------------------------------- 1 | async function sleep(millis: number): Promise { 2 | return new Promise(resolve => setTimeout(resolve, millis)); 3 | } 4 | 5 | 6 | /** 7 | * let t = Date.now() 8 | * sleep(100).then(() => console.log(Date.now() - t)) // 100 9 | */ 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2626.Array Reduce Transformation.ts: -------------------------------------------------------------------------------- 1 | type Fn = (accum: number, curr: number) => number 2 | 3 | function reduce(nums: number[], fn: Fn, init: number): number { 4 | let res = init; 5 | nums.forEach(num => { 6 | res = fn(res, num); 7 | }); 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2629.Function Composition.ts: -------------------------------------------------------------------------------- 1 | type F = (x: number) => number; 2 | 3 | function compose(functions: F[]): F { 4 | return function(x) { 5 | return functions.reverse().reduce((acc, f) => f(acc), x); 6 | } 7 | }; 8 | 9 | /** 10 | * const fn = compose([x => x + 1, x => 2 * x]) 11 | * fn(4) // 9 12 | */ 13 | 14 | -------------------------------------------------------------------------------- /2501-3000/2634.Filter Elements from Array.ts: -------------------------------------------------------------------------------- 1 | function filter(arr: number[], fn: (n: number, i: number) => any): number[] { 2 | const res: any[] = []; 3 | arr.forEach((num, i) => { 4 | if (fn(num, i)) { 5 | res.push(num); 6 | } 7 | }); 8 | return res; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2635.Apply Transform Over Each Element in Array.ts: -------------------------------------------------------------------------------- 1 | function map(arr: number[], fn: (n: number, i: number) => number): number[] { 2 | const res: number[] = new Array(arr.length); 3 | for (let i = 0; i < arr.length; i++) { 4 | res[i] = fn(arr[i], i); 5 | } 6 | return res; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2639.Find the Width of Columns of a Grid.ts: -------------------------------------------------------------------------------- 1 | function findColumnWidth(grid: number[][]): number[] { 2 | const res: number[] = []; 3 | grid.forEach(row => { 4 | row.forEach((ele, i) => { 5 | if (res.length === i) res.push(0); 6 | res[i] = Math.max(res[i], `${ele}`.length); 7 | }); 8 | }); 9 | return res; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /2501-3000/2643.Row With Maximum Ones.ts: -------------------------------------------------------------------------------- 1 | function rowAndMaximumOnes(mat: number[][]): number[] { 2 | const arr = mat.map(row => row.reduce((acc, num) => acc + num, 0)); 3 | const mx = Math.max(...arr); 4 | return [arr.indexOf(mx), mx]; 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2645.Minimum Additions to Make Valid String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addMinimum(self, word: str) -> int: 3 | res = 0 4 | wanted = 0 5 | for c in word + "a": 6 | diff = ((ord(c) - ord('a') + 3) - wanted) % 3 7 | res += diff 8 | wanted += diff + 1 9 | wanted %= 3 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /2501-3000/2648.Generate Fibonacci Sequence.ts: -------------------------------------------------------------------------------- 1 | function* fibGenerator(): Generator { 2 | let a = -1, b = 1; 3 | while (true) { 4 | [a, b] = [b, a + b]; 5 | yield b; 6 | } 7 | }; 8 | 9 | /** 10 | * const gen = fibGenerator(); 11 | * gen.next().value; // 0 12 | * gen.next().value; // 1 13 | */ 14 | 15 | -------------------------------------------------------------------------------- /2501-3000/2651.Calculate Delayed Arrival Time.c: -------------------------------------------------------------------------------- 1 | int findDelayedArrivalTime(int arrivalTime, int delayedTime){ 2 | return (arrivalTime + delayedTime) % 24; 3 | } 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2652.Sum Multiples.ts: -------------------------------------------------------------------------------- 1 | const prefix = new Array(1001); 2 | prefix[0] = 0; 3 | for (let i = 1; i < prefix.length; i++) { 4 | prefix[i] = prefix[i - 1]; 5 | if (!(i % 3 && i % 5 && i % 7)) { 6 | prefix[i] += i; 7 | } 8 | } 9 | function sumOfMultiples(n: number): number { 10 | return prefix[n]; 11 | }; 12 | 13 | 14 | -------------------------------------------------------------------------------- /2501-3000/2656.Maximum Sum With Exactly K Elements.ts: -------------------------------------------------------------------------------- 1 | function maximizeSum(nums: number[], k: number): number { 2 | return Math.max(...nums) * k + k * (k - 1) / 2; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2677.Chunk Array.ts: -------------------------------------------------------------------------------- 1 | function chunk(arr: any[], size: number): any[][] { 2 | const res = []; 3 | for (let i = 0; i < arr.length; i += size) { 4 | res.push(arr.slice(i, i + size)); 5 | } 6 | return res; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2678.Number of Senior Citizens.c: -------------------------------------------------------------------------------- 1 | int countSeniors(char ** details, int detailsSize){ 2 | int res = 0; 3 | for (int i = 0; i < detailsSize; i++) { 4 | details[i][13] = '\0'; 5 | if ((details[i][11] - '0') * 10 + details[i][12] - '0' > 60) res++; 6 | } 7 | return res; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /2501-3000/2679.Sum in a Matrix.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def matrixSum(self, nums: List[List[int]]) -> int: 3 | return sum(map(max, zip(*map(sorted, nums)))) 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2683.Neighboring Bitwise XOR.ts: -------------------------------------------------------------------------------- 1 | function doesValidArrayExist(derived: number[]): boolean { 2 | return derived.reduce((xor, num) => num ^ xor, 0) === 0; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2716.Minimize String Length.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Integer} 3 | def minimized_string_length(s) 4 | s.split('').uniq.size 5 | end 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2717.Semi-Ordered Permutation.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def semi_ordered_permutation(nums) 4 | n = nums.size 5 | sum = nums.index(1) + n - 1 - nums.index(n) 6 | sum < n - 1 ? sum : sum - 1 7 | end 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2729.Check if The Number is Fascinating.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isFascinating(self, n: int) -> bool: 3 | num = "".join(str(n * i) for i in range(1, 4)) 4 | return len(num) == len(set(num)) == 9 and '0' not in num 5 | 6 | -------------------------------------------------------------------------------- /2501-3000/2733.Neither Minimum nor Maximum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findNonMinOrMax(self, nums: List[int]) -> int: 3 | seen = set() 4 | for num in nums: 5 | seen.add(num) 6 | if len(seen) == 3: 7 | mn, mx = min(seen), max(seen) 8 | seen.remove(mn) 9 | seen.remove(mx) 10 | return seen.pop() 11 | return -1 12 | 13 | -------------------------------------------------------------------------------- /2501-3000/2740.Find the Value of the Partition.ts: -------------------------------------------------------------------------------- 1 | function findValueOfPartition(nums: number[]): number { 2 | nums.sort((a, b) => a - b); 3 | let diff = Infinity; 4 | for (let i = 1; i < nums.length; i++) { 5 | diff = Math.min(diff, nums[i] - nums[i - 1]); 6 | } 7 | return diff; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /2501-3000/2748.Number of Beautiful Pairs.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countBeautifulPairs(self, nums: List[int]) -> int: 3 | res = 0 4 | for i in range(len(nums)): 5 | for j in range(i +1, len(nums)): 6 | if math.gcd(int(str(nums[i])[0]), int(str(nums[j])[-1])) == 1: 7 | res += 1 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /2501-3000/2778.Sum of Squares of Special Elements.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfSquares(self, nums: List[int]) -> int: 3 | return sum(num * num for i, num in enumerate(nums) if len(nums) % (i + 1) == 0) 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2788.Split Strings by Separator.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | class Solution: 4 | def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]: 5 | list_of_lists = map(lambda word: filter(len, word.split(separator)), words) 6 | return list(itertools.chain.from_iterable(list_of_lists)) 7 | 8 | -------------------------------------------------------------------------------- /2501-3000/2789.Largest Element in an Array after Merge Operations.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxArrayValue(self, nums: List[int]) -> int: 3 | res = nums[0] 4 | while nums: 5 | while len(nums) > 1 and nums[-2] <= nums[-1]: 6 | tail = nums.pop() 7 | nums[-1] += tail 8 | res = max(res, nums.pop()) 9 | return res 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2791.Count Paths That Can Form a Palindrome in a Tree.md: -------------------------------------------------------------------------------- 1 | ## High level idea 2 | 3 | Use Manacher algorithm to find palindromes. But th DP array of the Manacher algorithm is not an array any more. It is a stack that corresponds to the tree's DFS recursion stack. So the DP array/stack can grow and shrink along with the DFS. 4 | -------------------------------------------------------------------------------- /2501-3000/2798.Number of Employees Who Met the Target.ts: -------------------------------------------------------------------------------- 1 | function numberOfEmployeesWhoMetTarget(hours: number[], target: number): number { 2 | return hours.filter(h => h >= target).length; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2828.Check if a String Is an Acronym of Words.ts: -------------------------------------------------------------------------------- 1 | function isAcronym(words: string[], s: string): boolean { 2 | return words.map(w => w[0]).join("") === s; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2829.Determine the Minimum Sum of a k-avoiding Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimumSum(int n, int k) { 3 | Set seen = new HashSet<>(); 4 | for (int i = 1; seen.size() < n; i++) { 5 | if (!seen.contains(k - i)) { 6 | seen.add(i); 7 | } 8 | } 9 | return seen.stream().reduce(0, (a, b) -> a + b); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /2501-3000/2833.Furthest Point From Origin.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def furthestDistanceFromOrigin(self, moves: str) -> int: 4 | def dist(fill): 5 | cnt = Counter(moves.replace("_", fill)) 6 | return abs(cnt["L"] - cnt["R"]) 7 | return max(dist("L"), dist("R")) 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2834.Find the Minimum Possible Sum of a Beautiful Array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumPossibleSum(self, n: int, target: int) -> int: 3 | i = 1 4 | seen = set() 5 | while len(seen) < n: 6 | if target - i not in seen: 7 | seen.add(i) 8 | i += 1 9 | return sum(seen) 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2839.Check if Strings Can be Made Equal With Operations I.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def canBeEqual(self, s1: str, s2: str) -> bool: 5 | return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2]) 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2840.Check if Strings Can be Made Equal With Operations II.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def checkStrings(self, s1: str, s2: str) -> bool: 5 | return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2]) 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2849.Determine if a Cell Is Reachable at a Given Time.c: -------------------------------------------------------------------------------- 1 | bool isReachableAtTime(int sx, int sy, int fx, int fy, int t){ 2 | return abs(sx - fx) <= t && abs(sy - fy) <= t && (t != 1 || sx != fx || sy != fy); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2864.Maximum Odd Binary Number.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def maximumOddBinaryNumber(self, s: str) -> str: 5 | c = Counter(s) 6 | return "1" * (c["1"] - 1) + "0" * c["0"] + "1" 7 | 8 | -------------------------------------------------------------------------------- /2501-3000/2873.Maximum Value of an Ordered Triplet I.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | class Solution: 4 | def maximumTripletValue(self, nums: List[int]) -> int: 5 | res = 0 6 | for comb in itertools.combinations(nums, 3): 7 | res = max(res, (comb[0] - comb[1]) * comb[2]) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /2501-3000/2894.Divisible and Non-divisible Sums Difference.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def differenceOfSums(self, n: int, m: int) -> int: 3 | num2 = (1 + n // m) * (n // m) // 2 * m 4 | num1 = (1 + n) * n // 2 - num2 5 | return num1 - num2 6 | 7 | -------------------------------------------------------------------------------- /2501-3000/2923.Find Champion I.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findChampion(self, grid: List[List[int]]) -> int: 3 | n = len(grid) 4 | for i in range(n): 5 | if sum(grid[i]) - grid[i][i] + 1 == n: 6 | return i 7 | 8 | -------------------------------------------------------------------------------- /2501-3000/2924.Find Champion II.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findChampion(self, n: int, edges: List[List[int]]) -> int: 3 | seen = set(range(n)) 4 | for _, v in edges: 5 | if v in seen: 6 | seen.remove(v) 7 | return seen.pop() if len(seen) == 1 else -1 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2932.Maximum Strong Pair XOR I.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumStrongPairXor(self, nums: List[int]) -> int: 3 | res = float("-inf") 4 | for i in range(len(nums)): 5 | for j in range(i, len(nums)): 6 | a, b = nums[i], nums[j] 7 | if abs(a - b) <= min(a, b): 8 | res = max(res, a ^ b) 9 | return res 10 | 11 | -------------------------------------------------------------------------------- /2501-3000/2938.Separate Black and White Balls.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumSteps(self, s: str) -> int: 3 | zeros = s.count("0") 4 | res = 0 5 | for c in s: 6 | if c == "0": 7 | zeros -= 1 8 | else: 9 | res += zeros 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /2501-3000/2960.Count Tested Devices After Test Operations.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countTestedDevices(self, batteryPercentages: List[int]) -> int: 3 | res = 0 4 | for p in batteryPercentages: 5 | if p > res: 6 | res += 1 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /2501-3000/2961.Double Modular Exponentiation.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]: 3 | return [i for i, [a, b, c, m] in enumerate(variables) if pow(pow(a, b, 10), c, m) == target] 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/2974.Minimum Number Game.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberGame(self, nums: List[int]) -> List[int]: 3 | nums.sort() 4 | for i in range(0, len(nums), 2): 5 | nums[i], nums[i + 1] = nums[i + 1], nums[i] 6 | return nums 7 | 8 | -------------------------------------------------------------------------------- /2501-3000/2980.Check if Bitwise OR Has Trailing Zeros.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasTrailingZeros(self, nums: List[int]) -> bool: 3 | return len([num for num in nums if num & 1 == 0]) >= 2 4 | 5 | -------------------------------------------------------------------------------- /2501-3000/3000.Maximum Area of Longest Diagonal Rectangle.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int: 3 | return max(map(lambda d: (d[0] * d[0] + d[1] * d[1], d[0] * d[1]), dimensions))[1] 4 | 5 | -------------------------------------------------------------------------------- /3001-3500/3005.Count Elements With Maximum Frequency.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def maxFrequencyElements(self, nums: List[int]) -> int: 5 | cnt = Counter(nums).most_common() 6 | return sum([p[1] for p in cnt if p[1] == cnt[0][1]]) 7 | 8 | -------------------------------------------------------------------------------- /3001-3500/3131.Find the Integer Added to Array I.ts: -------------------------------------------------------------------------------- 1 | function addedInteger(nums1: number[], nums2: number[]): number { 2 | return Math.min(...nums2) - Math.min(...nums1); 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /3001-3500/3136.Valid Word.py: -------------------------------------------------------------------------------- 1 | import string 2 | 3 | class Solution: 4 | def isValid(self, word: str) -> bool: 5 | vowels = set('aeiouAEIOU') 6 | consonants = set(string.ascii_letters) - vowels 7 | symbols = set("@#$") 8 | word_set = set(word) 9 | return bool(len(word) >= 3 and word_set & vowels and word_set & consonants and not (word_set & symbols)) 10 | 11 | -------------------------------------------------------------------------------- /3001-3500/3137.Minimum Number of Operations to Make Word K-Periodic.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | class Solution: 4 | def minimumOperationsToMakeKPeriodic(self, word: str, k: int) -> int: 5 | cnt = Counter() 6 | for i in range(0, len(word), k): 7 | cnt[word[i:i+k]] += 1 8 | return len(word) // k - max(cnt.values()) 9 | 10 | -------------------------------------------------------------------------------- /3001-3500/3146.Permutation Difference between Two Strings.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findPermutationDifference(self, s: str, t: str) -> int: 3 | arr1 = sorted((c, i) for i, c in enumerate(s)) 4 | arr2 = sorted((c, i) for i, c in enumerate(t)) 5 | return sum(abs(a[1] - b[1]) for (a, b) in zip(arr1, arr2)) 6 | 7 | -------------------------------------------------------------------------------- /3001-3500/3147.Taking Maximum Energy From the Mystic Dungeon.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumEnergy(self, energy: List[int], k: int) -> int: 3 | res = energy[-1] 4 | for start in range(len(energy) - 1, len(energy) - 1 - k, -1): 5 | sm = 0 6 | for i in range(start, -1, -k): 7 | sm += energy[i] 8 | res = max(res, sm) 9 | return res 10 | 11 | -------------------------------------------------------------------------------- /3001-3500/3168.Minimum Number of Chairs in a Waiting Room.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumChairs(self, s: str) -> int: 3 | res = cur = 0 4 | for c in s: 5 | cur += 1 if c == 'E' else -1 6 | res = max(res, cur) 7 | return res 8 | 9 | -------------------------------------------------------------------------------- /3001-3500/3169.Count Days Without Meetings.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countDays(self, days: int, meetings: List[List[int]]) -> int: 3 | meetings.sort() 4 | res = 0 5 | cur = 0 6 | for start, end in meetings: 7 | if start > cur: 8 | res += start - cur - 1 9 | cur = max(cur, end) 10 | res += days - cur 11 | return res 12 | 13 | -------------------------------------------------------------------------------- /3001-3500/3171.Find Subarray With Bitwise OR Closest to K.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumDifference(self, nums: List[int], k: int) -> int: 3 | s = set() 4 | res = float("inf") 5 | for num in nums: 6 | s = {num | prev for prev in s} | {num} 7 | res = min(res, min(abs(n - k) for n in s)) 8 | return res 9 | 10 | -------------------------------------------------------------------------------- /3001-3500/3178.Find the Child Who Has the Ball After K Seconds.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numberOfChild(n: Int, k: Int): Int { 3 | val res = k % ((n - 1) * 2) 4 | return if (res < n - 1) res else (n - 1) * 2 - res 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /3001-3500/3180.Maximum Total Reward Using Operations I.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxTotalReward(self, rewardValues: List[int]) -> int: 3 | rewardValues = sorted(set(rewardValues)) 4 | possible_sums = set() 5 | for r in rewardValues: 6 | possible_sums |= {r + x for x in possible_sums if r > x} | {r} 7 | return max(possible_sums) 8 | 9 | -------------------------------------------------------------------------------- /3001-3500/3184.Count Pairs That Form a Complete Day I.py: -------------------------------------------------------------------------------- 1 | from itertools import combinations 2 | class Solution: 3 | def countCompleteDayPairs(self, hours: List[int]) -> int: 4 | return sum(1 for a, b in combinations(hours, 2) if (a + b) % 24 == 0) 5 | 6 | -------------------------------------------------------------------------------- /3001-3500/3216.Lexicographically Smallest String After a Swap.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getSmallestString(self, s: str) -> str: 3 | s = list(s) 4 | for i in range(len(s) - 1): 5 | a, b = int(s[i]), int(s[i + 1]) 6 | if a > b and a % 2 == b % 2: 7 | s[i], s[i + 1] = s[i + 1], s[i] 8 | break 9 | return ''.join(s) 10 | 11 | -------------------------------------------------------------------------------- /3001-3500/3232.Find if Digit Game Can Be Won.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canAliceWin(self, nums: List[int]) -> bool: 3 | return sum(nums) != sum(num for num in nums if num < 10) * 2 4 | 5 | -------------------------------------------------------------------------------- /LCP/LCP 01.Guess Numbers.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def game(self, guess, answer): 3 | """ 4 | :type guess: List[int] 5 | :type answer: List[int] 6 | :rtype: int 7 | """ 8 | return len([a for a, b in zip(guess, answer) if a == b]) 9 | 10 | -------------------------------------------------------------------------------- /LCP/LCP 06.拿硬币.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minCount(self, coins): 3 | """ 4 | :type coins: List[int] 5 | :rtype: int 6 | """ 7 | return sum(coin // 2 + coin % 2 for coin in coins) 8 | 9 | -------------------------------------------------------------------------------- /LCR/LCR 069.山脉数组的峰顶索引.ts: -------------------------------------------------------------------------------- 1 | function peakIndexInMountainArray(arr: number[]): number { 2 | for (let i = 1; i < arr.length - 1; i++) { 3 | if (arr[i] > arr[i + 1]) return i; 4 | } 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /LCR/LCR 120.寻找文件副本.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution(object): 3 | def findRepeatNumber(self, nums): 4 | """ 5 | :type nums: List[int] 6 | :rtype: int 7 | """ 8 | return Counter(nums).most_common()[0][0] 9 | 10 | -------------------------------------------------------------------------------- /LCR/LCR 126.斐波那契数.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | MOD = 10 ** 9 + 7 4 | def fib(n) 5 | a, b = 0, 1 6 | (n - 1).times do 7 | a, b = b, a + b 8 | end 9 | return n.zero? ? 0 : b % MOD 10 | end 11 | 12 | -------------------------------------------------------------------------------- /LCR/LCR 131.砍竹子 I.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def cuttingRope(self, n: int) -> int: 3 | 4 | @lru_cache(None) 5 | def dp(n): 6 | if n == 1: 7 | return 1 8 | res = n 9 | for cur in range(1, n): 10 | res = max(res, cur * dp(n - cur)) 11 | return res 12 | return max(dp(n - i) * dp(i) for i in range(1, n)) 13 | 14 | -------------------------------------------------------------------------------- /LCR/LCR 133.位 1 的个数.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n - a positive integer 3 | * @return {number} 4 | */ 5 | var hammingWeight = function(n) { 6 | let res = 0; 7 | while (n) { 8 | res += 1; 9 | n &= n - 1; 10 | } 11 | return res; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /LCR/LCR 156.序列化与反序列化二叉树.js: -------------------------------------------------------------------------------- 1 | var serialize = JSON.stringify; 2 | var deserialize = JSON.parse; 3 | 4 | -------------------------------------------------------------------------------- /LCR/LCR 161.连续天数的最高销售额.ts: -------------------------------------------------------------------------------- 1 | function maxSubArray(nums: number[]): number { 2 | let maxSum = -Infinity, sm = 0; 3 | nums.forEach(num => { 4 | sm += num; 5 | maxSum = Math.max(maxSum, sm); 6 | sm = Math.max(sm, 0); 7 | }) 8 | return maxSum; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /LCR/LCR 169.招式拆解 II.ts: -------------------------------------------------------------------------------- 1 | function firstUniqChar(s: string): string { 2 | const cnt = {'': 0}; 3 | [].forEach.call(s, (c: string) => { 4 | cnt[c] ||= 0; 5 | cnt[c]++; 6 | }); 7 | for (let i = 0; i < s.length; i++) { 8 | if (cnt[s[i]] === 1) { 9 | return s[i]; 10 | } 11 | } 12 | return " "; 13 | }; 14 | 15 | 16 | -------------------------------------------------------------------------------- /LCR/LCR 172.统计目标成绩的出现次数.ts: -------------------------------------------------------------------------------- 1 | function search(nums: number[], target: number): number { 2 | return nums.filter(num => num === target).length; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /LCS/LCS 01.下载插件.c: -------------------------------------------------------------------------------- 1 | int leastMinutes(int n){ 2 | n--; 3 | int res = 1; 4 | while (n != 0) { 5 | n >>= 1; 6 | res++; 7 | } 8 | return res; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /others/技巧总结.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiwensun/leetcode/980a22db643417e3782e40b3b47b12343b5bcc45/others/技巧总结.docx -------------------------------------------------------------------------------- /面试题/面试题 01.01.Is Unique LCCI.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isUnique(self, astr): 3 | """ 4 | :type astr: str 5 | :rtype: bool 6 | """ 7 | mask = 0 8 | for c in astr: 9 | bit = 1 << (ord(c) - ord('a')) 10 | if bit & mask: 11 | return False 12 | mask |= bit 13 | return True 14 | 15 | -------------------------------------------------------------------------------- /面试题/面试题 17.01.Add Without Plus LCCI.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b){ 2 | unsigned ua = (unsigned) a; 3 | unsigned ub = (unsigned) b; 4 | while (ua != 0) { 5 | unsigned carry = (ua & ub) << 1; 6 | unsigned sum = ua ^ ub; 7 | ua = carry; 8 | ub = sum; 9 | } 10 | return (int)ub; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /面试题/面试题 17.04.Missing Number LCCI.ts: -------------------------------------------------------------------------------- 1 | function missingNumber(nums: number[]): number { 2 | let xor = nums.length; 3 | for (let i in nums) { 4 | xor ^= +i ^ nums[i]; 5 | } 6 | return xor; 7 | } 8 | ; 9 | -------------------------------------------------------------------------------- /面试题/面试题 17.14.Smallest K LCCI.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Solution: 4 | def smallestK(self, arr: List[int], k: int) -> List[int]: 5 | return heapq.nsmallest(k, arr) 6 | 7 | -------------------------------------------------------------------------------- /面试题/面试题 17.16.The Masseuse LCCI.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def massage(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | take = no_take = 0 8 | for num in nums: 9 | take, no_take = no_take + num, max(take, no_take) 10 | return max(take, no_take) 11 | 12 | -------------------------------------------------------------------------------- /面试题/面试题 17.16.The Masseuse LCCI.ts: -------------------------------------------------------------------------------- 1 | function massage(nums: number[]): number { 2 | let dp = [0, 0]; // booked, not booked 3 | for (let num of nums) { 4 | dp = [dp[1] + num, Math.max(...dp)]; 5 | } 6 | return Math.max(...dp); 7 | }; 8 | 9 | --------------------------------------------------------------------------------