diff --git a/leetcode/DIRECTORY.md b/leetcode/DIRECTORY.md index eea7a8ef..f9a4f8d7 100644 --- a/leetcode/DIRECTORY.md +++ b/leetcode/DIRECTORY.md @@ -3,143 +3,144 @@ ### LeetCode Algorithm -| # | Title | Solution | Difficulty | -| ----| ------------------------------------------------------------------------------------------------------------------------------------------------------| ----------------- | ---------- | -| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [C](./src/1.c) | Easy | -| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [C](./src/2.c) | Medium | -| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [C](./src/3.c) | Medium | -| 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays) | [C](./src/4.c) | Hard | -| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [C](./src/6.c) | Medium | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [C](./src/7.c) | Medium | -| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [C](./src/8.c) | Medium | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [C](./src/9.c) | Easy | -| 10 | [Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching) | [C](./src/10.c) | Hard | -| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [C](./src/11.c) | Medium | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c) | Medium | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [C](./src/13.c) | Easy | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) | [C](./src/14.c) | Easy | -| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses) | [C](./src/20.c) | Easy | -| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists) | [C](./src/21.c) | Easy | -| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [C](./src/24.c) | Medium | -| 26 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [C](./src/26.c) | Easy | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element) | [C](./src/27.c) | Easy | -| 28 | [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C](./src/28.c) | Medium | -| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [C](./src/29.c) | Medium | -| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses) | [C](./src/32.c) | Hard | -| 35 | [Search Insert Position](https://leetcode.com/problems/search-insert-position) | [C](./src/35.c) | Easy | -| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [C](./src/37.c) | Hard | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [C](./src/38.c) | Medium | -| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [C](./src/42.c) | Hard | -| 50 | [Pow(x, n)](https://leetcode.com/problems/powx-n) | [C](./src/50.c) | Medium | -| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray) | [C](./src/53.c) | Medium | -| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [C](./src/62.c) | Medium | -| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [C](./src/63.c) | Medium | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [C](./src/66.c) | Easy | -| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [C](./src/75.c) | Medium | -| 79 | [Word Search](https://leetcode.com/problems/word-search) | [C](./src/79.c) | Medium | -| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [C](./src/82.c) | Medium | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [C](./src/83.c) | Easy | -| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [C](./src/94.c) | Easy | -| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [C](./src/98.c) | Medium | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [C](./src/101.c) | Easy | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [C](./src/104.c) | Easy | -| 108 | [Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [C](./src/108.c) | Easy | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [C](./src/109.c) | Medium | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [C](./src/110.c) | Easy | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [C](./src/112.c) | Easy | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [C](./src/118.c) | Easy | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [C](./src/119.c) | Easy | -| 121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [C](./src/121.c) | Easy | -| 124 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [C](./src/124.c) | Hard | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [C](./src/125.c) | Easy | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [C](./src/136.c) | Easy | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [C](./src/141.c) | Easy | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [C](./src/142.c) | Medium | -| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [C](./src/153.c) | Medium | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [C](./src/160.c) | Easy | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [C](./src/169.c) | Easy | -| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [C](./src/173.c) | Medium | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [C](./src/189.c) | Medium | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [C](./src/190.c) | Easy | -| 191 | [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits) | [C](./src/191.c) | Easy | -| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [C](./src/201.c) | Medium | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [C](./src/203.c) | Easy | -| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [C](./src/206.c) | Easy | -| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [C](./src/215.c) | Medium | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [C](./src/217.c) | Easy | -| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [C](./src/223.c) | Medium | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [C](./src/226.c) | Easy | -| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [C](./src/230.c) | Medium | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [C](./src/231.c) | Easy | -| 234 | [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list) | [C](./src/234.c) | Easy | -| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [C](./src/236.c) | Medium | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [C](./src/242.c) | Easy | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [C](./src/268.c) | Easy | -| 274 | [H-Index](https://leetcode.com/problems/h-index) | [C](./src/274.c) | Medium | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [C](./src/278.c) | Easy | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [C](./src/283.c) | Easy | -| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [C](./src/287.c) | Medium | -| 344 | [Reverse String](https://leetcode.com/problems/reverse-string) | [C](./src/344.c) | Easy | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [C](./src/367.c) | Easy | -| 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string) | [C](./src/387.c) | Easy | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [C](./src/389.c) | Easy | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [C](./src/404.c) | Easy | -| 442 | [Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array) | [C](./src/442.c) | Medium | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [C](./src/461.c) | Easy | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [C](./src/476.c) | Easy | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [C](./src/485.c) | Easy | -| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [C](./src/509.c) | Easy | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [C](./src/520.c) | Easy | -| 561 | [Array Partition](https://leetcode.com/problems/array-partition) | [C](./src/561.c) | Easy | -| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [C](./src/617.c) | Easy | -| 647 | [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings) | [C](./src/647.c) | Medium | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [C](./src/669.c) | Medium | -| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [C](./src/674.c) | Easy | -| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection) | [C](./src/684.c) | Medium | -| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [C](./src/700.c) | Easy | -| 701 | [Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree) | [C](./src/701.c) | Medium | -| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [C](./src/704.c) | Easy | -| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [C](./src/709.c) | Easy | -| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [C](./src/771.c) | Easy | -| 807 | [Max Increase to Keep City Skyline](https://leetcode.com/problems/max-increase-to-keep-city-skyline) | [C](./src/807.c) | Medium | -| 841 | [Keys and Rooms](https://leetcode.com/problems/keys-and-rooms) | [C](./src/841.c) | Medium | -| 852 | [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [C](./src/852.c) | Medium | -| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [C](./src/876.c) | Easy | -| 901 | [Online Stock Span](https://leetcode.com/problems/online-stock-span) | [C](./src/901.c) | Medium | -| 905 | [Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity) | [C](./src/905.c) | Easy | -| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [C](./src/917.c) | Easy | -| 931 | [Minimum Falling Path Sum](https://leetcode.com/problems/minimum-falling-path-sum) | [C](./src/931.c) | Medium | -| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [C](./src/938.c) | Easy | -| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [C](./src/965.c) | Easy | -| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | [C](./src/977.c) | Easy | -| 985 | [Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | [C](./src/985.c) | Medium | -| 1008| [Construct Binary Search Tree from Preorder Traversal](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal) | [C](./src/1008.c) | Medium | -| 1009| [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [C](./src/1009.c) | Easy | -| 1019| [Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list) | [C](./src/1019.c) | Medium | -| 1026| [Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor) | [C](./src/1026.c) | Medium | -| 1089| [Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros) | [C](./src/1089.c) | Easy | -| 1147| [Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition) | [C](./src/1147.c) | Hard | -| 1184| [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [C](./src/1184.c) | Easy | -| 1189| [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [C](./src/1189.c) | Easy | -| 1207| [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [C](./src/1207.c) | Easy | -| 1283| [Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold) | [C](./src/1283.c) | Medium | -| 1524| [Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum) | [C](./src/1524.c) | Medium | -| 1653| [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced) | [C](./src/1653.c) | Medium | -| 1657| [Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close) | [C](./src/1657.c) | Medium | -| 1695| [Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value) | [C](./src/1695.c) | Medium | -| 1704| [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [C](./src/1704.c) | Easy | -| 1752| [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [C](./src/1752.c) | Easy | -| 1769| [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box)| [C](./src/1769.c) | Medium | -| 1833| [Maximum Ice Cream Bars](https://leetcode.com/problems/maximum-ice-cream-bars) | [C](./src/1833.c) | Medium | -| 1838| [Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element) | [C](./src/1838.c) | Medium | -| 2024| [Maximize the Confusion of an Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam) | [C](./src/2024.c) | Medium | -| 2095| [Delete the Middle Node of a Linked List](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list) | [C](./src/2095.c) | Medium | -| 2125| [Number of Laser Beams in a Bank](https://leetcode.com/problems/number-of-laser-beams-in-a-bank) | [C](./src/2125.c) | Medium | -| 2130| [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list) | [C](./src/2130.c) | Medium | -| 2222| [Number of Ways to Select Buildings](https://leetcode.com/problems/number-of-ways-to-select-buildings) | [C](./src/2222.c) | Medium | -| 2256| [Minimum Average Difference](https://leetcode.com/problems/minimum-average-difference) | [C](./src/2256.c) | Medium | -| 2270| [Number of Ways to Split Array](https://leetcode.com/problems/number-of-ways-to-split-array) | [C](./src/2270.c) | Medium | -| 2279| [Maximum Bags With Full Capacity of Rocks](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks) | [C](./src/2279.c) | Medium | -| 2304| [Minimum Path Cost in a Grid](https://leetcode.com/problems/minimum-path-cost-in-a-grid) | [C](./src/2304.c) | Medium | -| 2482| [Difference Between Ones and Zeros in Row and Column](https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column) | [C](./src/2482.c) | Medium | -| 2501| [Longest Square Streak in an Array](https://leetcode.com/problems/longest-square-streak-in-an-array) | [C](./src/2501.c) | Medium | +| # | Title | Solution | Difficulty | +| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ---------- | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [C](./src/1.c) | Easy | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [C](./src/2.c) | Medium | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [C](./src/3.c) | Medium | +| 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays) | [C](./src/4.c) | Hard | +| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [C](./src/6.c) | Medium | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [C](./src/7.c) | Medium | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [C](./src/8.c) | Medium | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [C](./src/9.c) | Easy | +| 10 | [Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching) | [C](./src/10.c) | Hard | +| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [C](./src/11.c) | Medium | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c) | Medium | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [C](./src/13.c) | Easy | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) | [C](./src/14.c) | Easy | +| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses) | [C](./src/20.c) | Easy | +| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists) | [C](./src/21.c) | Easy | +| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [C](./src/24.c) | Medium | +| 26 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [C](./src/26.c) | Easy | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element) | [C](./src/27.c) | Easy | +| 28 | [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C](./src/28.c) | Medium | +| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [C](./src/29.c) | Medium | +| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses) | [C](./src/32.c) | Hard | +| 35 | [Search Insert Position](https://leetcode.com/problems/search-insert-position) | [C](./src/35.c) | Easy | +| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [C](./src/37.c) | Hard | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [C](./src/38.c) | Medium | +| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [C](./src/42.c) | Hard | +| 50 | [Pow(x, n)](https://leetcode.com/problems/powx-n) | [C](./src/50.c) | Medium | +| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray) | [C](./src/53.c) | Medium | +| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [C](./src/62.c) | Medium | +| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [C](./src/63.c) | Medium | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [C](./src/66.c) | Easy | +| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [C](./src/75.c) | Medium | +| 79 | [Word Search](https://leetcode.com/problems/word-search) | [C](./src/79.c) | Medium | +| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [C](./src/82.c) | Medium | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [C](./src/83.c) | Easy | +| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [C](./src/94.c) | Easy | +| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [C](./src/98.c) | Medium | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [C](./src/101.c) | Easy | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [C](./src/104.c) | Easy | +| 108 | [Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [C](./src/108.c) | Easy | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [C](./src/109.c) | Medium | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [C](./src/110.c) | Easy | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [C](./src/112.c) | Easy | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [C](./src/118.c) | Easy | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [C](./src/119.c) | Easy | +| 121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [C](./src/121.c) | Easy | +| 124 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [C](./src/124.c) | Hard | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [C](./src/125.c) | Easy | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [C](./src/136.c) | Easy | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [C](./src/141.c) | Easy | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [C](./src/142.c) | Medium | +| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [C](./src/153.c) | Medium | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [C](./src/160.c) | Easy | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [C](./src/169.c) | Easy | +| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [C](./src/173.c) | Medium | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [C](./src/189.c) | Medium | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [C](./src/190.c) | Easy | +| 191 | [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits) | [C](./src/191.c) | Easy | +| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [C](./src/201.c) | Medium | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [C](./src/203.c) | Easy | +| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [C](./src/206.c) | Easy | +| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [C](./src/215.c) | Medium | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [C](./src/217.c) | Easy | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [C](./src/223.c) | Medium | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [C](./src/226.c) | Easy | +| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [C](./src/230.c) | Medium | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [C](./src/231.c) | Easy | +| 234 | [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list) | [C](./src/234.c) | Easy | +| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [C](./src/236.c) | Medium | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [C](./src/242.c) | Easy | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [C](./src/268.c) | Easy | +| 274 | [H-Index](https://leetcode.com/problems/h-index) | [C](./src/274.c) | Medium | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [C](./src/278.c) | Easy | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [C](./src/283.c) | Easy | +| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [C](./src/287.c) | Medium | +| 344 | [Reverse String](https://leetcode.com/problems/reverse-string) | [C](./src/344.c) | Easy | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [C](./src/367.c) | Easy | +| 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string) | [C](./src/387.c) | Easy | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [C](./src/389.c) | Easy | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [C](./src/404.c) | Easy | +| 442 | [Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array) | [C](./src/442.c) | Medium | +| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [C](./src/461.c) | Easy | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [C](./src/476.c) | Easy | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [C](./src/485.c) | Easy | +| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [C](./src/509.c) | Easy | +| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [C](./src/520.c) | Easy | +| 561 | [Array Partition](https://leetcode.com/problems/array-partition) | [C](./src/561.c) | Easy | +| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [C](./src/617.c) | Easy | +| 647 | [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings) | [C](./src/647.c) | Medium | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [C](./src/669.c) | Medium | +| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [C](./src/674.c) | Easy | +| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection) | [C](./src/684.c) | Medium | +| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [C](./src/700.c) | Easy | +| 701 | [Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree) | [C](./src/701.c) | Medium | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [C](./src/704.c) | Easy | +| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [C](./src/709.c) | Easy | +| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [C](./src/771.c) | Easy | +| 807 | [Max Increase to Keep City Skyline](https://leetcode.com/problems/max-increase-to-keep-city-skyline) | [C](./src/807.c) | Medium | +| 841 | [Keys and Rooms](https://leetcode.com/problems/keys-and-rooms) | [C](./src/841.c) | Medium | +| 852 | [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [C](./src/852.c) | Medium | +| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [C](./src/876.c) | Easy | +| 901 | [Online Stock Span](https://leetcode.com/problems/online-stock-span) | [C](./src/901.c) | Medium | +| 905 | [Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity) | [C](./src/905.c) | Easy | +| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [C](./src/917.c) | Easy | +| 931 | [Minimum Falling Path Sum](https://leetcode.com/problems/minimum-falling-path-sum) | [C](./src/931.c) | Medium | +| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [C](./src/938.c) | Easy | +| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [C](./src/965.c) | Easy | +| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | [C](./src/977.c) | Easy | +| 985 | [Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | [C](./src/985.c) | Medium | +| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [C](./src/997.c) | Easy | +| 1008 | [Construct Binary Search Tree from Preorder Traversal](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal) | [C](./src/1008.c) | Medium | +| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [C](./src/1009.c) | Easy | +| 1019 | [Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list) | [C](./src/1019.c) | Medium | +| 1026 | [Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor) | [C](./src/1026.c) | Medium | +| 1089 | [Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros) | [C](./src/1089.c) | Easy | +| 1147 | [Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition) | [C](./src/1147.c) | Hard | +| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [C](./src/1184.c) | Easy | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [C](./src/1189.c) | Easy | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [C](./src/1207.c) | Easy | +| 1283 | [Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold) | [C](./src/1283.c) | Medium | +| 1524 | [Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum) | [C](./src/1524.c) | Medium | +| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced) | [C](./src/1653.c) | Medium | +| 1657 | [Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close) | [C](./src/1657.c) | Medium | +| 1695 | [Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value) | [C](./src/1695.c) | Medium | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [C](./src/1704.c) | Easy | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [C](./src/1752.c) | Easy | +| 1769 | [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box) | [C](./src/1769.c) | Medium | +| 1833 | [Maximum Ice Cream Bars](https://leetcode.com/problems/maximum-ice-cream-bars) | [C](./src/1833.c) | Medium | +| 1838 | [Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element) | [C](./src/1838.c) | Medium | +| 2024 | [Maximize the Confusion of an Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam) | [C](./src/2024.c) | Medium | +| 2095 | [Delete the Middle Node of a Linked List](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list) | [C](./src/2095.c) | Medium | +| 2125 | [Number of Laser Beams in a Bank](https://leetcode.com/problems/number-of-laser-beams-in-a-bank) | [C](./src/2125.c) | Medium | +| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list) | [C](./src/2130.c) | Medium | +| 2222 | [Number of Ways to Select Buildings](https://leetcode.com/problems/number-of-ways-to-select-buildings) | [C](./src/2222.c) | Medium | +| 2256 | [Minimum Average Difference](https://leetcode.com/problems/minimum-average-difference) | [C](./src/2256.c) | Medium | +| 2270 | [Number of Ways to Split Array](https://leetcode.com/problems/number-of-ways-to-split-array) | [C](./src/2270.c) | Medium | +| 2279 | [Maximum Bags With Full Capacity of Rocks](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks) | [C](./src/2279.c) | Medium | +| 2304 | [Minimum Path Cost in a Grid](https://leetcode.com/problems/minimum-path-cost-in-a-grid) | [C](./src/2304.c) | Medium | +| 2482 | [Difference Between Ones and Zeros in Row and Column](https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column) | [C](./src/2482.c) | Medium | +| 2501 | [Longest Square Streak in an Array](https://leetcode.com/problems/longest-square-streak-in-an-array) | [C](./src/2501.c) | Medium | diff --git a/leetcode/src/997.c b/leetcode/src/997.c new file mode 100644 index 00000000..a599555f --- /dev/null +++ b/leetcode/src/997.c @@ -0,0 +1,29 @@ +// Using hashtable. +// Runtime: O(n + len(trust)) +// Space: O(n) +int findJudge(int n, int** trust, int trustSize, int* trustColSize){ + int* personsToTrust = calloc(n + 1, sizeof(int)); + int* personsFromTrust = calloc(n + 1, sizeof(int)); + + for(int i = 0; i < trustSize; i++){ + int* currentTrust = trust[i]; + personsToTrust[currentTrust[1]] += 1; + personsFromTrust[currentTrust[0]] += 1; + } + + int potentialJudjeNumber = -1; + for(int i = 1; i < n + 1; i++){ + if (personsToTrust[i] == n - 1 && personsFromTrust[i] == 0){ + if (potentialJudjeNumber > -1){ + return -1; + } + + potentialJudjeNumber = i; + } + } + + free(personsToTrust); + free(personsFromTrust); + + return potentialJudjeNumber; +}