/myleetcode

my leetcode solution

Primary LanguageC

Stay Hungry, Stay Foolish

My own leetcode solutions in pure c. TODO:

  1. update 1-two-sum.c using hash table.(done)
  2. update 28-implement-strstr.c using KMP(done) and Boyer-Moore algorithm.
  3. update 5-longest-palindromic-substring.c using manacher algorithm.(done)
  4. update 214-shortest-palindrome.c using optimized algorithms.
  5. update 287-find-the-duplicate-number.c using binary search and Floyd's Tortoise and Hare(cycle detection) algorithm.(done)
  6. update 496-next-greater-element-i.c using hash table.(done)
  7. update 798-smallest-rotation-with-highest-score.c using optimized algorithms.(done)
  8. update 456-132-pattern.c using optimized algorithms.
  9. update 78-subsets.c using bit manipulation.(done)
  10. update qn 494-target-sum.c using dynamic programming.(done)
  11. update 289-game-of-life.c using bit manipulation so it can be solved in space.(done)

Completion statistic:

  • Total : 344
    • Easy : 183
    • Medium : 138
    • Hard : 23

LeetCode Solution Table

ID Title Difficulty Acceptance Rate source
001 Two Sum easy 0.441 c
002 Add Two Numbers medium 0.311 c
003 Longest Substring Without Repeating Characters medium 0.283 c
005 Longest Palindromic Substring medium 0.272 c
006 ZigZag Conversion medium 0.318 c
007 Reverse Integer easy 0.253 c
008 String to Integer (atoi) medium 0.146 c
009 Palindrome Number easy 0.433 c
011 Container With Most Water medium 0.445 c
012 Integer to Roman medium 0.509 c
013 Roman to Integer easy 0.523 c
014 Longest Common Prefix easy 0.335 c
015 3Sum medium 0.239 c
016 3Sum Closest medium 0.457 c
017 Letter Combinations of a Phone Number medium 0.415 c
019 Remove Nth Node From End of List medium 0.342 c
020 Valid Parentheses easy 0.365 c
021 Merge Two Sorted Lists easy 0.472 c
022 Generate Parentheses medium 0.548 c
023 Merge k Sorted Lists hard 0.344 c
024 Swap Nodes in Pairs medium 0.446 c
026 Remove Duplicates from Sorted Array easy 0.406 c
027 Remove Element easy 0.445 c
028 Implement strStr() easy 0.319 c
031 Next Permutation medium 0.304 c
032 Longest Valid Parentheses hard 0.254 c
033 Search in Rotated Sorted Array medium 0.328 c
034 Find First and Last Position of Element in Sorted Array medium 0.335 c
035 Search Insert Position easy 0.408 c
036 Valid Sudoku medium 0.430 c
037 Sudoku Solver hard 0.369 c
038 Count and Say easy 0.404 c
039 Combination Sum medium 0.484 c
040 Combination Sum II medium 0.415 c
041 First Missing Positive hard 0.288 c
042 Trapping Rain Water hard 0.431 c
043 Multiply Strings medium 0.306 c
046 Permutations medium 0.551 c
047 Permutations II medium 0.404 c
048 Rotate Image medium 0.484 c
049 Group Anagrams medium 0.467 c
050 Pow(x, n) medium 0.279 c
051 N-Queens hard 0.392 c
052 N-Queens II hard 0.519 c
053 Maximum Subarray easy 0.435 c
054 Spiral Matrix medium 0.304 c
055 Jump Game medium 0.318 c
056 Merge Intervals medium 0.356 c
058 Length of Last Word easy 0.322 c
059 Spiral Matrix II medium 0.465 c
060 Permutation Sequence medium 0.330 c
062 Unique Paths medium 0.475 c
063 Unique Paths II medium 0.334 c
064 Minimum Path Sum medium 0.468 c
065 Valid Number hard 0.139 c
066 Plus One easy 0.412 c
067 Add Binary easy 0.391 c
069 Sqrt(x) easy 0.313 c
070 Climbing Stairs easy 0.441 c
071 Simplify Path medium 0.287 c
073 Set Matrix Zeroes medium 0.397 c
074 Search a 2D Matrix medium 0.348 c
075 Sort Colors medium 0.421 c
076 Minimum Window Substring hard 0.307 c
077 Combinations medium 0.476 c
078 Subsets medium 0.527 c
079 Word Search medium 0.312 c
080 Remove Duplicates from Sorted Array II medium 0.403 c
081 Search in Rotated Sorted Array II medium 0.326 c
085 Maximal Rectangle hard 0.333 c
088 Merge Sorted Array easy 0.357 c
089 Gray Code medium 0.457 c
091 Decode Ways medium 0.223 c
093 Restore IP Addresses medium 0.314 c
100 Same Tree easy 0.500 c
118 Pascal's Triangle easy 0.459 c
119 Pascal's Triangle II easy 0.435 c
120 Triangle medium 0.393 c
121 Best Time to Buy and Sell Stock easy 0.472 c
122 Best Time to Buy and Sell Stock II easy 0.518 c
125 Valid Palindrome easy 0.310 c
130 Surrounded Regions medium 0.228 c
131 Palindrome Partitioning medium 0.408 c
134 Gas Station medium 0.337 c
136 Single Number easy 0.601 c
137 Single Number II medium 0.459 c
139 Word Break medium 0.352 c
140 Word Break II hard 0.272 c
150 Evaluate Reverse Polish Notation medium 0.321 c
151 Reverse Words in a String medium 0.167 c
152 Maximum Product Subarray medium 0.292 c
153 Find Minimum in Rotated Sorted Array medium 0.429 c
154 Find Minimum in Rotated Sorted Array II hard 0.393 c
165 Compare Version Numbers medium 0.235 c
166 Fraction to Recurring Decimal medium 0.194 c
167 Two Sum II - Input array is sorted easy 0.503 c
168 Excel Sheet Column Title easy 0.289 c
169 Majority Element easy 0.526 c
171 Excel Sheet Column Number easy 0.514 c
172 Factorial Trailing Zeroes easy 0.373 c
174 Dungeon Game hard 0.270 c
187 Repeated DNA Sequences medium 0.360 c
189 Rotate Array easy 0.300 c
190 Reverse Bits easy 0.313 c
191 Number of 1 Bits easy 0.431 c
198 House Robber easy 0.410 c
200 Number of Islands medium 0.414 c
201 Bitwise AND of Numbers Range medium 0.358 c
202 Happy Number easy 0.451 c
204 Count Primes easy 0.289 c
205 Isomorphic Strings easy 0.373 c
206 Reverse Linked List easy 0.546 c
209 Minimum Size Subarray Sum medium 0.348 c
212 Word Search II hard 0.286 c
213 House Robber II medium 0.352 c
214 Shortest Palindrome hard 0.275 c
215 Kth Largest Element in an Array medium 0.477 c
216 Combination Sum III medium 0.515 c
217 Contains Duplicate easy 0.519 c
219 Contains Duplicate II easy 0.352 c
220 Contains Duplicate III medium 0.197 c
221 Maximal Square medium 0.330 c
223 Rectangle Area medium 0.358 c
227 Basic Calculator II medium 0.334 c
229 Majority Element II medium 0.320 c
231 Power of Two easy 0.419 c
240 Search a 2D Matrix II medium 0.408 c
242 Valid Anagram easy 0.521 c
258 Add Digits easy 0.540 c
263 Ugly Number easy 0.405 c
268 Missing Number easy 0.483 c
274 H-Index medium 0.345 c
278 First Bad Version easy 0.299 c
279 Perfect Squares medium 0.419 c
282 Expression Add Operators hard 0.327 c
283 Move Zeroes easy 0.542 c
287 Find the Duplicate Number medium 0.495 c
289 Game of Life medium 0.453 c
292 Nim Game easy 0.556 c
299 Bulls and Cows medium 0.394 c
303 Range Sum Query - Immutable easy 0.379 c
313 Super Ugly Number medium 0.413 c
319 Bulb Switcher medium 0.439 c
326 Power of Three easy 0.416 c
338 Counting Bits medium 0.646 c
344 Reverse String easy 0.632 c
349 Intersection of Two Arrays easy 0.545 c
350 Intersection of Two Arrays II easy 0.477 c
371 Sum of Two Integers easy 0.509 c
377 Combination Sum IV medium 0.437 c
383 Ransom Note easy 0.498 c
387 First Unique Character in a String easy 0.500 c
389 Find the Difference easy 0.530 c
392 Is Subsequence medium 0.467 c
401 Binary Watch easy 0.453 c
409 Longest Palindrome easy 0.480 c
412 Fizz Buzz easy 0.595 c
414 Third Maximum Number easy 0.289 c
415 Add Strings easy 0.436 c
434 Number of Segments in a String easy 0.369 c
438 Find All Anagrams in a String easy 0.372 c
442 Find All Duplicates in an Array medium 0.608 c
443 String Compression easy 0.376 c
447 Number of Boomerangs easy 0.498 c
448 Find All Numbers Disappeared in an Array easy 0.533 c
451 Sort Characters By Frequency medium 0.560 c
452 Minimum Number of Arrows to Burst Balloons medium 0.463 c
453 Minimum Moves to Equal Array Elements easy 0.491 c
456 132 Pattern medium 0.273 c
459 Repeated Substring Pattern easy 0.398 c
461 Hamming Distance easy 0.703 c
462 Minimum Moves to Equal Array Elements II medium 0.523 c
463 Island Perimeter easy 0.609 c
473 Matchsticks to Square medium 0.358 c
474 Ones and Zeroes medium 0.397 c
475 Heaters easy 0.317 c
476 Number Complement easy 0.623 c
483 Smallest Good Base hard 0.341 c
485 Max Consecutive Ones easy 0.550 c
486 Predict the Winner medium 0.467 c
492 Construct the Rectangle easy 0.486 c
494 Target Sum medium 0.452 c
495 Teemo Attacking medium 0.522 c
496 Next Greater Element I easy 0.595 c
498 Diagonal Traverse medium 0.453 c
500 Keyboard Row easy 0.621 c
504 Base 7 easy 0.449 c
507 Perfect Number easy 0.342 c
520 Detect Capital easy 0.524 c
521 Longest Uncommon Subsequence I easy 0.563 c
530 Minimum Absolute Difference in BST easy 0.504 c
532 K-diff Pairs in an Array easy 0.298 c
535 Encode and Decode TinyURL medium 0.767 c
541 Reverse String II easy 0.454 c
542 01 Matrix medium 0.356 c
551 Student Attendance Record I easy 0.452 c
556 Next Greater Element III medium 0.299 c
557 Reverse Words in a String III easy 0.640 c
561 Array Partition I easy 0.689 c
566 Reshape the Matrix easy 0.588 c
575 Distribute Candies easy 0.596 c
598 Range Addition II easy 0.486 c
605 Can Place Flowers easy 0.308 c
617 Merge Two Binary Trees easy 0.701 c
628 Maximum Product of Three Numbers easy 0.459 c
633 Sum of Square Numbers easy 0.327 c
639 Decode Ways II hard 0.250 c
650 2 Keys Keyboard medium 0.465 c
657 Robot Return to Origin easy 0.714 c
661 Image Smoother easy 0.487 c
665 Non-decreasing Array easy 0.194 c
674 Longest Continuous Increasing Subsequence easy 0.442 c
679 24 Game hard 0.427 c
680 Valid Palindrome II easy 0.341 c
682 Baseball Game easy 0.609 c
688 Knight Probability in Chessboard medium 0.443 c
693 Binary Number with Alternating Bits easy 0.578 c
695 Max Area of Island medium 0.571 c
696 Count Binary Substrings easy 0.533 c
697 Degree of an Array easy 0.503 c
717 1-bit and 2-bit Characters easy 0.492 c
718 Maximum Length of Repeated Subarray medium 0.459 c
728 Self Dividing Numbers easy 0.700 c
733 Flood Fill easy 0.507 c
739 Daily Temperatures medium 0.599 c
709 To Lower Case easy 0.768 c
744 Find Smallest Letter Greater Than Target easy 0.440 c
746 Min Cost Climbing Stairs easy 0.471 c
747 Largest Number At Least Twice of Others easy 0.405 c
753 Cracking the Safe hard 0.461 c
754 Reach a Number easy 0.325 c
762 Prime Number of Set Bits in Binary Representation easy 0.591 c
763 Partition Labels medium 0.702 c
764 Largest Plus Sign medium 0.433 c
766 Toeplitz Matrix easy 0.617 c
771 Jewels and Stones easy 0.830 c
700 Search in a Binary Search Tree easy 0.680 c
701 Insert into a Binary Search Tree medium 0.757 c
704 Binary Search easy 0.475 c
777 Swap Adjacent in LR String medium 0.333 c
783 Minimum Distance Between BST Nodes easy 0.504 c
784 Letter Case Permutation easy 0.566 c
788 Rotated Digits easy 0.541 c
791 Custom Sort String medium 0.617 c
792 Number of Matching Subsequences medium 0.428 c
795 Number of Subarrays with Bounded Maximum medium 0.431 c
796 Rotate String easy 0.489 c
798 Smallest Rotation with Highest Score hard 0.401 c
804 Unique Morse Code Words easy 0.746 c
806 Number of Lines To Write String easy 0.629 c
807 Max Increase to Keep City Skyline medium 0.813 c
811 Subdomain Visit Count easy 0.652 c
812 Largest Triangle Area easy 0.558 c
821 Shortest Distance to a Character easy 0.633 c
824 Goat Latin easy 0.576 c
825 Friends Of Appropriate Ages medium 0.361 c
830 Positions of Large Groups easy 0.477 c
832 Flipping an Image easy 0.725 c
836 Rectangle Overlap easy 0.464 c
840 Magic Squares In Grid easy 0.354 c
844 Backspace String Compare easy 0.459 c
852 Peak Index in a Mountain Array easy 0.695 c
859 Buddy Strings easy 0.276 c
860 Lemonade Change easy 0.503 c
867 Transpose Matrix easy 0.639 c
876 Middle of the Linked List easy 0.640 c
880 Decoded String at Index medium 0.229 c
881 Boats to Save People medium 0.437 c
883 Projection Area of 3D Shapes easy 0.657 c
884 Uncommon Words from Two Sentences easy 0.607 c
888 Fair Candy Swap easy 0.566 c
892 Surface Area of 3D Shapes easy 0.558 c
896 Monotonic Array easy 0.551 c
899 Orderly Queue hard 0.471 c
905 Sort Array By Parity easy 0.725 c
908 Smallest Range I easy 0.644 c
917 Reverse Only Letters easy 0.560 c
922 Sort Array By Parity II easy 0.669 c
925 Long Pressed Name easy 0.443 c
929 Unique Email Addresses easy 0.714 c
934 Shortest Bridge medium 0.438 c
938 Range Sum of BST easy 0.795 c
941 Valid Mountain Array easy 0.353 c
942 DI String Match easy 0.700 c
944 Delete Columns to Make Sorted easy 0.693 c
949 Largest Time for Given Digits easy 0.339 c
953 Verifying an Alien Dictionary easy 0.556 c
957 Prison Cells After N Days medium 0.379 c
961 N-Repeated Element in Size 2N Array easy 0.725 c
962 Maximum Width Ramp medium 0.413 c
965 Univalued Binary Tree easy 0.669 c
969 Pancake Sorting medium 0.622 c
970 Powerful Integers easy 0.395 c
509 Fibonacci Number easy 0.668 c
973 K Closest Points to Origin medium 0.624 c
976 Largest Perimeter Triangle easy 0.571 c
977 Squares of a Sorted Array easy 0.721 c
978 Longest Turbulent Subarray medium 0.453 c
983 Minimum Cost For Tickets medium 0.572 c
984 String Without AAA or BBB medium 0.334 c
985 Sum of Even Numbers After Queries easy 0.639 c
986 Interval List Intersections medium 0.625 c
989 Add to Array-Form of Integer easy 0.445 c
991 Broken Calculator medium 0.399 c
994 Rotting Oranges easy 0.463 c
997 Find the Town Judge easy 0.489 c
999 Available Captures for Rook easy 0.663 c
1001 Grid Illumination hard 0.340 c
1002 Find Common Characters easy 0.659 c
1003 Check If Word Is Valid After Substitutions medium 0.518 c
1005 Maximize Sum Of Array After K Negations easy 0.494 c
1006 Clumsy Factorial medium 0.541 c
1007 Minimum Domino Rotations For Equal Row medium 0.475 c
1009 Complement of Base 10 Integer easy 0.588 c
1010 Pairs of Songs With Total Durations Divisible by 60 easy 0.454 c
1011 Capacity To Ship Packages Within D Days medium 0.527 c
1013 Partition Array Into Three Parts With Equal Sum easy 0.551 c
1014 Best Sightseeing Pair medium 0.482 c
1015 Smallest Integer Divisible by K medium 0.278 c
1016 Binary String With Substrings Representing 1 To N medium 0.621 c
1017 Convert to Base -2 medium 0.558 c
1018 Binary Prefix Divisible By 5 easy 0.464 c
1020 Number of Enclaves medium 0.549 c
1021 Remove Outermost Parentheses easy 0.767 c
1022 Sum of Root To Leaf Binary Numbers easy 0.530 c
1023 Camelcase Matching medium 0.568 c
1025 Divisor Game easy 0.626 c
1026 Maximum Difference Between Node and Ancestor medium 0.590 c
1030 Matrix Cells in Distance Order easy 0.663 c
1029 Two City Scheduling easy 0.537 c
1033 Moving Stones Until Consecutive easy 0.343 c
1034 Coloring A Border medium 0.423 c
1035 Uncrossed Lines medium 0.510 c
1038 Binary Search Tree to Greater Sum Tree medium 0.803 c
1037 Valid Boomerang easy 0.372 c
1041 Robot Bounded In Circle easy 0.419 c
1042 Flower Planting With No Adjacent easy 0.471 c
1046 Last Stone Weight easy 0.636 c
1047 Remove All Adjacent Duplicates In String easy 0.624 c
1048 Longest String Chain medium 0.461 c
1051 Height Checker easy 0.710 c
1052 Grumpy Bookstore Owner medium 0.506 c
1053 Previous Permutation With One Swap medium 0.430 c
1054 Distant Barcodes medium 0.365 c