Skip to content

JavaScript solutions to various LeetCode problems

License

Notifications You must be signed in to change notification settings

JoshCrozier/leetcode-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode solutions in JavaScript

https://leetcode.com/

Table of Contents:

# Title Difficulty
1 Two Sum Easy
2 Add Two Numbers Medium
3 Longest Substring Without Repeating Characters Medium
4 Median of Two Sorted Arrays Hard
5 Longest Palindromic Substring Medium
6 ZigZag Conversion Medium
7 Reverse Integer Easy
8 String to Integer (atoi) Medium
9 Palindrome Number Easy
10 Regular Expression Matching Hard
11 Container With Most Water Medium
12 Integer to Roman Medium
13 Roman to Integer Easy
14 Longest Common Prefix Easy
15 3Sum Medium
16 3Sum Closest Medium
17 Letter Combinations of a Phone Number Medium
18 4Sum Medium
19 Remove Nth Node From End of List Medium
20 Valid Parentheses Easy
21 Merge Two Sorted Lists Easy
22 Generate Parentheses Medium
23 Merge k Sorted Lists Hard
24 Swap Nodes in Pairs Medium
25 Reverse Nodes in k-Group Hard
26 Remove Duplicates from Sorted Array Easy
27 Remove Element Easy
28 Implement strStr() Easy
29 Divide Two Integers Medium
30 Substring with Concatenation of All Words Hard
31 Next Permutation Medium
32 Longest Valid Parentheses Hard
33 Search in Rotated Sorted Array Medium
34 Find First and Last Position of Element in Sorted Array Medium
35 Search Insert Position Easy
36 Valid Sudoku Medium
37 Sudoku Solver Hard
38 Count and Say Medium
39 Combination Sum Medium
40 Combination Sum II Medium
41 First Missing Positive Hard
42 Trapping Rain Water Hard
43 Multiply Strings Medium
44 Wildcard Matching Hard
45 Jump Game II Medium
46 Permutations Medium
47 Permutations II Medium
48 Rotate Image Medium
49 Group Anagrams Medium
50 Pow(x, n) Medium
51 N-Queens Hard
52 N-Queens II Hard
53 Maximum Subarray Easy
54 Spiral Matrix Medium
55 Jump Game Medium
56 Merge Intervals Medium
57 Insert Interval Medium
58 Length of Last Word Easy
59 Spiral Matrix II Medium
60 Permutation Sequence Hard
61 Rotate List Medium
62 Unique Paths Medium
63 Unique Paths II Medium
64 Minimum Path Sum Medium
65 Valid Number Hard
66 Plus One Easy
67 Add Binary Easy
68 Text Justification Hard
69 Sqrt(x) Medium
70 Climbing Stairs Easy
71 Simplify Path Medium
72 Edit Distance Medium
73 Set Matrix Zeroes Medium
74 Search a 2D Matrix Medium
75 Sort Colors Medium
77 Combinations Medium
78 Subsets Medium
79 Word Search Medium
80 Remove Duplicates from Sorted Array II Medium
81 Search in Rotated Sorted Array II Medium
82 Remove Duplicates from Sorted List II Medium
83 Remove Duplicates from Sorted List Easy
84 Largest Rectangle in Histogram Hard
85 Maximal Rectangle Hard
86 Partition List Medium
88 Merge Sorted Array Easy
89 Gray Code Medium
90 Subsets II Medium
92 Reverse Linked List II Medium
93 Restore IP Addresses Medium
94 Binary Tree Inorder Traversal Easy
95 Unique Binary Search Trees II Medium
96 Unique Binary Search Trees Medium
98 Validate Binary Search Tree Medium
99 Recover Binary Search Tree Medium
100 Same Tree Easy
101 Symmetric Tree Easy
102 Binary Tree Level Order Traversal Medium
104 Maximum Depth of Binary Tree Easy
108 Convert Sorted Array to Binary Search Tree Easy
110 Balanced Binary Tree Easy
111 Minimum Depth of Binary Tree Easy
112 Path Sum Easy
113 Path Sum II Medium
114 Flatten Binary Tree to Linked List Medium
115 Distinct Subsequences Hard
116 Populating Next Right Pointers in Each Node Medium
118 Pascal's Triangle Easy
119 Pascal's Triangle II Easy
120 Triangle Medium
121 Best Time to Buy and Sell Stock Easy
125 Valid Palindrome Easy
128 Longest Consecutive Sequence Medium
131 Palindrome Partitioning Medium
133 Clone Graph Medium
134 Gas Station Medium
135 Candy Hard
136 Single Number Easy
137 Single Number II Medium
138 Copy List with Random Pointer Medium
139 Word Break Medium
140 Word Break II Hard
141 Linked List Cycle Easy
142 Linked List Cycle II Medium
143 Reorder List Medium
144 Binary Tree Preorder Traversal Easy
145 Binary Tree Postorder Traversal Easy
146 LRU Cache Medium
148 Sort List Medium
149 Max Points on a Line Hard
151 Reverse Words in a String Medium
152 Maximum Product Subarray Medium
160 Intersection of Two Linked Lists Medium
164 Maximum Gap Medium
167 Two Sum II - Input Array Is Sorted Easy
168 Excel Sheet Column Title Easy
169 Majority Element Easy
179 Largest Number Medium
187 Repeated DNA Sequences Medium
189 Rotate Array Medium
190 Reverse Bits Easy
191 Number of 1 Bits Easy
198 House Robber Medium
202 Happy Number Easy
203 Remove Linked List Elements Easy
204 Count Primes Medium
205 Isomorphic Strings Easy
206 Reverse Linked List Easy
207 Course Schedule Medium
213 House Robber II Medium
214 Shortest Palindrome Hard
215 Kth Largest Element in an Array Medium
216 Combination Sum III Medium
217 Contains Duplicate Easy
219 Contains Duplicate II Easy
220 Contains Duplicate III Hard
225 Implement Stack using Queues Easy
226 Invert Binary Tree Easy
229 Majority Element II Medium
231 Power of Two Easy
232 Implement Queue using Stacks Easy
234 Palindrome Linked List Easy
235 Lowest Common Ancestor of a Binary Search Tree Easy
237 Delete Node in a Linked List Easy
238 Product of Array Except Self Medium
242 Valid Anagram Easy
263 Ugly Number Easy
264 Ugly Number II Medium
268 Missing Number Easy
273 Integer to English Words Hard
274 H-Index Medium
278 First Bad Version Medium
283 Move Zeroes Easy
290 Word Pattern Easy
295 Find Median from Data Stream Hard
316 Remove Duplicate Letters Medium
326 Power of Three Easy
328 Odd Even Linked List Medium
334 Increasing Triplet Subsequence Medium
338 Counting Bits Easy
342 Power of Four Easy
344 Reverse String Easy
345 Reverse Vowels of a String Easy
347 Top K Frequent Elements Medium
349 Intersection of Two Arrays Easy
350 Intersection of Two Arrays II Easy
367 Valid Perfect Square Easy
371 Sum of Two Integers Medium
372 Super Pow Medium
374 Guess Number Higher or Lower Medium
383 Ransom Note Easy
387 First Unique Character in a String Easy
389 Find the Difference Easy
392 Is Subsequence Easy
394 Decode String Medium
395 Longest Substring with At Least K Repeating Characters Medium
405 Convert a Number to Hexadecimal Easy
407 Trapping Rain Water II Hard
412 Fizz Buzz Easy
414 Third Maximum Number Easy
415 Add Strings Easy
419 Battleships in a Board Medium
435 Non-overlapping Intervals Medium
442 Find All Duplicates in an Array Medium
443 String Compression Medium
448 Find All Numbers Disappeared in an Array Easy
451 Sort Characters By Frequency Medium
452 Minimum Number of Arrows to Burst Balloons Medium
456 132 Pattern Medium
459 Repeated Substring Pattern Easy
461 Hamming Distance Easy
463 Island Perimeter Medium
476 Number Complement Easy
482 License Key Formatting Easy
485 Max Consecutive Ones Easy
491 Non-decreasing Subsequences Medium
492 Construct the Rectangle Easy
496 Next Greater Element I Easy
500 Keyboard Row Easy
501 Find Mode in Binary Search Tree Easy
502 IPO Hard
503 Next Greater Element II Medium
504 Base 7 Easy
506 Relative Ranks Easy
507 Perfect Number Easy
509 Fibonacci Number Easy
520 Detect Capital Easy
521 Longest Uncommon Subsequence I Easy
541 Reverse String II Easy
542 01 Matrix Medium
547 Number of Provinces Medium
551 Student Attendance Record I Easy
557 Reverse Words in a String III Easy
563 Binary Tree Tilt Easy
565 Array Nesting Medium
566 Reshape the Matrix Easy
567 Permutation in String Medium
575 Distribute Candies Easy
594 Longest Harmonious Subsequence Easy
599 Minimum Index Sum of Two Lists Easy
605 Can Place Flowers Easy
606 Construct String from Binary Tree Easy
617 Merge Two Binary Trees Easy
621 Task Scheduler Medium
628 Maximum Product of Three Numbers Easy
643 Maximum Average Subarray I Easy
645 Set Mismatch Medium
648 Replace Words Medium
649 Dota2 Senate Medium
653 Two Sum IV - Input is a BST Easy
680 Valid Palindrome II Easy
686 Repeated String Match Easy
695 Max Area of Island Medium
697 Degree of an Array Easy
700 Search in a Binary Search Tree Easy
701 Insert into a Binary Search Tree Medium
704 Binary Search Easy
705 Design HashSet Easy
706 Design HashMap Easy
713 Subarray Product Less Than K Medium
722 Remove Comments Medium
724 Find Pivot Index Easy
733 Flood Fill Easy
735 Asteroid Collision Medium
739 Daily Temperatures Medium
746 Min Cost Climbing Stairs Easy
747 Largest Number At Least Twice of Others Easy
762 Prime Number of Set Bits in Binary Representation Easy
784 Letter Case Permutation Medium
791 Custom Sort String Medium
796 Rotate String Easy
804 Unique Morse Code Words Easy
819 Most Common Word Easy
821 Shortest Distance to a Character Easy
824 Goat Latin Easy
831 Masking Personal Information Medium
841 Keys and Rooms Medium
844 Backspace String Compare Easy
846 Hand of Straights Medium
867 Transpose Matrix Easy
868 Binary Gap Easy
872 Leaf-Similar Trees Easy
876 Middle of the Linked List Easy
884 Uncommon Words from Two Sentences Easy
890 Find and Replace Pattern Medium
901 Online Stock Span Medium
905 Sort Array By Parity Easy
912 Sort an Array Medium
914 X of a Kind in a Deck of Cards Medium
916 Word Subsets Medium
922 Sort Array By Parity II Easy
925 Long Pressed Name Easy
926 Flip String to Monotone Increasing Medium
929 Unique Email Addresses Easy
933 Number of Recent Calls Easy
966 Vowel Spellchecker Medium
970 Powerful Integers Easy
976 Largest Perimeter Triangle Easy
977 Squares of a Sorted Array Easy
985 Sum of Even Numbers After Queries Easy
989 Add to Array-Form of Integer Easy
994 Rotting Oranges Medium
997 Find the Town Judge Easy
1002 Find Common Characters Easy
1004 Max Consecutive Ones III Medium
1005 Maximize Sum Of Array After K Negations Easy
1009 Complement of Base 10 Integer Easy
1010 Pairs of Songs With Total Durations Divisible by 60 Medium
1022 Sum of Root To Leaf Binary Numbers Easy
1023 Camelcase Matching Medium
1037 Valid Boomerang Easy
1041 Robot Bounded In Circle Medium
1047 Remove All Adjacent Duplicates In String Easy
1051 Height Checker Easy
1071 Greatest Common Divisor of Strings Easy
1081 Smallest Subsequence of Distinct Characters Medium
1103 Distribute Candies to People Easy
1108 Defanging an IP Address Easy
1122 Relative Sort Array Easy
1189 Maximum Number of Balloons Easy
1200 Minimum Absolute Difference Easy
1206 Design Skiplist Hard
1207 Unique Number of Occurrences Easy
1208 Get Equal Substrings Within Budget Medium
1217 Minimum Cost to Move Chips to The Same Position Easy
1232 Check If It Is a Straight Line Easy
1233 Remove Sub-Folders from the Filesystem Medium
1249 Minimum Remove to Make Valid Parentheses Medium
1252 Cells with Odd Values in a Matrix Easy
1287 Element Appearing More Than 25% In Sorted Array Easy
1290 Convert Binary Number in a Linked List to Integer Easy
1291 Sequential Digits Medium
1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold Medium
1295 Find Numbers with Even Number of Digits Easy
1296 Divide Array in Sets of K Consecutive Numbers Medium
1297 Maximum Number of Occurrences of a Substring Medium
1304 Find N Unique Integers Sum up to Zero Easy
1309 Decrypt String from Alphabet to Integer Mapping Easy
1313 Decompress Run-Length Encoded List Easy
1317 Convert Integer to the Sum of Two No-Zero Integers Easy
1318 Minimum Flips to Make a OR b Equal to c Medium
1323 Maximum 69 Number Easy
1324 Print Words Vertically Medium
1331 Rank Transform of an Array Easy
1332 Remove Palindromic Subsequences Easy
1333 Filter Restaurants by Vegan-Friendly, Price and Distance Medium
1342 Number of Steps to Reduce a Number to Zero Easy
1351 Count Negative Numbers in a Sorted Matrix Easy
1356 Sort Integers by The Number of 1 Bits Easy
1360 Number of Days Between Two Dates Easy
1365 How Many Numbers Are Smaller Than the Current Number Easy
1368 Minimum Cost to Make at Least One Valid Path in a Grid Hard
1374 Generate a String With Characters That Have Odd Counts Easy
1380 Lucky Numbers in a Matrix Easy
1389 Create Target Array in the Given Order Easy
1400 Construct K Palindrome Strings Medium
1402 Reducing Dishes Hard
1408 String Matching in an Array Easy
1410 HTML Entity Parser Medium
1431 Kids With the Greatest Number of Candies Easy
1436 Destination City Easy
1437 Check If All 1's Are at Least Length K Places Away Easy
1443 Minimum Time to Collect All Apples in a Tree Medium
1446 Consecutive Characters Easy
1447 Simplified Fractions Medium
1450 Number of Students Doing Homework at a Given Time Easy
1451 Rearrange Words in a Sentence Medium
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence Easy
1456 Maximum Number of Vowels in a Substring of Given Length Medium
1460 Make Two Arrays Equal by Reversing Sub-arrays Easy
1464 Maximum Product of Two Elements in an Array Easy
1466 Reorder Routes to Make All Paths Lead to the City Zero Medium
1470 Shuffle the Array Easy
1472 Design Browser History Medium
1475 Final Prices With a Special Discount in a Shop Easy
1480 Running Sum of 1d Array Easy
1481 Least Number of Unique Integers after K Removals Medium
1486 XOR Operation in an Array Easy
1491 Average Salary Excluding the Minimum and Maximum Salary Easy
1492 The kth Factor of n Medium
1493 Longest Subarray of 1's After Deleting One Element Medium
1496 Path Crossing Easy
1502 Can Make Arithmetic Progression From Sequence Easy
1507 Reformat Date Easy
1512 Number of Good Pairs Easy
1519 Number of Nodes in the Sub-Tree With the Same Label Medium
1528 Shuffle String Easy
1550 Three Consecutive Odds Easy
1551 Minimum Operations to Make Array Equal Medium
1566 Detect Pattern of Length M Repeated K or More Times Easy
1576 Replace All ?'s to Avoid Consecutive Repeating Characters Medium
1598 Crawler Log Folder Easy
1657 Determine if Two Strings Are Close Medium
1668 Maximum Repeating Substring Easy
1669 Merge In Between Linked Lists Medium
1672 Richest Customer Wealth Easy
1679 Max Number of K-Sum Pairs Medium
1716 Calculate Money in Leetcode Bank Easy
1732 Find the Highest Altitude Easy
1748 Sum of Unique Elements Easy
1765 Map of Highest Peak Medium
1768 Merge Strings Alternately Easy
1780 Check if Number is a Sum of Powers of Three Medium
1791 Find Center of Star Graph Easy
1812 Determine Color of a Chessboard Square Easy
1817 Finding the Users Active Minutes Medium
1832 Check if the Sentence Is Pangram Easy
1833 Maximum Ice Cream Bars Medium
1880 Check if Word Equals Summation of Two Words Easy
1886 Determine Whether Matrix Can Be Obtained By Rotation Easy
1920 Build Array from Permutation Easy
1929 Concatenation of Array Easy
1935 Maximum Number of Words You Can Type Easy
1996 The Number of Weak Characters in the Game Medium
2000 Reverse Prefix of Word Easy
2011 Final Value of Variable After Performing Operations Easy
2016 Maximum Difference Between Increasing Elements Easy
2017 Grid Game Medium
2027 Minimum Moves to Convert String Easy
2037 Minimum Number of Moves to Seat Everyone Easy
2047 Number of Valid Words in a Sentence Easy
2053 Kth Distinct String in an Array Medium
2085 Count Common Words With One Occurrence Easy
2095 Delete the Middle Node of a Linked List Medium
2099 Find Subsequence of Length K With the Largest Sum Medium
2114 Maximum Number of Words Found in Sentences Easy
2116 Check if a Parentheses String Can Be Valid Medium
2129 Capitalize the Title Easy
2130 Maximum Twin Sum of a Linked List Medium
2154 Keep Multiplying Found Values by Two Easy
2185 Counting Words With a Given Prefix Easy
2215 Find the Difference of Two Arrays Easy
2235 Add Two Integers Easy
2244 Minimum Rounds to Complete All Tasks Medium
2352 Equal Row and Column Pairs Medium
2390 Removing Stars From a String Medium
2396 Strictly Palindromic Number Medium
2413 Smallest Even Multiple Easy
2425 Bitwise XOR of All Pairings Medium
2427 Number of Common Factors Easy
2429 Minimize XOR Medium
2469 Convert the Temperature Easy
2482 Difference Between Ones and Zeros in Row and Column Medium
2490 Circular Sentence Easy
2529 Maximum Count of Positive Integer and Negative Integer Easy
2535 Difference Between Element Sum and Digit Sum of an Array Easy
2618 Check if Object Instance of Class Medium
2619 Array Prototype Last Easy
2620 Counter Easy
2621 Sleep Easy
2622 Cache With Time Limit Medium
2623 Memoize Medium
2625 Flatten Deeply Nested Array Medium
2626 Array Reduce Transformation Easy
2627 Debounce Medium
2629 Function Composition Easy
2630 Memoize II Hard
2631 Group By Medium
2634 Filter Elements from Array Easy
2635 Apply Transform Over Each Element in Array Easy
2637 Promise Time Limit Medium
2648 Generate Fibonacci Sequence Easy
2649 Nested Array Generator Medium
2650 Design Cancellable Function Hard
2657 Find the Prefix Common Array of Two Arrays Medium
2661 First Completely Painted Row or Column Medium
2665 Counter II Easy
2666 Allow One Function Call Easy
2667 Create Hello World Function Easy
2677 Chunk Array Easy
2683 Neighboring Bitwise XOR Medium
2693 Call Function with Custom Context Medium
2695 Array Wrapper Easy
2703 Return Length of Arguments Passed Easy
2704 To Be Or Not To Be Easy
2705 Compact Object Medium
2715 Timeout Cancellation Easy
2721 Execute Asynchronous Functions in Parallel Medium
2722 Join Two Arrays by ID Medium
2723 Add Two Promises Easy
2724 Sort By Easy
3042 Count Prefix and Suffix Pairs I Easy
3110 Score of a String Easy
3223 Minimum Length of String After Operations Medium
3392 Count Subarrays of Length Three With a Condition Easy
3396 Minimum Number of Operations to Make Elements in Array Distinct Easy
3397 Maximum Number of Distinct Elements After Operations Medium
3402 Minimum Operations to Make Columns Strictly Increasing Easy

License

MIT License

Copyright (c) 2019-2025 Josh Crozier