├── .github └── workflows │ └── issue_comment.yml ├── .gitignore ├── 2021-07 ├── 2021-07-19 (day1) │ ├── A_GO │ │ ├── README.md │ │ └── solution.c++ │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ └── solution.py │ ├── Hello │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.rs │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ ├── solution_01.py │ │ └── solution_02.py │ ├── README.md │ ├── SeanK │ │ ├── README.md │ │ └── solution.py │ ├── SeptRabbit │ │ ├── README.md │ │ └── reverseInteger.js │ ├── White │ │ ├── README.md │ │ └── day1_reverse_integer.py │ └── huibizhang │ │ ├── README.md │ │ └── solution.js ├── 2021-07-20 (day2) │ ├── A_GO │ │ ├── README.md │ │ └── Solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.py │ │ ├── solution1_result.png │ │ ├── solution2.py │ │ └── solution2_result.png │ ├── Hello │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.rs │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── SeptRabbit │ │ ├── PalindromeNumber.js │ │ └── README.md │ ├── White │ │ ├── README.md │ │ └── day2_white_palindrome_number.py │ └── huibizhang │ │ ├── README.md │ │ ├── solution.js │ │ └── solution_optimization.js ├── 2021-07-21 (day3) │ ├── A_GO │ │ ├── README.md │ │ └── Solution.cpp │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.rs │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ └── README.md │ ├── README.md │ ├── SeptRabbit │ │ ├── LongPalindrome.js │ │ └── README.md │ └── White │ │ └── day3_longest_palindromic_substring.py ├── 2021-07-22 (day4) │ ├── A_GO │ │ ├── README.md │ │ ├── Solution1.cpp │ │ ├── solution1.png │ │ ├── solution2.cpp │ │ └── solution2.png │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── huibizhang │ │ ├── README.md │ │ └── solution.java │ ├── septRabbit │ │ ├── README.md │ │ └── ValidParentheses.js │ └── white │ │ ├── README.md │ │ └── day4_valid_parentheses.py ├── 2021-07-23 (day5) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution-1.js │ │ └── solution-2.js │ ├── README.md │ ├── White │ │ └── day5_search_insert-position.py │ └── septRabbit │ │ ├── README.md │ │ └── searchInsert.js ├── 2021-07-24 (day6) │ ├── A_Go │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── White │ │ ├── README.md │ │ └── day6_sliding_window.py │ └── septRabbit │ │ ├── README.md │ │ └── longestSubstring.js ├── 2021-07-25 (day7) │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ ├── solution.js │ │ └── solution2.js │ ├── README.md │ └── White │ │ ├── README.md │ │ └── day7_median_of_two_sorted_arrays.py ├── 2021-07-26 (day8) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ └── README.md ├── 2021-07-27 (day9) │ ├── A_GO │ │ ├── README.md │ │ └── solotion.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── soluction.js │ │ └── solution.py │ ├── README.md │ ├── White │ │ ├── README.md │ │ └── day9_singly_linked_list.py │ └── huibizhang │ │ ├── README.md │ │ └── solution.js ├── 2021-07-28 (day10) │ ├── A_GO │ │ ├── README.md │ │ └── solotion.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── White │ │ ├── README.md │ │ └── day10_int2roman.py │ └── septRabbit │ │ └── intToRoman.js ├── 2021-07-29 (day11) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── README.md │ └── septRabbit │ │ └── sameTree.js ├── 2021-07-30 (day12) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ ├── README.md │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ └── README.md └── 2021-07-31 (day13) │ ├── A_GO │ ├── README.md │ └── solution.cpp │ ├── CXPhoenix │ ├── README.md │ ├── solution.png │ └── solution.py │ ├── Hello │ └── solution.js │ ├── Husky │ ├── README.md │ ├── solution_BFS.py │ └── solution_DP.py │ ├── Kevin │ ├── README.md │ └── solution.js │ └── README.md ├── 2021-08 ├── 2021-08-01 (day14) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution-TimeLimitedError.png │ │ ├── solution-TimeLimitedError.py │ │ ├── solution.png │ │ └── solution.py │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.py │ │ └── solution_2.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ └── README.md ├── 2021-08-02 (day15) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ └── White │ │ ├── README.md │ │ └── day15_merge_two_sorted_lists.py ├── 2021-08-03 (day16) │ ├── A_GO │ │ ├── 111298.jpg │ │ ├── README.md │ │ └── Solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution.js │ │ ├── solution.png │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ └── White │ │ ├── README.md │ │ └── day16_rotate_image.py ├── 2021-08-04 (day17) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ ├── solution2.py │ │ ├── solution3.png │ │ └── solution3.py │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── README.md │ └── White │ │ ├── README.md │ │ └── day17_add_two_numbers.py ├── 2021-08-05 (day18) │ ├── A_GO │ │ ├── README.md │ │ ├── solution1.cpp │ │ └── solution2.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ ├── solution2.py │ │ ├── solution3.png │ │ ├── solution3.py │ │ ├── solution4.png │ │ └── solution4.py │ ├── Hello │ │ ├── solution.js │ │ └── solution.rs │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Randolph │ │ ├── README.md │ │ └── solution.py │ └── White │ │ ├── README.md │ │ └── day18_two_sum.py ├── 2021-08-06 (day19) │ ├── A_GO │ │ ├── 111962.jpg │ │ ├── README.md │ │ └── solution.cpp │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ └── solution1.py │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── merge_sort.png │ │ └── solution.py │ ├── Kevin │ │ └── README.md │ ├── README.md │ └── Tim │ │ ├── README.md │ │ └── solution.py ├── 2021-08-07 (day20) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ └── solution1.py │ ├── Hello │ │ ├── solution.js │ │ └── solution2.js │ ├── Husky │ │ ├── solution_1.py │ │ └── solution_2.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Randolph │ │ ├── README.md │ │ └── solution.py │ ├── Tim │ │ ├── README.md │ │ └── solution.py │ └── White │ │ ├── README.md │ │ └── first_unique_char.py ├── 2021-08-08 (day21) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Hello │ │ ├── generator.js │ │ └── recursion.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── README.md │ └── Tim │ │ ├── README.md │ │ ├── fig │ │ └── pic1.png │ │ └── solution.py ├── 2021-08-09 (day22) │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ └── solution1.py │ ├── Fanli │ │ └── 21. Merge Two Sorted Lists.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ └── White │ │ ├── README.md │ │ └── sort_list.py ├── 2021-08-10 (day23) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── Fanli │ │ └── 98. Validate Binary Search Tree.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ └── White │ │ ├── README.md │ │ └── validate_binary_search_tree.py ├── 2021-08-11 (day24) │ ├── A_GO │ │ ├── README.md │ │ └── solution.js │ ├── Fanli │ │ └── 101. Symmetric Tree.js │ ├── Hello │ │ ├── BFS.js │ │ └── DFS.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution.js │ │ └── solution_2.js │ ├── README.md │ └── Tim │ │ ├── README.md │ │ ├── fig │ │ └── fig1.png │ │ └── solution.py ├── 2021-08-12 (day25) │ ├── A_GO │ │ ├── README.md │ │ └── solution.cpp │ ├── Fanli │ │ └── 49. Group Anagrams.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution.js │ │ └── solution_2.js │ ├── README.md │ └── Tim │ │ ├── README.md │ │ ├── fig │ │ └── fig1.png │ │ └── solution.py ├── 2021-08-13 (day26) │ ├── AGO │ │ ├── README.md │ │ └── solution.cpp │ ├── Fanli │ │ └── 141. Linked List Cycle.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution_1.py │ │ └── solution_2.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── White │ │ ├── README.md │ │ └── linked_list_cycle.py │ └── haha │ │ ├── README.md │ │ └── solution.javascript ├── 2021-08-14 (day27) │ ├── README.md │ └── Tim │ │ ├── README.md │ │ └── solution.py ├── 2021-08-15 (day28) │ ├── AGO │ │ ├── README.md │ │ └── solution.cpp │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Chocolate │ │ ├── README.md │ │ └── solution.py │ ├── Fanli │ │ └── 26. Remove Duplicates from Sorted Array.js │ ├── Hello │ │ ├── splice.js │ │ └── two-point.js │ ├── Husky │ │ ├── README.md │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution.js │ │ └── solution_2.js │ ├── README.md │ ├── Randolph │ │ ├── README.md │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── remove_duplicates_from_sorted_array.py │ ├── haha │ │ ├── README.md │ │ └── solution-fix.js │ └── huibizhang │ │ └── solution.js ├── 2021-08-16 (day29) │ ├── AGO │ │ ├── README.md │ │ └── solution.cpp │ ├── Fanli │ │ └── 94. Binary Tree Inorder Traversal.js │ ├── Hello │ │ ├── iterative.js │ │ └── recursive.js │ ├── Husky │ │ ├── README.md │ │ ├── solution_1.py │ │ └── solution_2.py │ ├── README.md │ └── White │ │ ├── README.md │ │ └── binary_tree_inorder_traversal.py ├── 2021-08-17 (day30) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Fanli │ │ └── 326. Power of Three.js │ ├── Hello │ │ ├── iteration.js │ │ ├── math.js │ │ └── recursion.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── power_of_three.py │ └── septRabbit │ │ └── isPowerOfThree.js ├── 2021-08-18 (day31) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── XOR-display.png │ │ ├── XOR-solution.gif │ │ ├── solution1.png │ │ ├── solution1.py │ │ ├── solution2.png │ │ └── solution2.py │ ├── Fanli │ │ └── 136. Single Number.js │ ├── Hello │ │ ├── bitwise.js │ │ ├── solution.js │ │ └── sum.js │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── single_number.py │ ├── haha │ │ ├── README.md │ │ └── solution.js │ ├── huibizhang │ │ ├── solution1_map.js │ │ ├── solution2_object.js │ │ └── solution3_string-appear-count.js │ └── husky │ │ ├── README.md │ │ └── solution.py ├── 2021-08-19 (day32) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Chocolate │ │ ├── README.md │ │ └── solution.py │ ├── Fanli │ │ └── 268. Missing Number.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── missing_number.py │ ├── haha │ │ ├── README.md │ │ └── solution.js │ └── huibizhang │ │ ├── solution_index-not-exist.js │ │ ├── solution_like-math.js │ │ ├── solution_number-sort.js │ │ └── solution_object-sort.js ├── 2021-08-20 (day33) │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Fanli │ │ └── 287. Find the Duplicate Number.js │ ├── Hello │ │ ├── floyds_cycle.js │ │ └── sort.js │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ └── White │ │ ├── README.md │ │ └── find_the_duplicate_number.py ├── 2021-08-21 (day34) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Fanli │ │ └── 215. Kth Largest Element in an Array.js │ ├── Hello │ │ └── solution.js │ ├── README.md │ ├── White │ │ ├── Kth_largest_element_in_an_array.py │ │ └── README.md │ └── huibizhang │ │ ├── solution_replace-max.js │ │ └── solution_sorted.js ├── 2021-08-22 (day35) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── CXPhoenix │ │ ├── README.md │ │ ├── solution.png │ │ └── solution.py │ ├── Fanli │ │ └── 997. Find the Town Judge.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution-2.js │ │ └── solution.js │ ├── README.md │ └── Tim │ │ ├── README.md │ │ ├── fig │ │ └── fig1.png │ │ └── solution.py ├── 2021-08-23 (day36) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Fanli │ │ └── 121. Best Time to Buy and Sell Stock.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── README.md │ │ ├── solution_1.py │ │ └── solution_2.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-08-24 (day37) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-08-25 (day38) │ ├── Hello │ │ └── solution.js │ └── README.md ├── 2021-08-26 (day39) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Hsuky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── climbing_stairs.py │ └── haha │ │ ├── README.md │ │ ├── solution.js │ │ └── 公式解.png ├── 2021-08-27 (day40) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── dp.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.ts │ ├── README.md │ └── Tim │ │ ├── README.md │ │ ├── fig │ │ └── fig1.png │ │ └── solution.py ├── 2021-08-28 (day41) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ ├── solution_1.py │ │ └── solution_2.py │ ├── README.md │ └── Tim │ │ └── solution.py ├── 2021-08-29 (day42) │ ├── AGO │ │ └── BinaryHeap.ts │ └── README.md ├── 2021-08-30 (day43) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.ts │ ├── README.md │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── caaaaat │ │ ├── README.md │ │ └── solution.java │ └── haha │ │ ├── README.md │ │ └── solution.js └── 2021-08-31 (day44) │ ├── AGO │ ├── README.md │ └── solution.ts │ ├── Hello │ └── solution.js │ ├── Husky │ └── solution.py │ ├── README.md │ ├── Ray │ └── solution.js │ ├── caaaaat │ └── solution.java │ └── haha │ ├── README.md │ └── solution.js ├── 2021-09 ├── 2021-09-01 (day45) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── caaaaat │ │ └── solution.java ├── 2021-09-02 (day46) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── Erica │ │ ├── README.md │ │ └── solution.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── solution.js │ │ └── solution2.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── valid_anagram.py │ ├── caaaaat │ │ └── solution.java │ └── haha │ │ ├── README.md │ │ ├── ascii-solution.js │ │ └── solution.js ├── 2021-09-03 (day47) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── stack.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── images │ │ │ └── solution.jpg │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Shaun │ │ ├── README.md │ │ └── Solution.java │ └── caaaaat │ │ └── solution.java ├── 2021-09-04 (day48) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── caaaaat │ │ └── solution.java │ └── kevin │ │ ├── README.md │ │ └── solution.ts ├── 2021-09-05 (day49) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── MiMeow │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Shaun │ │ └── Solution.java │ └── kevin │ │ ├── README.md │ │ └── solution.js ├── 2021-09-06 (day50) │ ├── AGO │ │ └── solution.ts │ ├── Alpha │ │ ├── README.md │ │ └── solution.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Shaun │ │ └── Solution.java │ ├── White │ │ ├── README.md │ │ └── majority_element.py │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-09-07 (day51) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ ├── solution.js │ │ └── solution2.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Shaun │ │ ├── README.md │ │ └── Solution.java │ └── White │ │ ├── README.md │ │ └── intersection_of_2_arrays.py ├── 2021-09-08 (day52) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ └── Ray │ │ └── solution.js ├── 2021-09-09 (day53) │ ├── AGO │ │ ├── solution1.ts │ │ └── solution2.ts │ ├── Erica │ │ ├── README.md │ │ └── solution.js │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── MiMeow │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── plus_one.py │ ├── haha │ │ ├── README.md │ │ └── solution.js │ └── kevin │ │ ├── README.md │ │ └── solution.ts ├── 2021-09-10 (day54) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Hsuky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── MiMeow │ │ └── solution.py │ ├── README.md │ └── Ray │ │ └── solution.js ├── 2021-09-11 (day55) │ ├── AGO │ │ ├── READM.md │ │ └── solutioon.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── MiMeow │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-09-12 (day56) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ └── Ray │ │ └── solution.js ├── 2021-09-13 (day57) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── eat_lunch.py │ └── caaaaat │ │ └── solution.java ├── 2021-09-14 (day58) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ ├── README.md │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── palindrome_linked_list..py │ └── caaaaat │ │ └── solution.java ├── 2021-09-15 (day59) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ └── solution.js │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── simplify_path.py │ ├── aug │ │ └── solution.js │ └── caaaaat │ │ └── solution.java ├── 2021-09-16 (day60) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── implement_str.py │ ├── aug │ │ └── solution.js │ └── caaaaat │ │ └── solution.java ├── 2021-09-17 (day61) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── excel_sheet_column_title.py │ ├── aug │ │ └── solution.js │ └── caaaaat │ │ └── solution.java ├── 2021-09-18 (day62) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── aug │ │ └── solution.js │ └── caaaaat │ │ └── solution.java ├── 2021-09-19 (day63) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ └── aug │ │ └── solution.js ├── 2021-09-20 (day64) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ └── aug │ │ └── solution.js ├── 2021-09-22 (day65) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── aug │ │ └── solution.js │ ├── haha │ │ └── solution.js │ └── pencil │ │ └── solution.js ├── 2021-09-23 (day66) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── Kevin │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── is_subsequence.py │ ├── aug │ │ └── solution.js │ └── pencil │ │ └── solution.js ├── 2021-09-24 (day67) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Sid │ │ ├── README.md │ │ └── solution.js │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── aug │ │ └── solution.js │ └── kevin │ │ ├── README.md │ │ └── solution.js ├── 2021-09-25 (day68) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ └── aug │ │ └── solution.js ├── 2021-09-26 (day69) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── aug │ │ └── solution.js ├── 2021-09-27 (day70) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── aug │ │ └── solution.js ├── 2021-09-28 (day71) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── array_partition1.py │ └── aug │ │ └── solution.js ├── 2021-09-29 (day72) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── permute.py │ └── aug │ │ └── solution.js └── 2021-09-30 (day73) │ ├── AGO │ ├── README.md │ └── solution.ts │ ├── Hello │ └── solution.js │ ├── Husky │ └── solution.py │ ├── README.md │ ├── Ray │ └── solution.js │ ├── Tim │ ├── README.md │ ├── fig │ │ └── fig1.png │ ├── solution1.py │ └── solution2.py │ ├── White │ ├── README.md │ └── letter_case_permute.py │ └── aug │ ├── runtime.png │ ├── runtime2.png │ └── solution.js ├── 2021-10 ├── 2021-10-01 (day74) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── allPathsSourceTarget.py │ └── aug │ │ └── solution.js ├── 2021-10-02 (day75) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── numTilePossibilities.py │ └── aug │ │ └── solution.js ├── 2021-10-03 (day76) │ ├── Hello │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ └── aug │ │ ├── runtime.png │ │ ├── runtime2.png │ │ └── solution.js ├── 2021-10-04 (day77) │ ├── AGO │ │ └── solution.ts │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── White │ │ ├── README.md │ │ └── getHappyString.py │ └── aug │ │ ├── runtime.png │ │ ├── runtime2.png │ │ ├── solution.js │ │ └── solution2.js ├── 2021-10-05 (day78) │ ├── AGO │ │ └── solition.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── MiMeow │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── findContentChildren.py │ └── aug │ │ └── solution.js ├── 2021-10-06 (day79) │ ├── AGO │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── canPlaceFlowers.py │ ├── aug │ │ └── solution.js │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-10-07 (day80) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── longestPalindrome.py │ ├── aug │ │ └── solution.js │ └── solution.js ├── 2021-10-08 (day81) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── balancedStringSplit.py │ ├── aug │ │ └── solution.js │ └── haha │ │ ├── README.md │ │ └── solution.js ├── 2021-10-09 (day82) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ └── aug │ │ └── solution.js ├── 2021-10-10 (day83) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── largestNumber.py │ └── aug │ │ └── solution.js ├── 2021-10-12 (day84) │ ├── AGO │ │ ├── README.md │ │ └── solution.ts │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ ├── README.md │ │ ├── fig │ │ │ └── fig1.png │ │ └── solution.py │ ├── White │ │ ├── README.md │ │ └── canThreePartsEqualSum.py │ └── aug │ │ └── solution.js ├── 2021-10-13 (day85) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── aug │ │ ├── solution.js │ │ └── solution2.js ├── 2021-10-14 (day86) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── aug │ │ └── solution.js ├── 2021-10-16 (day87) │ ├── Hello │ │ └── solution.js │ ├── Husky │ │ └── solution.py │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── Tim │ │ └── solution.py │ └── aug │ │ └── solution.js ├── 2021-10-18 (day88) │ ├── Hello │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ └── aug │ │ └── solution.js ├── 2021-10-19 (day89) │ ├── Hello │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.js │ ├── ago │ │ └── solution.ts │ └── aug │ │ ├── solution.js │ │ ├── solution2.js │ │ └── solution3.js ├── 2021-10-20 (day90) │ ├── README.md │ ├── Ray │ │ └── solution.cpp │ └── aug │ │ ├── solution.js │ │ └── solution2.js ├── 2021-10-23 (day91) │ ├── README.md │ ├── Ray │ │ └── solution.cpp │ └── aug │ │ └── solution.js ├── 2021-10-25 (day92) │ ├── Hello │ │ └── solution.js │ ├── README.md │ ├── Ray │ │ └── solution.cpp │ └── aug │ │ ├── solution.js │ │ └── solution2.js ├── 2021-10-26 (day93) │ ├── AGO │ │ └── solution.ts │ ├── README.md │ ├── Ray │ │ └── solution.cpp │ └── aug │ │ └── solution.js ├── 2021-10-28 (day94) │ ├── AGO │ │ └── solution.ts │ ├── README.md │ └── aug │ │ └── solution.js └── 2021-10-29 (day95) │ ├── README.md │ └── aug │ └── solution.js ├── 2021-11 ├── 2021-11-01 (day96) │ ├── README.md │ └── aug │ │ ├── solution.js │ │ └── solution2.js └── 2021-11-02 (day97) │ ├── README.md │ ├── Ray │ └── solution.js │ └── aug │ └── solution.js ├── 2022-01 ├── 2022-01-12 (day98) │ ├── Husky │ │ └── solution.py │ ├── README.md │ └── kirby │ │ └── solution.js ├── 2022-01-14 (day99) │ ├── README.md │ └── solution.py └── 2022-01-17 (day100) │ ├── Husky │ └── solution.py │ ├── README.md │ └── kevin │ ├── README.md │ └── solution.js ├── DataStructures ├── BinaryTree │ └── kirby │ │ ├── balanced-binary-tree │ │ └── solution.js │ │ └── sum-root-to-leaf-numbers │ │ └── solution.js ├── HashTable │ ├── alpha │ │ ├── contains-duplicate │ │ │ ├── README.md │ │ │ └── Solution.js │ │ └── word-break │ │ │ ├── README.md │ │ │ └── Solution.js │ ├── casper │ │ ├── 139.Word-Break │ │ │ ├── README.md │ │ │ └── main.go │ │ └── 217.Contains-Duplicate │ │ │ ├── README.md │ │ │ └── main.go │ ├── kirby │ │ ├── contains-duplicate │ │ │ └── hashtable.js │ │ └── word-break │ │ │ └── solution.js │ └── pencil │ │ ├── 139.WordBreak │ │ ├── README.md │ │ └── solution.js │ │ └── 217.ContainsDuplicate │ │ ├── README.md │ │ └── solution.js ├── LinkedList │ ├── READMD.md │ ├── RayJs │ │ ├── design-browser-history │ │ │ └── solution.cpp │ │ └── middle-of-the-linked-list │ │ │ └── solution.cpp │ ├── ago │ │ ├── 1472.design-browser-history │ │ │ ├── README.md │ │ │ └── solution.go │ │ └── 876.middle-of-the-linked-list │ │ │ ├── README.md │ │ │ └── solution.go │ ├── alpha │ │ ├── design browser history │ │ │ ├── README.md │ │ │ └── Solution.js │ │ └── middle-of-the-linked-list │ │ │ ├── README.md │ │ │ ├── Solution1.js │ │ │ └── Solution2.js │ ├── casper │ │ ├── 1472.design-browser-history │ │ │ ├── README.md │ │ │ └── main.go │ │ └── 876.middle-of-the-linked-list │ │ │ ├── README.md │ │ │ └── main.go │ ├── kirby │ │ ├── design-browser-history │ │ │ ├── README.md │ │ │ ├── solution.c │ │ │ └── solution.js │ │ └── middle-of-the-linked-list │ │ │ ├── README.md │ │ │ ├── solution.c │ │ │ ├── solution.js │ │ │ └── solution.rs │ └── recoil │ │ └── 1472.design-browser-history │ │ ├── README.md │ │ └── solution.js ├── Queue │ ├── ago │ │ ├── design-circular-queue │ │ │ └── solution.go │ │ └── time-needed-to-buy-tickets │ │ │ └── solution.go │ └── kirby │ │ ├── design-circular-queue │ │ └── array-based.js │ │ ├── implement-queue │ │ ├── array-based.js │ │ └── pointer-based.js │ │ └── time-needed-to-buy-tickets │ │ └── solution.c ├── Stack │ ├── READMD.md │ ├── Ray │ │ ├── Daily-Temperatures │ │ │ └── solution.cpp │ │ └── Maximum-Nesting-Depth-of-the-Parentheses │ │ │ ├── stackSolution.cpp │ │ │ └── woStackSolution.cpp │ ├── ago │ │ ├── daily-temperatures │ │ │ ├── README.md │ │ │ └── solution.go │ │ └── maximum-nesting-depth-of-the-parentheses │ │ │ ├── README.md │ │ │ └── solution.go │ ├── alpha │ │ ├── daily-temperatures │ │ │ ├── README.md │ │ │ └── solution.js │ │ └── maximum-nesting-depth-of-the-parentheses │ │ │ ├── README.md │ │ │ └── solution.js │ ├── casper │ │ ├── 1614.Maximum-Nesting-Depth-of-the-Parentheses │ │ │ ├── README.md │ │ │ └── main.go │ │ └── 739.Daily-Temperatures │ │ │ ├── README.md │ │ │ └── main.go │ └── kirby │ │ ├── daily-temperatures │ │ ├── README.md │ │ ├── solution.c │ │ ├── solution.js │ │ └── solution.rs │ │ └── maximum-nesting-depth-of-the-parentheses │ │ ├── README.md │ │ ├── solution.c │ │ ├── solution.ex │ │ ├── solution.js │ │ ├── solution.py │ │ └── solution.rs └── Tree │ ├── ago │ ├── 427. Construct Quad Tree │ │ ├── README.md │ │ └── solution.go │ └── 559. Maximum Depth of N-ary Tree │ │ ├── README.md │ │ └── solution.go │ ├── alpha │ └── maximum-depth-of-n-ary-tree │ │ ├── README.md │ │ └── Solution.js │ └── kirby │ ├── construct-quad-tree │ └── solution.js │ └── maximum-depth-of-n-ary-tree │ └── solution.js ├── README.md ├── problem_list.log └── script ├── COVER_README.template ├── README.template ├── createREADME.py └── requirements.txt /2021-07/2021-07-19 (day1)/CXPhoenix/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | ```python 4 | class Solution: 5 | def reverse(self, x: int) -> int: 6 | rx = int(''.join(list(str(x))[::-1]) if x >= 0 else ''.join([list(str(x))[0], *list(str(x))[1:][::-1]])) 7 | return 0 if (rx >= 2**31 or rx < -2**31) else rx 8 | ``` 9 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/CXPhoenix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | rx = int(''.join(list(str(x))[::-1]) if x >= 0 else ''.join([list(str(x))[0], *list(str(x))[1:][::-1]])) 4 | return 0 if (rx >= 2**31 or rx < -2**31) else rx -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | var reverse = function (x) { 2 | const scalar = Number(String(Math.abs(x)).split("").reverse().join("")); 3 | 4 | if (scalar > 2 ** 31) return 0; 5 | 6 | return Math.sign(x) * scalar; 7 | }; 8 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/Husky/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {number} 4 | */ 5 | var reverse = function (x) { 6 | let MAX = Math.pow(2, 31); 7 | if (x === 0) { 8 | return 0; 9 | } 10 | 11 | let ans = Math.abs(x) 12 | .toString() 13 | .split("") 14 | .map((_, i, x_) => x_[x_.length - 1 - i]) 15 | .join(""); 16 | 17 | ans = x > 0 ? ans - 0 : 0 - ans; 18 | 19 | return ans >= -MAX && ans < MAX ? ans : 0; 20 | }; 21 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/Husky/solution_01.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | max_value = 2**31 4 | 5 | reversed_str = str(x)[::-1] 6 | try: 7 | reversed_num = int(reversed_str) 8 | except: 9 | reversed_num = -int(reversed_str[:-1]) 10 | 11 | return reversed_num if -max_value <= reversed_num <= max_value - 1 else 0 12 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/Husky/solution_02.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | max_value = 2**31 4 | sign = x > 0 5 | x = abs(x) 6 | y = 0 7 | 8 | while(x != 0): 9 | y = y*10 + x % 10 10 | x = x//10 11 | 12 | if y < -max_value or y >= max_value: 13 | return 0 14 | 15 | return y if sign else -y 16 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/SeanK/README.md: -------------------------------------------------------------------------------- 1 | # Check input First 2 | ```python 3 | # use Python slice notation 4 | if x > 0: 5 | res = int(str(x)[::-1]) 6 | else: 7 | res = -1 * int(str(abs(x))[::-1]) 8 | ``` 9 | # Check output isn't overflow 10 | ```python 11 | if res > 2**31 or res < -2**31: 12 | res = 0 13 | ``` 14 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/SeanK/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | if x > 0: 4 | res = int(str(x)[::-1]) 5 | else: 6 | res = -1 * int(str(abs(x))[::-1]) 7 | if res > 2**31 or res < -2**31: 8 | res = 0 9 | return res -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/SeptRabbit/README.md: -------------------------------------------------------------------------------- 1 | 1. Convert int to string 2 | 3 | 2. Splice each character o the string, and add to new array from the last character and join them to be a new string (reverse the string) 4 | 5 | 3. Check if the reverse string is outside of the sign range. If yes, return zero 6 | -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/White/README.md: -------------------------------------------------------------------------------- 1 | 1. 判斷是正負數,負數的話跳過負號取後面的字元 2 | 3 | 2. 字元反轉,再轉回數字 4 | 5 | 3. 判斷是否在 -2**31 ~ 2**31 之間,不是的話則傳回 0 -------------------------------------------------------------------------------- /2021-07/2021-07-19 (day1)/White/day1_reverse_integer.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | if x >= 0: 4 | answer = int(''.join(reversed(str(x)))) 5 | else: 6 | answer = int('-{}'.format(int(''.join(reversed(str(x)[1:]))))) 7 | 8 | test = lambda y : y if (-2**31 < y < 2**31-1) else 0 9 | return test(answer) -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | # solution 2 | 3 | **first judge if x is not positive or 0, it can't be true** 4 | 5 | **second change number to string and use for loop to renew in to an array, then use join to be a reversed string** 6 | 7 | **third change string to a number then judge if less than positive range will be true, else will be false** -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | x = str(x) 4 | for i in range(len(x)//2): 5 | if x[i] != x[len(x)-i-1]: 6 | break 7 | else: 8 | return True 9 | return False -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/CXPhoenix/solution1_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-20 (day2)/CXPhoenix/solution1_result.png -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | return True if str(x) == str(x)[::-1] else False -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/CXPhoenix/solution2_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-20 (day2)/CXPhoenix/solution2_result.png -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | Reversing an integer and check equivalent 4 | 5 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {boolean} 4 | */ 5 | function isPalindrome(x) { 6 | return String(x) === Array.from(String(x)).reverse().join(""); 7 | } 8 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Hello/solution.rs: -------------------------------------------------------------------------------- 1 | fn is_palindrome(x: i32) -> bool { 2 | let rev = x.to_string(); 3 | 4 | rev.chars().rev().eq(rev.chars()) 5 | } 6 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Husky/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {boolean} 4 | */ 5 | var isPalindrome = function (x) { 6 | const MAX = 2 ** 31; 7 | 8 | if (x < 0 || x > MAX - 1) { 9 | return false; 10 | } 11 | 12 | const xStr = x.toString(); 13 | return xStr 14 | .split("") 15 | .slice(0, parseInt(xStr.length / 2)) 16 | .every((v, i) => v === xStr[xStr.length - 1 - i]); 17 | }; 18 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | if x < 0 or x > 2 ** 31 - 1: 4 | return False 5 | 6 | x_str = str(x) 7 | return x_str == x_str[::-1] 8 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {boolean} 4 | */ 5 | var isPalindrome = function (x) { 6 | if (x < 0) return false; 7 | 8 | const reverse = x.toString().split("").reverse(); 9 | 10 | if (Number(reverse.join("")) > 2 ** 31 - 1) return false; 11 | 12 | const origin = x.toString().split(""); 13 | 14 | return origin.find((y, i, _x) => _x[i] !== reverse[i]) === undefined 15 | ? true 16 | : false; 17 | }; 18 | -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 回文的特徵是左右對稱。 3 | 2. 先排除負數及單一字元的狀況:負數一定不是回文,單一字元一定是回文。 4 | 3. 把int轉成str後切對半,注意奇數長度與偶數長度切的位置不同。 5 | 4. 切好後再取左半部與反轉後的右半部做比較。 6 | 7 | 8 | # leecode 提交結果 9 | Runtime: 52 ms, faster than 90.29% of Python3 online submissions for Palindrome Number. 10 | Memory Usage: 14.1 MB, less than 76.80% of Python3 online submissions for Palindrome Number. -------------------------------------------------------------------------------- /2021-07/2021-07-20 (day2)/huibizhang/solution_optimization.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {boolean} 4 | */ 5 | var isPalindrome = function(x) { 6 | if(x<0 || x > 2**31 - 1) { 7 | return false 8 | } 9 | 10 | let num = x 11 | let delta = 0 12 | while(num>0){ 13 | delta = delta*10 + num%10 14 | num = Math.floor(num/10) 15 | } 16 | 17 | return x===delta 18 | }; -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-21 (day3)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-21 (day3)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | Expand around from center 4 | -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/Husky/README.md: -------------------------------------------------------------------------------- 1 | ### python 2 | 3 | 1. 從左邊逐一字元取出檢查 4 | 2. 從右邊挑選相同項目 5 | 3. 檢查是否迴文 6 | 4. 替換最大 7 | 5. 修剪剩餘數量小於最長回文條件 8 | 9 | 10 | ##### 未實現修剪法 11 | 1. 採用等於當下最長迴文長度進行左側搜尋,應可大量修剪搜尋次數 -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/SeptRabbit/README.md: -------------------------------------------------------------------------------- 1 | 1. Make sure s meets the constraints 2 | 2. Find the all string combinations by using 2 for loops 3 | If the combination is palindrome, add in strList 4 | If no combination is palindrome, return 0 5 | 3. Find the longest string in strList 6 | -------------------------------------------------------------------------------- /2021-07/2021-07-21 (day3)/White/day3_longest_palindromic_substring.py: -------------------------------------------------------------------------------- 1 | # 純暴力法找出所有可能字串 再判斷是否回文,結果 Time Limit Exceeded 2 | class Solution: 3 | def longestPalindrome(self, s: str) -> str: 4 | answer = '' 5 | for i in range(len(s)): 6 | for j in range(len(s)-i+1): 7 | x = s[i:i+j] 8 | if str(x) == ''.join(reversed(str(x))): 9 | if len(x) > len(answer): 10 | answer = x 11 | return answer -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/A_GO/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-22 (day4)/A_GO/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/A_GO/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-22 (day4)/A_GO/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **use stack,and switch to judge case** -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-22 (day4)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-22 (day4)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | stack -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/Husky/README.md: -------------------------------------------------------------------------------- 1 | ### stack 2 | 3 | 1. if is '([{' add to stack 4 | 2. check stack content, if is empty return false 5 | 3. pop stack item if was pairs continue else return flase 6 | 4. final check stack length 7 | -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/septRabbit/README.md: -------------------------------------------------------------------------------- 1 | 1. string length has to be even to have match. 2 | 2. loop from s[0], if the element is the left half, push it to a new array 3 | 3. then look for the next element, if s[i+1] is the right half, then check if the last element in array (arr[arr.length-1]) is the left half. If yes, remove it from array using pop() 4 | 4. if all have match, array should be empty and return true 5 | -------------------------------------------------------------------------------- /2021-07/2021-07-22 (day4)/white/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 正確答案必須是偶數,才有可能兩兩相對。 3 | 2. 原本想用搜尋的方式,比對左右括號是否成對,阿狗提示stack後,突然發現超好用。 4 | 3. 把左右括號用dict儲存,左括號為key,右括號為value,方便比較。 5 | 6 | 用了一個迴圈,時間複雜度:O(n) -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **use binary search and while loop to judge the number's index** -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-23 (day5)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | l = 0 4 | r = len(nums)-1 5 | while l <= r: 6 | mid = (r+l)//2 7 | if target > nums[mid]: 8 | l = mid +1 9 | else: 10 | r = mid - 1 11 | return l 12 | -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-23 (day5)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/Husky/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} target 4 | * @return {number} 5 | */ 6 | var searchInsert = function (nums, target) { 7 | let searchIndex = nums.indexOf(target) 8 | if (searchIndex > -1) { 9 | return searchIndex 10 | } else { 11 | nums.push(target) 12 | nums.sort((a, b) => a - b) 13 | return nums.indexOf(target) 14 | } 15 | }; -------------------------------------------------------------------------------- /2021-07/2021-07-23 (day5)/septRabbit/README.md: -------------------------------------------------------------------------------- 1 | 1. Find the middle of the nums array. 2 | 2. if target is smaller than nums[0], insert position should be 0 3 | if target is greater than nums[nums.length-1], insert position should be nums.length 4 | 3. Loop when middle of nums is not target, check if target > nums[mid], set new left to mid + 1 and only look for target in the half. 5 | 4. If target is not found, if insert the target in nums, then the target index should be left 6 | -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **無法成功去找出重複的片段** -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-24 (day6)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLongestSubstring(self, s: str) -> int: 3 | start = 0 4 | maxLen = 0 5 | for i in range(len(s)): 6 | try: 7 | start = s.index(s[i], start,i)+1 8 | except: 9 | if maxLen < i - start + 1: 10 | maxLen = i - start + 1 11 | 12 | return maxLen 13 | -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-24 (day6)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | 4 | -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. create temp string 2 | 2. if: next in temp string -> slice from duplicate and check longest 3 | 3. else: add substring to temp string -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/White/day6_sliding_window.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLongestSubstring(self, s: str) -> int: 3 | left, right, max_length = 0, 0, 0 4 | 5 | while right < len(s): 6 | while s[right] in s[left:right]: 7 | left = left + 1 8 | 9 | right = right + 1 10 | max_length = max(max_length, right - left) 11 | 12 | return max_length -------------------------------------------------------------------------------- /2021-07/2021-07-24 (day6)/septRabbit/README.md: -------------------------------------------------------------------------------- 1 | 1. We want to find the non-repeat char. So, first, check the string from the first char. 2 | 2. If it doesn't exist, then add it to the string array. 3 | 3. If it exists, remove all elements from the string and start over from the current char. 4 | 4. Store the current found string length in max and compare the next string length with max. 5 | -------------------------------------------------------------------------------- /2021-07/2021-07-25 (day7)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-25 (day7)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-25 (day7)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-25 (day7)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-25 (day7)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: 3 | nums = sorted([*nums1, *nums2]) 4 | if len(nums) % 2: 5 | return float(nums[len(nums)//2]) 6 | return (nums[len(nums)//2]+nums[len(nums)//2-1])/2 7 | -------------------------------------------------------------------------------- /2021-07/2021-07-25 (day7)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | ## What is the Median? 4 | 5 | The `median` tells you *where the middle of the data set is*. 6 | 7 | ### Formula 8 | 9 | ``` 10 | Med(X) = X[n / 2], if n is odd 11 | Med(X) = (X[n-1 / 2] + X[n+1 / 2]) / 2, if n is even 12 | 13 | X = ordered list of values in data set 14 | n = number of values in data set 15 | ``` -------------------------------------------------------------------------------- /2021-07/2021-07-25 (day7)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 兩個list因為是已排序,所以可以從頭開始做比較,放入新list中。 3 | 2. 兩個list需要有各自的指標。 4 | 3. 其中一個list比完後,剩下的直接放入新list尾端。 5 | 4. 想直接用 .sort() 但似乎算犯規(?) 6 | 7 | # leecode 提交結果 8 | Runtime: 88 ms, faster than 85.13% of Python3 online submissions for Median of Two Sorted Arrays. 9 | Memory Usage: 14.5 MB, less than 80.66% of Python3 online submissions for Median of Two Sorted Arrays. -------------------------------------------------------------------------------- /2021-07/2021-07-26 (day8)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **for loop and judge string** -------------------------------------------------------------------------------- /2021-07/2021-07-26 (day8)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-26 (day8)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-07/2021-07-26 (day8)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-26 (day8)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-26 (day8)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-26 (day8)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 轉換成文字成相對數字 2 | 2. 檢查是否有後面大於前面的數字 3 | 3. 有的話就變為負的 4 | 4. 全部加總 -------------------------------------------------------------------------------- /2021-07/2021-07-27 (day9)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-27 (day9)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-27 (day9)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. create clone head 2 | 2. check next value is curr value => curr.next = curr.next.next 3 | 3. check next value isn't curr value => curr = next 4 | 4. return head -------------------------------------------------------------------------------- /2021-07/2021-07-27 (day9)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 逐一檢查有無下一個node,和下一個node比較val是否相同 3 | 2. 失去link的node即不存在於list 4 | 3. 測試資料裡有陷阱 [],用了哈奇之前教的early return 避開 5 | 6 | # leecode 提交結果 7 | Runtime: 44 ms, faster than 57.80% of Python3 online submissions for Remove Duplicates from Sorted List. 8 | Memory Usage: 14.2 MB, less than 81.15% of Python3 online submissions for Remove Duplicates from Sorted List. 9 | 10 | # 時間複雜度 11 | O(n) -------------------------------------------------------------------------------- /2021-07/2021-07-28 (day10)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **created an object about specific Roman numeral,and use for loop to check every object key,and decriced value to 0 then added to string** -------------------------------------------------------------------------------- /2021-07/2021-07-28 (day10)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-28 (day10)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-07/2021-07-28 (day10)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-28 (day10)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 以10為底數取得餘數 2 | 2. 判斷餘數分類 3 | 3. 底數x10,進行下一輪 -------------------------------------------------------------------------------- /2021-07/2021-07-28 (day10)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 把數字和羅馬字用兩個list做對應,特殊的如4和9的寫法也放進去 3 | 2. 依序比較數字是否存在list中,有的話就減掉,比到數字減至0為止 4 | 5 | # leecode 提交結果 6 | Runtime: 36 ms, faster than 98.58% of Python3 online submissions for Integer to Roman. 7 | Memory Usage: 14.3 MB, less than 59.06% of Python3 online submissions for Integer to Roman. 8 | -------------------------------------------------------------------------------- /2021-07/2021-07-29 (day11)/Alpha/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-29 (day11)/Alpha/README.md -------------------------------------------------------------------------------- /2021-07/2021-07-29 (day11)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-29 (day11)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-07/2021-07-29 (day11)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-29 (day11)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 確認兩點是否為其一node 2 | 2. 檢查value 3 | 3. 遞迴檢查左右分支 -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/A_GO/README.md: -------------------------------------------------------------------------------- 1 | # 100. Same Tree 2 | 3 | Easy 4 | 5 | ## Description 6 | 7 | Given the roots of two binary trees p and q, write a function to check if they are the same or not. 8 | 9 | Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. 10 | 11 | ## My Thoghts 12 | 13 | Just use DSP to travel all node and record depth of 14 | left child and right child. 15 | return the bigger depth 16 | 17 | ## O(n) -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **To check the tree's deepth, first judge if root is null return 0, other case to do recursive and caculate the maximum node value for left and right** -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-30 (day12)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-30 (day12)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def maxDepth(self, root: TreeNode) -> int: 9 | if root is None: 10 | return 0 11 | return max(1+self.maxDepth(root.left), 1+self.maxDepth(root.right)) 12 | -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/Hello/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | function TreeNode(val, left, right) { 2 | this.val = val === undefined ? 0 : val; 3 | this.left = left === undefined ? null : left; 4 | this.right = right === undefined ? null : right; 5 | } 6 | 7 | /** 8 | * @param {TreeNode} root 9 | * @return {number} 10 | */ 11 | function maxDepth(root) { 12 | return !root ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; 13 | } 14 | -------------------------------------------------------------------------------- /2021-07/2021-07-30 (day12)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立遞迴函數 2 | 2. 計算左右深度 3 | 3. 比較大小 -------------------------------------------------------------------------------- /2021-07/2021-07-31 (day13)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-07/2021-07-31 (day13)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-07/2021-07-31 (day13)/Husky/README.md: -------------------------------------------------------------------------------- 1 | #### DP 解 2 | 3 | 紀錄到達每一個位置的最短距離 4 | 5 | #### BFS 6 | 7 | 檢查每一步涵蓋範圍內的下一步是否能到達終點 8 | -------------------------------------------------------------------------------- /2021-07/2021-07-31 (day13)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Jump Game II 2 | 3 | 今天台灣男雙羽球太精采,README 暫停一天 4 | -------------------------------------------------------------------------------- /2021-08/2021-08-01 (day14)/CXPhoenix/solution-TimeLimitedError.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-01 (day14)/CXPhoenix/solution-TimeLimitedError.png -------------------------------------------------------------------------------- /2021-08/2021-08-01 (day14)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-01 (day14)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-01 (day14)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立相同大小矩陣 2 | 2. 逐一填值,取上跟左的值相比取小者,並加上自身 -------------------------------------------------------------------------------- /2021-08/2021-08-01 (day14)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Minimum Path Sum 2 | 3 | Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. 4 | 5 | Note: You can only move either down or right at any point in time. 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/A_GO/README.md: -------------------------------------------------------------------------------- 1 | # 21. Merge Two Sorted Lists 2 | 3 | Easy 4 | 5 | ## Description 6 | 7 | Merge two sorted linked lists and return it as a *sorted* list. The list should be made by splicing together the nodes of the first two lists. 8 | 9 | ## My Thoghts 10 | 11 | I was trying to use while loop to solve problem. 12 | 13 | But I stuck. 14 | 15 | So use recursicve to merge lists into L1 from end. 16 | 17 | ## O(m+n) -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-02 (day15)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-02 (day15)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立新的link 2 | 2. 保留指針 3 | 3. while loop 抽取l1 l2的值出來比大小 4 | 4. 將較小的提取出來接上在新的link上 -------------------------------------------------------------------------------- /2021-08/2021-08-02 (day15)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 建立一個空的 singly-linked list 用來存 answer 3 | 2. 使用 temp 做為 answer 的指標 4 | 3. 比較 l1, l2,小的節點加到 temp 裡,其中一個 list 用完後,另一個 list 剩下的部份一定比較大,直接接起來 5 | 4. 最後傳回時注意傳回的為 answer.next,而非 answer 本身 6 | 7 | # leecode 提交結果 8 | Runtime: 28 ms, faster than 98.17% of Python3 online submissions for Merge Two Sorted Lists. 9 | Memory Usage: 14.2 MB, less than 62.43% of Python3 online submissions for Merge Two Sorted Lists. 10 | 11 | # 時間複雜度 12 | O(m+n) -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/A_GO/111298.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-03 (day16)/A_GO/111298.jpg -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-03 (day16)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/CXPhoenix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotate(self, matrix: List[List[int]]) -> None: 3 | """ 4 | Do not return anything, modify matrix in-place instead. 5 | """ 6 | n = len(matrix) 7 | for col in range(n): 8 | tmp = [] 9 | for row in range(n): 10 | tmp.append(matrix[n-1-row][col]) 11 | matrix.append(tmp) 12 | del(matrix[:n]) 13 | -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/Husky/README.md: -------------------------------------------------------------------------------- 1 | ![](./solution.png) -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/Husky/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-03 (day16)/Husky/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotate(self, matrix: List[List[int]]) -> None: 3 | """ 4 | Do not return anything, modify matrix in-place instead. 5 | """ 6 | for i, row in enumerate(zip(*matrix[::-1])): 7 | matrix[i] = list(row) -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Rotate Image 2 | 3 | You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). 4 | 5 | You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. 6 | 7 | ## 8 | 9 | - 取 1 / 4 的部分一個對一個附值 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 光明正大地先看了哈奇的答案 3 | 2. 利用 python 的 zip 進行旋轉 4 | 3. 題目規定不能開新matrix,利用[:]取代原matrix來達到要求 5 | 6 | # leecode 提交結果 7 | Runtime: 32 ms, faster than 85.85% of Python3 online submissions for Rotate Image. 8 | Memory Usage: 14.4 MB, less than 31.35% of Python3 online submissions for Rotate Image. -------------------------------------------------------------------------------- /2021-08/2021-08-03 (day16)/White/day16_rotate_image.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotate(self, matrix: List[List[int]]) -> None: 3 | """ 4 | Do not return anything, modify matrix in-place instead. 5 | """ 6 | matrix[:] = list(zip(*reversed(matrix))) -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-04 (day17)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-04 (day17)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/CXPhoenix/solution3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-04 (day17)/CXPhoenix/solution3.png -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 0. 宣告進位暫存變數 2 | 1. 逐一取出相加,並加上進位暫存 3 | 2. 檢查是否大於10,大於的話將進位暫存紀錄此次10位數,此node紀錄當次個位數 4 | 3. L1 L2都用光後,檢查進位暫存是否有值,有的話再新增一個node -------------------------------------------------------------------------------- /2021-08/2021-08-04 (day17)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. linked list 走法和之前的題目一樣 3 | 2. 進位的值要加到下一筆 ListNode 4 | 3. 測試時發現兩個 list 長度不一時,直接取值會error,因此另外設x y 來取代 5 | 6 | # leecode 提交結果 7 | Runtime: 60 ms, faster than 96.68% of Python3 online submissions for Add Two Numbers. 8 | Memory Usage: 14.4 MB, less than 44.82% of Python3 online submissions for Add Two Numbers. 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | **To check the tree's deepth, first judge if root is null return 0, other case to do recursive and caculate the maximum node value for left and right** -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-05 (day18)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | for i in range(len(nums)): 4 | for j in range(len(nums)): 5 | if i == j: 6 | continue 7 | if nums[i] + nums[j] == target: 8 | return [i,j] 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-05 (day18)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | for i in range(len(nums)): 4 | if target-nums[i] in nums[i+1:]: 5 | return(i, nums.index(target-nums[i], i+1)) 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-05 (day18)/CXPhoenix/solution3.png -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution3.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | record = {} 4 | for i in range(len(nums)): 5 | toFind = target - nums[i] 6 | if toFind in record.keys(): 7 | return [record[toFind], i] 8 | record[nums[i]] = i 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-05 (day18)/CXPhoenix/solution4.png -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/CXPhoenix/solution4.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | record = {} 4 | for i in range(len(nums)): 5 | toFind = target - nums[i] 6 | try: 7 | return [record[toFind], i] 8 | except: 9 | record[nums[i]] = i 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} target 4 | * @return {number[]} 5 | */ 6 | function twoSum(nums, target) { 7 | const cache = {}; 8 | 9 | for (let i = 0; i < nums.length; i++) { 10 | if (nums[i] in cache) { 11 | return [i, cache[nums[i]]]; 12 | } 13 | 14 | cache[target - nums[i]] = i; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立hash map 2 | 2. 比對相加成立條件 -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]': 3 | numMap = {} 4 | for i in range(len(nums)): 5 | if nums[i] in numMap: 6 | return [numMap[nums[i]], i] 7 | else: 8 | numMap[target - nums[i]] = i -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} target 4 | * @return {number[]} 5 | */ 6 | var twoSum = function (nums, target) { 7 | let temp = []; 8 | let index = 0; 9 | 10 | while (temp.indexOf(nums[index]) === -1) { 11 | temp.push(target - nums[index]); 12 | index++; 13 | } 14 | 15 | return [temp.indexOf(nums[index]), index]; 16 | }; 17 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/Randolph/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | a = 0 4 | for i in range (len(nums)): 5 | a = target - nums[i] 6 | if a in nums and nums.index(a) != i: 7 | return [i,nums.index(a)] 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 因為 list 中任兩值合計為答案,所以輪到 nums[i] 時就從剩下的找是否有值等於 target - nums[i] 3 | 結果就是很慢的荔枝 4 | 5 | # leecode 提交結果 6 | Runtime: 816 ms, faster than 34.46% of Python3 online submissions for Two Sum. 7 | Memory Usage: 14.8 MB, less than 92.35% of Python3 online submissions for Two Sum. -------------------------------------------------------------------------------- /2021-08/2021-08-05 (day18)/White/day18_two_sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | for i, val in enumerate(nums): 4 | comp = target - nums[i] 5 | if comp in nums and (nums.index(comp) != i): 6 | return [i, nums.index(comp)] -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/A_GO/111962.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-06 (day19)/A_GO/111962.jpg -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-06 (day19)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/Husky/README.md: -------------------------------------------------------------------------------- 1 | ![](./merge_sort.png) 2 | -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/Husky/merge_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-06 (day19)/Husky/merge_sort.png -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Merge k Sorted Lists 2 | 3 | You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. 4 | 5 | Merge all the linked-lists into one sorted linked-list and return it. 6 | 7 | ## 想法 8 | 9 | - Compare one by one 10 | 11 | 跑多次迴圈,每次都從 `lists` 陣列中的每個 linked-lists 的目前第一個位置來比較,找到最小值就放到新的 linked-lists,最後回傳 12 | 13 | ## 解法 14 | 15 | 放棄 QQ 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-06 (day19)/Tim/README.md: -------------------------------------------------------------------------------- 1 | # WARNING 暴力解 2 | 3 | * 1. Loop through every single linked-list and find the minimum value at the current searching depth. 4 | 5 | * 2. Connect solution.next to the list with min value. 6 | 7 | * 3. Recurring until all the linked-lists are empty. 8 | 9 | ## Simple but Slow 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/A_GO/README.md: -------------------------------------------------------------------------------- 1 | # 387. First Unique Character in a String 2 | 3 | Easy 4 | 5 | ## Description 6 | 7 | Given a string `s`, find the first non-repeating character in it and return its index. If it does not exist, return `-1`. 8 | 9 | ## My Thoghts 10 | 11 | Use a map to store count of char and a queue to store index of char. 12 | If the char is repeat, pop one out of queue and check till front is not repeat. 13 | 14 | ## O(N) -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | var firstUniqChar = function(s) { 2 | for(i=0;i int: 3 | record={} 4 | for i in range(len(s)): 5 | if record.get(s[i]) is not None: 6 | record[s[i]] = 1e6 7 | else: 8 | record[s[i]] = i 9 | return min(record.values()) if min(record.values()) < len(s) else -1 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Hello/solution2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | function firstUniqChar(s) { 6 | for (let index = 0; index < s.length; index++) { 7 | if (s.indexOf(s[index]) === s.lastIndexOf(s[index])) { 8 | return index; 9 | } 10 | } 11 | 12 | return -1; 13 | } 14 | 15 | console.log(firstUniqChar("aabb")); 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Husky/solution_1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | m = {} 4 | for char in s: 5 | if char not in m: 6 | m[char] = 1 7 | else: 8 | m[char] = -1 9 | 10 | for i in range(len(s)): 11 | char = s[i] 12 | if m[char] == 1: 13 | return i 14 | return -1 -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Husky/solution_2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | uniq = set() 4 | for i, char in enumerate(s): 5 | if char not in uniq: 6 | if char not in s[i+1:]: 7 | return i 8 | else: 9 | uniq.add(char) 10 | 11 | return -1 -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # First Unique Character in a String 2 | 3 | Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. 4 | 5 | ## Solution 6 | 7 | - 跑兩次迴圈 8 | - 第一次,紀錄每個字串的出現次數 9 | - 第二次,根據紀錄回傳第一個只出現一次的字串,沒有找到就回傳 -1 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | var firstUniqChar = function (s) { 6 | let map = {}; 7 | for (let i = 0; i < s.length; i++) { 8 | map[s[i]] = map[s[i]] + 1 || 1; 9 | } 10 | for (let i = 0; i < s.length; i++) { 11 | if (map[s[i]] === 1) return i; 12 | } 13 | return -1; 14 | }; 15 | -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Randolph/README.md: -------------------------------------------------------------------------------- 1 | # First Unique Character in a String 2 | 3 | Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. 4 | 5 | # Solution 6 | 7 | - 用迴圈找出a-z中只出現過一次的字母 並將其在s裡的索引值推入data串列裡 8 | - 在判斷data串列是否為空 若是則返回-1 若不是則返回data串列中的最小值 -------------------------------------------------------------------------------- /2021-08/2021-08-07 (day20)/Randolph/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | english = "abcdefghijklmnopqrstuvwxyz" 4 | data = [] 5 | for i in english: 6 | if s.count(i) == 1: 7 | data.append(s.index(i)) 8 | if data == []: 9 | return -1 10 | else: 11 | return min(data) 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-08 (day21)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 概念,先反轉,再從後面取出,就會是正常序列 2 | -------------------------------------------------------------------------------- /2021-08/2021-08-08 (day21)/Tim/fig/pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-08 (day21)/Tim/fig/pic1.png -------------------------------------------------------------------------------- /2021-08/2021-08-09 (day22)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-09 (day22)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-09 (day22)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. merge sort先決條件要排序好 2 | 2. 全部打散,就解決排序問題 3 | 3. 組裝 -------------------------------------------------------------------------------- /2021-08/2021-08-09 (day22)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: linked list -> list.sort() -> linked list 2 | 3 | #### optimization: list could be sorted when reading the linked list 4 | 5 | ![][fig] 6 | 7 | [fig]:./fig/pic1.png 8 | 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-09 (day22)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-09 (day22)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-09 (day22)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. solution 提示裡把 list 從中間拆成兩個 list,再合併排序。 3 | 2. 丟進合併排序前兩個 list 各自排序過再丟入合併排序。 4 | 3. 合併排序用的是 day15 練習的code。 5 | 6 | # leecode 提交結果 7 | Runtime: 480 ms, faster than 48.96% of Python3 online submissions for Sort List. 8 | Memory Usage: 30.1 MB, less than 73.56% of Python3 online submissions for Sort List. 9 | 10 | 照官方 solution 的影片示意,正確解法在丟進合併排序前應該不用先排序,可能是沒有遵照作法速度才這麼慢。 11 | -------------------------------------------------------------------------------- /2021-08/2021-08-10 (day23)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-08/2021-08-10 (day23)/Fanli/98. Validate Binary Search Tree.js: -------------------------------------------------------------------------------- 1 | function isValidBST(root, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER){ 2 | //邊界值 3 | if (!root) return true 4 | //超出範圍即為false 5 | if (root.val >= max || root.val <= min) return false 6 | //判斷左子樹和右子數 7 | return (isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max)) 8 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-10 (day23)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-10 (day23)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-10 (day23)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 二元樹使用中序走訪會得到排序好的結果。 3 | 2. 使用遞迴將中序走訪取得的結果加入list。 4 | 3. 將中序走訪的結果list和 sorted(list)的結果比較,相同即為true。 5 | 4. 因二元樹不可以有相同值的節點,故加入set做比較。 6 | 7 | # leecode 提交結果 8 | Runtime: 44 ms, faster than 69.67% of Python3 online submissions for Validate Binary Search Tree. 9 | Memory Usage: 17.8 MB, less than 7.19% of Python3 online submissions for Validate Binary Search Tree. 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-11 (day24)/Fanli/101. Symmetric Tree.js: -------------------------------------------------------------------------------- 1 | function isSymmetric(root) { 2 | if(!root)return true 3 | return compare(root.right,root.left) 4 | }; 5 | 6 | function compare(left,right){ 7 | //若都為null直接返回true 8 | if(!left&&!right)return true 9 | if(left?.val!==right?.val)return false 10 | //確保對比的是同一個鏡像節點 11 | return compare(left.right,right.left) && compare(left.left,right.right) 12 | } -------------------------------------------------------------------------------- /2021-08/2021-08-11 (day24)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: BFS BJ4 2 | 3 | #### optimization?: save the queue while checking if it is symmetric 4 | 5 | 6 | 7 | ![][fig] 8 | 9 | [fig]:./fig/fig1.png 10 | 11 | -------------------------------------------------------------------------------- /2021-08/2021-08-11 (day24)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-11 (day24)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Fanli/49. Group Anagrams.js: -------------------------------------------------------------------------------- 1 | //HashMap 2 | function groupAnagrams(strs) { 3 | let map = new Map() 4 | strs.forEach(str => { 5 | let strKey = str.split("").sort().join("") 6 | if (map.has(strKey)) map.get(strKey).push(str) 7 | else map.set(strKey, [str]) 8 | }) 9 | return [...map.values()] 10 | } -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} strs 3 | * @return {string[][]} 4 | */ 5 | function groupAnagrams(strs) { 6 | const map = new Map(); 7 | 8 | for (const str of strs) { 9 | const sorted = str.split("").sort().join(""); 10 | 11 | if (map.has(sorted)) { 12 | map.get(sorted).push(str); 13 | } else { 14 | map.set(sorted, [str]); 15 | } 16 | } 17 | 18 | return Array.from(map.values()); 19 | } 20 | -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立hash map 2 | 2. 每個字串重新排列後檢查 hash map裡面有沒有 3 | 3. 有的話往後塞,沒有的話建立新的key -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | anagramsMap = {} 4 | for s in strs: 5 | key = ''.join(sorted(s)) 6 | if key in anagramsMap: 7 | anagramsMap[key].append(s) 8 | else: 9 | anagramsMap[key] = [s] 10 | 11 | return [anagrams for anagrams in anagramsMap.values()] -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Group Anagrams 2 | 3 | Given an array of strings strs, group the anagrams together. You can return the answer in any order. 4 | 5 | An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. 6 | 7 | ## Solution 8 | 9 | 解法都是建立一個 "排序過的字串" 當作對象來比較 10 | 11 | - 解法一 做一個陣列,拿來跑迴圈比較 12 | - 解法二 做一個物件,直接取值比較 13 | -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Tim/README.md: -------------------------------------------------------------------------------- 1 | 2 | ![][fig] 3 | 4 | [fig]:./fig/fig1.png 5 | 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-12 (day25)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-12 (day25)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/AGO/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool hasCycle(ListNode *head) { 4 | unordered_mapmem; 5 | while(head) 6 | { 7 | if(mem[head->next]>0) return true; 8 | mem[head]++; 9 | head = head->next; 10 | } 11 | return false; 12 | } 13 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/Fanli/141. Linked List Cycle.js: -------------------------------------------------------------------------------- 1 | //LinkList 快慢指針 2 | function hasCycle(head) { 3 | //考慮邊界 4 | if(!head) return false 5 | //宣告快慢指標 6 | let fast = head; 7 | let slow = head; 8 | //當快指標有盡頭時表示無閉環, 否則不斷迭代 9 | while(fast.next?.next){ 10 | //快指標走2步 11 | fast = fast.next.next 12 | slow = slow.next 13 | //當快指標追上慢指標表示有閉環 14 | if(fast===slow)return true 15 | } 16 | return false 17 | } -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/Husky/README.md: -------------------------------------------------------------------------------- 1 | ### 方法一 2 | 1. 遍歷所有node,並且存在set中,並且逐一去檢查是有否出現過 3 | 4 | ### 方法二 5 | 2. 龜兔賽跑,最晚在第二圈結束的時候兔子會追上烏龜,這時候就會形成Cycle -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/Husky/solution_2.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, x): 4 | # self.val = x 5 | # self.next = None 6 | 7 | class Solution: 8 | def hasCycle(self, head: ListNode) -> bool: 9 | slow = fast = head 10 | while fast and fast.next: 11 | slow = slow.next 12 | fast = fast.next.next 13 | if slow is fast: 14 | return True 15 | return False -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/White/README.md: -------------------------------------------------------------------------------- 1 | 遅い 2 | 3 | # leecode 4 | Runtime: 69 ms, faster than 11.41% of Python3 online submissions for Linked List Cycle. 5 | Memory Usage: 17.7 MB, less than 55.13% of Python3 online submissions for Linked List Cycle. -------------------------------------------------------------------------------- /2021-08/2021-08-13 (day26)/haha/README.md: -------------------------------------------------------------------------------- 1 | 1. 題目編號 題目標題 題目內容 141. Linked List Cycle 2 | Given head, the head of a linked list, determine if the linked list has a cycle in it. 3 | 2. 解題思路 4 | (1) 創建一個集合 5 | (2) 如果有 node 進行判斷,沒有直接回傳 false 6 | (3) 如果有 node,新增 node 到節點裡直到沒有節點為止,如果接得到 node 就代表是一個 cycle 7 | 3. 程式碼附完整註解 8 | 4. 時間複雜度 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution 2 | 3 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var removeDuplicates = function(nums) { 6 | if(nums.length === 0) { 7 | return 0; 8 | } 9 | let j = 0; 10 | for(i=1; i< nums.length; i++) { 11 | if (nums[i] !== nums[j]) { 12 | j++; 13 | nums[j] = nums[i]; 14 | } 15 | } 16 | return j + 1; 17 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-15 (day28)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | i = 1 4 | count = 1 5 | while i < len(nums): 6 | if nums[i] in nums[:i]: 7 | del(nums[i]) 8 | continue 9 | count += 1 10 | i += 1 11 | return count 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-15 (day28)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Chocolate/README.md: -------------------------------------------------------------------------------- 1 | ## 26. Remove Duplicates from Sorted Array 2 | 3 | Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. 4 | 5 | ## Chocolate's solution 6 | 用if迴圈判別是否有重複的數字 -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Chocolate/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | if not nums: return 0 4 | a, b = 0, 1 5 | while b < len(nums): 6 | if nums[a] != nums[b]: 7 | a += 1 8 | nums[a] = nums[b] 9 | b += 1 10 | return a + 1 -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Fanli/26. Remove Duplicates from Sorted Array.js: -------------------------------------------------------------------------------- 1 | function removeDuplicates (nums) { 2 | let left = 0 3 | let right = 1 4 | while(right= nums.length) return point + 1; 9 | 10 | if (cursor !== point) { 11 | nums[++point] = nums[cursor]; 12 | } 13 | 14 | return removeDuplicates(nums, point); 15 | } 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Husky/README.md: -------------------------------------------------------------------------------- 1 | Two Pointers => 遇到前後兩項不同就取代回去 2 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | n = len(nums) 4 | if n == 0: 5 | return 0 6 | 7 | replaceIndex = 1 8 | for i in range(1, n): 9 | if nums[i - 1] != nums[i]: 10 | nums[replaceIndex] = nums[i] 11 | replaceIndex += 1 12 | 13 | return replaceIndex 14 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | var removeDuplicates = function (nums) { 2 | // Skip the first value in nums, so set `i` with `1` instead of `0` 3 | let i = 1; 4 | while (i < nums.length) { 5 | if (nums[i - 1] === nums[i]) { 6 | nums.splice(i, 1); 7 | } else { 8 | i++; 9 | } 10 | } 11 | return nums.length; 12 | }; 13 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Kevin/solution_2.js: -------------------------------------------------------------------------------- 1 | var removeDuplicates = function (nums) { 2 | // Skip the first value in nums, so set `i` and `j` with `1` instead of `0` 3 | let i = 1; 4 | for (let j = 1; j < nums.length; j++) { 5 | if (nums[j] !== nums[j - 1]) { 6 | nums[i] = nums[j]; 7 | i++; 8 | } 9 | } 10 | return i; 11 | }; 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Randolph/README.md: -------------------------------------------------------------------------------- 1 | ## 題目 2 | 3 | Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. 4 | 5 | ## Randolph's solution 6 | 7 | -用for迴圈判斷nums串列裡是否有出現兩次以上的數字 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/Randolph/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | for i in nums: 4 | while nums.count(i) > 1: 5 | nums.remove(i) 6 | return len(nums) -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 記錄目前索引比較位置,開始讀陣列資料做比較,如果值相同的就不做動作,如果不同就拉到目前索引的下一位。 3 | 2. 回傳要求答案長度,故索引值+1。 4 | 5 | # leecode 提交結果 6 | Runtime: 80 ms, faster than 89.69 % of Python3 online submissions for Remove Duplicates from Sorted Array. 7 | Memory Usage: 15.7 MB, less than 53.83 % of Python3 online submissions for Remove Duplicates from Sorted Array. -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/White/remove_duplicates_from_sorted_array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | i = 0 4 | for n in range(len(nums)): 5 | if nums[n] != nums[i]: 6 | i += 1 7 | nums[i] = nums[n] 8 | return i+1 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/haha/README.md: -------------------------------------------------------------------------------- 1 | question : [easy] 26. Remove Duplicates from Sorted Array 2 | 3 | solution : 4 | if hash table not has value push nums[i] to be only key and this.count add 1, 5 | hash table will like { 'value': index }, 6 | get hash table's values ex: [1,1,2], hash = { '1': 0, '2': 2 }, 7 | let tableVal get nums real data like tableVal = [ 0, 2 ] => [ 1, 2], 8 | sort my result and if it is negative number return (a - b), 9 | assign result to set nums 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-15 (day28)/huibizhang/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var removeDuplicates = function(nums) { 6 | const nagtive_keys = {}, 7 | positive_keys = {} 8 | 9 | nums.forEach((num) =>{ 10 | (num >= 0?positive_keys:nagtive_keys)[num]=num 11 | }) 12 | 13 | const keys = Object.keys(nagtive_keys).concat(Object.keys(positive_keys)) 14 | keys.forEach((key,index) => nums[index]=key) 15 | 16 | return keys.length 17 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-16 (day29)/Fanli/94. Binary Tree Inorder Traversal.js: -------------------------------------------------------------------------------- 1 | function inorderTraversal(root) { 2 | let res = [] 3 | const _inorderTraversal = function(node){ 4 | if(!node) return 5 | _inorderTraversal(node.left) 6 | res.push(node.val) 7 | _inorderTraversal(node.right) 8 | } 9 | _inorderTraversal(root) 10 | return res 11 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-16 (day29)/Hello/iterative.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {TreeNode} root 3 | * @return {number[]} 4 | */ 5 | function inorderTraversal(root) { 6 | const stack = []; 7 | const result = []; 8 | 9 | while (true) { 10 | if (root) { 11 | stack.push(root); 12 | root = root.left; 13 | continue; 14 | } 15 | 16 | if (!stack.length) return result; 17 | 18 | root = stack.pop(); 19 | result.push(root.val); 20 | root = root.right; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2021-08/2021-08-16 (day29)/Hello/recursive.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {TreeNode} root 3 | * @return {number[]} 4 | */ 5 | function inorderTraversal(root) { 6 | if (!root) return []; 7 | 8 | return [ 9 | ...inorderTraversal(root.left), 10 | root.val, 11 | ...inorderTraversal(root.right), 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /2021-08/2021-08-16 (day29)/Husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 左右遞迴 2 | 3 | 2. 左邊依序放入 stack,在從後面依序拿出來,並丟入右邊節點再重來一次,直到 tree 跟 stack 都清空 4 | -------------------------------------------------------------------------------- /2021-08/2021-08-16 (day29)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 使用遞迴將樹轉為中序輸出至list 3 | 4 | # leecode 提交結果 5 | Runtime: 28 ms, faster than 82.70% of Python3 online submissions for Binary Tree Inorder Traversal. 6 | Memory Usage: 14 MB, less than 98.74% of Python3 online submissions for Binary Tree Inorder Traversal. -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function isPowerOfThree(n: number): boolean { 2 | if (n == 1) 3 | return true; 4 | if (n % 3 == 0 && n > 3) { 5 | return isPowerOfThree(n / 3); 6 | } 7 | if (n != 3) 8 | return false; 9 | else 10 | return true; 11 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | var isPowerOfThree = function(n) { 2 | for (i=1;i<=n;i*=3) { 3 | if ( n === i ) { 4 | return true 5 | } 6 | } 7 | return false 8 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-17 (day30)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | if n == 0: 4 | return False 5 | def calc(n): 6 | if n == 1: 7 | return True 8 | if n % 3: 9 | return False 10 | return calc(n//3) 11 | return calc(n) 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-17 (day30)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | if n <= 0: 4 | return False 5 | if 3 ** 21 % n == 0: 6 | return True 7 | return False 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Fanli/326. Power of Three.js: -------------------------------------------------------------------------------- 1 | function isPowerOfThree(n) { 2 | while (n && n % 3 === 0) { 3 | n /= 3; 4 | } 5 | return n === 1; 6 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Hello/iteration.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | function isPowerOfThree(n) { 6 | while (n >= 3) { 7 | n /= 3; 8 | } 9 | 10 | return n === 1; 11 | } 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Hello/math.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | function isPowerOfThree(n) { 6 | return n > 0 && 3 ** 19 % n === 0; 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Hello/recursion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | function isPowerOfThree(n) { 6 | return n < 3 ? n === 1 : isPowerOfThree(n / 3); 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | if n == 0: 4 | return False 5 | if n == 1: 6 | return True 7 | elif n % 3 != 0: 8 | return False 9 | 10 | return self.isPowerOfThree(n/3) 11 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Power of Three 2 | 3 | Given an integer n, return true if it is a power of three. Otherwise, return false. 4 | 5 | An integer n is a power of three, if there exists an integer x such that n == 3x. 6 | 7 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | 6 | // Solution 1 - recursive 7 | var isPowerOfThree = function(n) { 8 | if(n < 1 ) return false 9 | if(n === 1) return true 10 | return isPowerOfThree( n/3 ) 11 | }; 12 | 13 | // Solution 2 - loop 14 | var isPowerOfThree = function(n) { 15 | if( n === 0 ) return false 16 | while( n%3 === 0 ){ 17 | n /= 3 18 | } 19 | return n === 1 20 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### 5 solutions are provided. 2 | 3 | #### optimization?: None 4 | 5 | 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-17 (day30)/White/power_of_three.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | while n % 3 == 0 and n != 0: 4 | n = n / 3 5 | return True if n ==1 else False -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function singleNumber(nums: number[]): number { 2 | let result:number; 3 | nums.forEach(e => { 4 | result ^= e; 5 | }); 6 | return result; 7 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Alpha/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-18 (day31)/Alpha/README.md -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | var singleNumber = function(nums) { 2 | const result = new Set(); 3 | for(let num of nums) { 4 | if(result.has(num)) { 5 | result.delete(num); 6 | } else { 7 | result.add(num); 8 | } 9 | } 10 | return [...result][0]; 11 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/XOR-display.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-18 (day31)/CXPhoenix/XOR-display.png -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/XOR-solution.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-18 (day31)/CXPhoenix/XOR-solution.gif -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/solution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-18 (day31)/CXPhoenix/solution1.png -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | record = {} 4 | for num in nums: 5 | if record.get(num): 6 | del record[num] 7 | continue 8 | record[num] = True 9 | return list(record.keys())[0] 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/solution2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-18 (day31)/CXPhoenix/solution2.png -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/CXPhoenix/solution2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | single = 0 4 | for num in nums: 5 | single ^= num 6 | return single 7 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Fanli/136. Single Number.js: -------------------------------------------------------------------------------- 1 | function singleNumber(nums) { 2 | let res=nums[0] 3 | for (let i=1;i a ^ b, 0); 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | function singleNumber(nums) { 6 | return nums.reduce((a, b) => a ^ b, 0); 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Hello/sum.js: -------------------------------------------------------------------------------- 1 | const sum = (nums) => nums.reduce((a, b) => a + b, 0); 2 | 3 | function singleNumber(nums) { 4 | const set = Array.from(new Set(nums)); 5 | 6 | return 2 * sum(set) - sum(nums); 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var singleNumber = function(nums) { 6 | const set = new Set() 7 | for(let i =0; i int: 3 | res = set() 4 | for i in nums: 5 | if i in res: 6 | res.remove(i) 7 | else: 8 | res.add(i) 9 | return list(res)[0] 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/White/single_number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | arr = {} 4 | for i in nums: 5 | if i in arr.keys(): 6 | arr[i] = arr[i] + 1 7 | else: 8 | arr[i] = 1 9 | 10 | res = [key for key, val in arr.items() if val == 1] 11 | return res[0] -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/haha/README.md: -------------------------------------------------------------------------------- 1 | question: [EASY] 136. Single Number
2 |
3 | solution:
4 | create a new Map, for loop the input,
5 | and if each one has in map, delete it, or not add it 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var singleNumber = function (nums) { 6 | let map = new Map() 7 | nums.forEach((el, index) => { 8 | // if each one has in map, delete it, or not add it 9 | map.has(el) ? map.delete(el) : map.set(el, index) 10 | }) 11 | return [...map.keys()] 12 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/huibizhang/solution1_map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var singleNumber = function(nums) { 6 | const map = new Map() 7 | 8 | nums.forEach((num) => { 9 | map.has(num)?map.delete(num):map.set(num) 10 | }) 11 | 12 | return [...map.keys()] 13 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/huibizhang/solution2_object.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var singleNumber = function(nums) { 6 | const map = {} 7 | 8 | nums.forEach((num) => { 9 | (map[num]!==undefined)?(delete map[num]):(map[num] = num) 10 | }) 11 | 12 | return [...Object.keys(map)] 13 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/huibizhang/solution3_string-appear-count.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var singleNumber = function(nums) { 6 | const keys = new Set(nums) 7 | let s = ` ${nums.join(' ')} ` 8 | 9 | for (key of keys) { 10 | if(s.match(new RegExp(`\\s${key}\\b`,'g')).length===1){ 11 | return key 12 | } 13 | } 14 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/husky/README.md: -------------------------------------------------------------------------------- 1 | 1. 建立 set 2 | 2. 第一次出現就加入 3 | 3. 第二次出現就移除 4 | 4. 最後只會剩一個,pop 出來 5 | -------------------------------------------------------------------------------- /2021-08/2021-08-18 (day31)/husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | only = set() 4 | 5 | for n in nums: 6 | if n in only: 7 | only.remove(n) 8 | else: 9 | only.add(n) 10 | 11 | return only.pop() -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function missingNumber(nums: number[]): number { 2 | let result: number = 0; // store answer 3 | for (let i = 1; i <= nums.length; i++) { 4 | result += i; 5 | result -= nums[i - 1]; 6 | } 7 | return result; 8 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/CXPhoenix/README.md: -------------------------------------------------------------------------------- 1 | CXPhoenix's Solutions 2 | === 3 | 4 | ## 268. Missing Number 5 | 6 | [original question](https://leetcode.com/problems/missing-number) 7 | 8 | --- 9 | 10 | ## My Thoughts 11 | 12 | 想法很直觀,就是整個數列差一個數字是哪一個, 13 | 14 | 那麼就暴力的來,把原本該有的數列數字加起來,然後減掉現有數列, 15 | 16 | 就算完了.... 17 | 18 | [solution](./solution.py) 19 | 20 | 21 | 22 | --- 23 | 24 | ## Big-O 25 | 26 | solution -> O(n) -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-19 (day32)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/CXPhoenix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: List[int]) -> int: 3 | return sum(list(range(len(nums)+1)))- sum(nums) 4 | -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Chocolate/README.md: -------------------------------------------------------------------------------- 1 | ## 268. Missing Number 2 | Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. 3 | 4 | ## Chocolate's solution 5 | 算出總長度後 6 | 用for帶出原本的數字 7 | 最後把總長度的總和減掉原本的數字 -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Chocolate/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: List[int]) -> int: 3 | a = len(nums)+1 4 | Sum = 0 5 | for i in nums: 6 | Sum += i 7 | return sum(range(a))-Sum -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Fanli/268. Missing Number.js: -------------------------------------------------------------------------------- 1 | function missingNumber(nums) { 2 | return (((nums.length+1)/2) * nums.length) - nums.reduce((a,b)=>a+b) 3 | } -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | function missingNumber(nums) { 6 | return nums.reduce((sum, num, index) => sum ^ num ^ index, nums.length); 7 | } 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: List[int]) -> int: 3 | a = 0 4 | for i in range(len(nums)): 5 | a ^= i^nums[i] 6 | 7 | return a^(len(nums)) 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function(nums) { 6 | // 梯形公式 7 | let sum = (nums.length + 1) * (nums.length) / 2 8 | for(let i =0; i int: 3 | 4 | Sum = 0 5 | for i in nums: 6 | Sum += i 7 | return sum(range(len(nums)+1))-Sum 8 | 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/White/missing_number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: List[int]) -> int: 3 | return int(((1 + len(nums))* ((len(nums))/ 2)) - sum(nums)) -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/haha/README.md: -------------------------------------------------------------------------------- 1 | question: [EASY] 268. Missing Number
2 |
3 | solution:
4 | create a new Set, for loop the input,
5 | and if set has not index, return it 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function (nums) { 6 | let set = new Set(nums) 7 | for (let i = 0; i <= nums.length; i++) { 8 | if (!set.has(i)) return i 9 | } 10 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/huibizhang/solution_index-not-exist.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function(nums) { 6 | let missing = nums.length 7 | 8 | for(index=0;index a+b) 13 | 14 | return sum - num_sum || nums.length 15 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/huibizhang/solution_number-sort.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function(nums) { 6 | const renums = nums.sort((a, b) => a - b) 7 | let missing = renums[renums.length-1] + 1 8 | 9 | for (let [key,index] of renums.entries()) { 10 | if (key!=index) { 11 | missing = key 12 | break 13 | } 14 | } 15 | 16 | return missing 17 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-19 (day32)/huibizhang/solution_object-sort.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function(nums) { 6 | const map = {} 7 | 8 | nums.forEach((num) => { 9 | map[num] = num; 10 | }) 11 | 12 | let missing = Math.max(...nums) + 1 13 | 14 | for (let [key,index] of Object.keys(map).entries()) { 15 | if (key!=index) { 16 | missing = key 17 | break 18 | } 19 | } 20 | 21 | return missing 22 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var findDuplicate = function(nums) { 6 | let tmp = new Set(); 7 | for(let num of nums) { 8 | if(tmp.has(num)) { 9 | return num; 10 | } else { 11 | tmp.add(num) 12 | } 13 | } 14 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/CXPhoenix/README.md: -------------------------------------------------------------------------------- 1 | CXPhoenix's Solution 2 | === 3 | 4 | ## 287. Find the Duplicate Number 5 | 6 | [original question](https://leetcode.com/problems/find-the-duplicate-number) 7 | 8 | --- 9 | 10 | ## My thoughts 11 | 12 | 直接上code 13 | 14 | [solution](./solution.py) 15 | 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-20 (day33)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/CXPhoenix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicate(self, nums: List[int]) -> int: 3 | r = {} 4 | for n in nums: 5 | if r.get(n): 6 | return n 7 | r[n] = 8591 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/Fanli/287. Find the Duplicate Number.js: -------------------------------------------------------------------------------- 1 | function findDuplicate(nums) { 2 | let map = new Map() 3 | for(let i=0;i a - b); 3 | 4 | for (let index = 0; index < nums.length; index++) { 5 | if (nums[index] === nums[index + 1]) { 6 | return nums[index]; 7 | } 8 | } 9 | 10 | return -1; 11 | } 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Find the Duplicate Number 2 | 3 | ## Solution 4 | 5 | Set -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var findDuplicate = function(nums) { 6 | const set = new Set() 7 | let i = 0 8 | while(true){ 9 | if(set.has(nums[i])) return nums[i] 10 | set.add(nums[i]) 11 | i++ 12 | } 13 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-20 (day33)/White/find_the_duplicate_number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicate(self, nums: List[int]) -> int: 3 | nums.sort() 4 | i = 0 5 | for j in range(1, len(nums)): 6 | if nums[i] == nums[j]: 7 | return nums[i] 8 | i += 1 -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/CXPhoenix/README.md: -------------------------------------------------------------------------------- 1 | CXPhoenix's Solution 2 | === 3 | 4 | ## 215. Kth Largest Element in an Array 5 | 6 | [original question](https://leetcode.com/problems/kth-largest-element-in-an-array) 7 | 8 | --- 9 | 10 | ## My Thoughts 11 | 12 | 就..排序後找到第 k 大的 13 | 14 | 但是聽說要用heap sort 15 | 16 | 我用內建的 quick sort 17 | 18 | 結案 19 | 20 | [solution](./solution.py) 21 | 22 | 23 | 24 | --- 25 | 26 | ## Big-O 27 | 28 | O(nlogn) -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-21 (day34)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/CXPhoenix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKthLargest(self, nums: List[int], k: int) -> int: 3 | sortNums = sorted(nums) 4 | get = [] 5 | for _ in range(k): 6 | get.append(sortNums.pop()) 7 | return get[-1] -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/Fanli/215. Kth Largest Element in an Array.js: -------------------------------------------------------------------------------- 1 | function findKthLargest(nums, k) { 2 | return nums.sort((a,b)=>b-a).splice(0,k)[k-1] 3 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | function findKthLargest(nums, k) { 7 | return nums.sort((a, b) => a - b)[nums.length - k]; 8 | } 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/White/Kth_largest_element_in_an_array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKthLargest(self, nums: List[int], k: int) -> int: 3 | nums.sort(reverse=True) 4 | return nums[k-1] 5 | 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-21 (day34)/huibizhang/solution_replace-max.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | var findKthLargest = function(nums, k) { 7 | for(let i=0;i b-a)[k-1] 8 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/CXPhoenix/solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-22 (day35)/CXPhoenix/solution.png -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/Fanli/997. Find the Town Judge.js: -------------------------------------------------------------------------------- 1 | function findJudge(n, trust) { 2 | let degrees = Array(n).fill(0) 3 | trust.forEach(t=>{ 4 | degrees[t[0]-1]-- 5 | degrees[t[1]-1]++ 6 | }) 7 | for(let i=0;i int: 3 | if len(trust) == 0: 4 | return 1 if n == 1 else -1 5 | 6 | m = [0]*(n + 1) 7 | m_ = set() 8 | for i, j in trust: 9 | m_.add(i) 10 | m[j] += 1 11 | 12 | for i in range(1, n + 1): 13 | if m[i] == n - 1 and i not in m_: 14 | return i 15 | 16 | return -1 17 | -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Find the Town Judge 2 | 3 | # Solution 4 | 5 | ## 1 6 | 7 | 1. 使用兩個 Map 來分別儲存 8 | - 每個人信任哪些人 9 | - 每個人被幾個人信任 10 | 2. 交叉比對即可 11 | 12 | ## 2 13 | 14 | 1. 如果 n 為 1 則直接回傳 1 15 | 2. 建立一個陣列來儲存每個人的狀態 16 | 3. 跑迴圈 17 | - 如果有被信任的人就要 `+1` 18 | - 如果有信任別人就 指定為 `Infinity` 19 | 4. 最後回傳該陣列裡的值是 n - 1 的 `index` 20 | -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/Kevin/solution-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @param {number[][]} trust 4 | * @return {number} 5 | */ 6 | var findJudge = function (n, trust) { 7 | if (n === 1) return 1; 8 | const qualify = new Array(n + 1).fill(0); 9 | trust.forEach(each => { 10 | const [trustSb, beTrusted] = each; 11 | qualify[trustSb] = -Infinity; 12 | qualify[beTrusted] += 1; 13 | }); 14 | return qualify.indexOf(n - 1); 15 | }; 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: create dict first, (1). judge can't trust anyone, remove key. (2). add 1 if be trusted. (3). check if there's only one judge and the value should be n-1 (n ppl trust the judge), otherwise return -1. 2 | 3 | 4 | ![][fig] 5 | 6 | [fig]:./fig/fig1.png 7 | 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-22 (day35)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-22 (day35)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function maxProfit(prices: number[]): number { 2 | let maxCur:number = 0; 3 | let maxSoFar: number = 0; 4 | for(let i = 1;iprices[i]) min=prices[i] 7 | else profit=Math.max(profit,prices[i]-min) 8 | } 9 | return profit 10 | } -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | function maxProfit(prices) { 6 | let min = Infinity; 7 | let profit = 0; 8 | 9 | for (const price of prices) { 10 | if (min > price) min = price; 11 | 12 | if (price - min > profit) profit = price - min; 13 | } 14 | 15 | return profit; 16 | } 17 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Husky/README.md: -------------------------------------------------------------------------------- 1 | #### solution 2 2 | 3 | #### Kadane’s Algorithm 4 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Husky/solution_1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | valley = 10**4 + 1 4 | max_ = 0 5 | 6 | for i in range(0, len(prices)): 7 | if prices[i] < valley: 8 | valley = prices[i] 9 | elif (prices[i] - valley) > max_: 10 | max_ = prices[i] - valley 11 | return max_ 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Husky/solution_2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | local_diff = 0 4 | global_diff = float('-inf') 5 | 6 | if len(prices) <= 1: 7 | return 0 8 | 9 | for i in range(1, len(prices)): 10 | local_diff = max(0, local_diff + prices[i] - prices[i-1]) 11 | if local_diff > global_diff: 12 | global_diff = local_diff 13 | 14 | return global_diff 15 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Best Time to Buy and Sell Stock 2 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function (prices) { 6 | let [minPointer, profit] = [0, 0]; 7 | prices.forEach((each, index) => { 8 | if (each - prices[minPointer] > profit) { 9 | profit = each - prices[minPointer]; 10 | } 11 | if (each < prices[minPointer]) { 12 | minPointer = index; 13 | } 14 | }); 15 | return profit; 16 | }; 17 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Keep tracking the historical minumim value, test if current value yields a higher value, if so, save it to the result. 2 | 3 | #### complexity: O(N) 4 | 5 | ![][fig] 6 | 7 | [fig]:./fig/fig1.png 8 | 9 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-23 (day36)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | res = 0 4 | min_v = 1e4 5 | for p in prices: 6 | min_v = min([min_v,p]) 7 | tmp = p - min_v 8 | if tmp > res: 9 | res = tmp 10 | return res 11 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day-36: [EASY] 121. Best Time to Buy and Sell Stock
2 |
3 | solution:
4 | let min be the smallest,
5 | and for loop array find (the element - the smallest) is the largest will become answer 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-23 (day36)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function (prices) { 6 | let min = prices[0] 7 | let max = 0 8 | prices.forEach(el => { 9 | if (el < min) min = el 10 | if (el - min > max) max = el - min 11 | }) 12 | return max 13 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Solution -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function(prices) { 6 | let sum = 0; 7 | for(i=0;i 0) profit += diff; 12 | } 13 | 14 | return profit; 15 | } 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | profit = 0 4 | 5 | for i in range(1, len(prices)): 6 | if prices[i] - prices[i - 1] > 0: 7 | profit += prices[i] - prices[i - 1] 8 | 9 | return profit 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Best Time to Buy and Sell Stock II 2 | 3 | ## Solution 4 | 5 | Greedy! 6 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function (prices) { 6 | let result = 0; 7 | 8 | for (let i = 1; i < prices.length; i++) { 9 | if (prices[i] > prices[i - 1]) { 10 | result += prices[i] - prices[i - 1]; 11 | } 12 | } 13 | return result; 14 | }; 15 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Buy low, sell high. Find the minimum point first, once it's done, go ahead and find the peak. Sum all the min-peak segments. 2 | 3 | 4 | ![][fig] 5 | 6 | [fig]:./fig/fig1.png 7 | 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-24 (day37)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day-37: [EASY] 122. Best Time to Buy and Sell Stock II
2 |
3 | solution:
4 | beacause must sell the stock before buy again,
5 | so for loop the element find if buy today and sell to next day is more than 0 add up them
6 | -------------------------------------------------------------------------------- /2021-08/2021-08-24 (day37)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function (prices) { 6 | let profit = 0 7 | prices.forEach((el, index) => { 8 | if (prices[index + 1]) { 9 | let transactions = prices[index + 1] - el 10 | if (transactions > 0) profit += transactions 11 | } 12 | }) 13 | return profit 14 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | function climbStairs(n, dp = [undefined, 1, 2]) { 6 | dp[n] ||= climbStairs(n - 1, dp) + climbStairs(n - 2, dp); 7 | 8 | return dp[n]; 9 | } 10 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Hsuky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def climbStairs(self, n: int) -> int: 3 | memo = {} 4 | 5 | def recursion(n): 6 | if n <= 2: 7 | return n 8 | 9 | if n not in memo: 10 | memo[n] = recursion(n - 1) + recursion(n - 2) 11 | return memo[n] 12 | 13 | return recursion(n) 14 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Climbing Stairs -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var climbStairs = function(n) { 6 | return helper(n, []) 7 | }; 8 | 9 | function helper(n, cache){ 10 | if(cache[n]){ 11 | return cache[n] 12 | } 13 | if(n === 1) cache[n] = 1 14 | else if(n === 2) cache[n] = 2 15 | else cache[n] = helper(n-2, cache) + helper(n-1, cache) 16 | return cache[n] 17 | } -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Ways to climb (N) steps = to climb (N-1) steps + (N-2) steps. It's Fibonacci sequence. 2 | 3 | 4 | ![][fig] 5 | 6 | [fig]:./fig/fig1.png 7 | 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-26 (day39)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def climbStairs(self, n: int) -> int: 3 | 4 | prev = 0 5 | cur = 1 6 | for i in range(n): 7 | tmp = cur 8 | cur = prev+cur 9 | prev = tmp 10 | return cur 11 | 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/White/climbing_stairs.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def climbStairs(self, n: int) -> int: 3 | if n <= 2: 4 | return n 5 | 6 | a, b, res = 1, 1, 2 7 | for i in range(1, n-1): 8 | a, b = b, res 9 | res = a + b 10 | return res 11 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day-39: [EASY] 70. Climbing Stairs
2 |
3 | solution:
4 | use Fibonacci Sequence formula solution and math is in '2021-08-26(day39)/haha/公式解.png' 5 | -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var climbStairs = function (n) { 6 | if (n < 2) return n 7 | let ratio = (1 + Math.sqrt(5)) / 2 8 | let ratioAlt = (1 - Math.sqrt(5)) / 2 9 | return (Math.pow(ratio, n + 1) - Math.pow(ratioAlt, n + 1)) / Math.sqrt(5) 10 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-26 (day39)/haha/公式解.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-26 (day39)/haha/公式解.png -------------------------------------------------------------------------------- /2021-08/2021-08-27 (day40)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function minCostClimbingStairs(cost: number[]): number { 2 | let minCost = 0; 3 | let cost1StepBefore = cost[1]; 4 | let cost2StepBefore = cost[0]; 5 | for (let i = 2; i < cost.length; i++) { 6 | minCost = Math.min(cost1StepBefore, cost2StepBefore) + cost[i]; 7 | cost2StepBefore = cost1StepBefore; 8 | cost1StepBefore = minCost; 9 | } 10 | return Math.min(cost1StepBefore, cost2StepBefore); 11 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-27 (day40)/Hello/dp.js: -------------------------------------------------------------------------------- 1 | const { min } = Math; 2 | 3 | /** 4 | * @param {number[]} cost 5 | * @return {number} 6 | */ 7 | function minCostClimbingStairs(cost) { 8 | const dp = [cost[0], cost[1]]; 9 | 10 | for (let index = 2; index <= cost.length; index++) { 11 | const current = cost[index] || 0; 12 | 13 | dp[index] = current + min(dp[index - 2], dp[index - 1]); 14 | } 15 | 16 | return dp[cost.length]; 17 | } 18 | -------------------------------------------------------------------------------- /2021-08/2021-08-27 (day40)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostClimbingStairs(self, cost: List[int]) -> int: 3 | dp = [0]*(len(cost)+1) 4 | 5 | if len(cost) > 2: 6 | for i in range(2, len(cost)+1): 7 | dp[i] = min(dp[i-2] + cost[i-2], dp[i-1] + cost[i-1]) 8 | else: 9 | dp[2] = min(cost[0], cost[1]) 10 | 11 | return dp[-1] 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-27 (day40)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Min Cost Climbing Stairs 2 | 3 | # Submissions 4 | 5 | Runtime: 145 ms, faster than 10.00% of TypeScript online submissions for Min Cost Climbing Stairs. 6 | 7 | Memory Usage: 40.4 MB, less than 95.00% of TypeScript online submissions for Min Cost Climbing Stairs. -------------------------------------------------------------------------------- /2021-08/2021-08-27 (day40)/Kevin/solution.ts: -------------------------------------------------------------------------------- 1 | function minCostClimbingStairs(cost: number[]): number { 2 | const dp: number[] = [0,0] 3 | for(let i = 2; i int: 3 | 4 | sum_cost2 = cost[0] # two steps before the current point 5 | sum_cost1 = cost[1] # one step 6 | 7 | for i in range(2,len(cost)): 8 | tmp = sum_cost1 9 | sum_cost1 = cost[i] + min(sum_cost1,sum_cost2) 10 | sum_cost2 = tmp 11 | 12 | return min(sum_cost1,sum_cost2) 13 | -------------------------------------------------------------------------------- /2021-08/2021-08-28 (day41)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {boolean} 4 | */ 5 | function canJump(nums, current = nums.length - 1, dp = nums.length - 1) { 6 | if (current === 0) return dp === 0; 7 | 8 | current -= 1; 9 | 10 | if (current + nums[current] >= dp) { 11 | dp = current; 12 | } 13 | 14 | return canJump(nums, current, dp); 15 | } 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-28 (day41)/Husky/solution_2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canJump(self, nums: List[int]) -> bool: 3 | n = len(nums) 4 | if n == 1: 5 | return True 6 | 7 | last = n - 1 8 | 9 | for i in range(n - 2, -1, -1): 10 | if nums[i] + i >= last: 11 | last = i 12 | 13 | return last == 0 14 | -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function generate(numRows: number): number[][] { 2 | let result: number[][] = new Array(); 3 | for (let i = 0; i < numRows; i += 1) { 4 | result[i] = new Array(); 5 | result[i][0] = 1; 6 | result[i][i] = 1; 7 | 8 | let row: number[] = new Array(); 9 | for (let j = 1; j < i; j += 1) { 10 | result[i][j] = result[i - 1][j - 1] + result[i - 1][j]; 11 | } 12 | } 13 | return result; 14 | }; -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generate(self, numRows: int) -> List[List[int]]: 3 | output = [[1], [1, 1]] 4 | 5 | for i in range(2, numRows): 6 | curr = [1] + \ 7 | [output[-1][j - 1] + output[-1][j] for j in range(1, i)] + \ 8 | [1] 9 | output.append(curr) 10 | 11 | return output[:numRows] 12 | -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Pascal's Triangle 2 | -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: (a) Edges should be 1, and (b) middle = sum of the upper layer. 2 | 3 | 4 | ![][fig] 5 | 6 | [fig]:./fig/fig1.png 7 | 8 | -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-08/2021-08-30 (day43)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-08/2021-08-30 (day43)/caaaaat/README.md: -------------------------------------------------------------------------------- 1 | 118. Pascal's Triangle 2 | 3 | solution 4 | 5 | -------------------------------------------------------------------------------- /2021-08/2021-08-31 (day44)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function getRow(rowIndex: number): number[] { 2 | let result: number[] = new Array(); 3 | for(let i=0;i<=rowIndex;i+=1){ 4 | let temp = 1; 5 | let next = 1; 6 | for(let j = 1;j 0; x--) { 11 | result[x] = result[x - 1] + result[x] || 1; 12 | } 13 | 14 | return getRow(rowIndex, current, result); 15 | } 16 | -------------------------------------------------------------------------------- /2021-08/2021-08-31 (day44)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getRow(self, rowIndex: int) -> List[int]: 3 | pascal = [1, 1] 4 | if rowIndex < 1: 5 | return pascal[:rowIndex - 1] 6 | 7 | for i in range(1, rowIndex): 8 | for j in range(i, 0, -1): 9 | pascal[j] = pascal[j - 1] + pascal[j] 10 | 11 | pascal += [1] 12 | 13 | return pascal 14 | -------------------------------------------------------------------------------- /2021-08/2021-08-31 (day44)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day44: [EASY] 119. Pascal's Triangle II
2 | -------------------------------------------------------------------------------- /2021-09/2021-09-01 (day45)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | function divisorGame(n) { 6 | return n % 2 === 0; 7 | } 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-01 (day45)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | var divisorGame = function(n) { 2 | if (n % 2 === 0) { 3 | return true; 4 | } 5 | return false; 6 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-01 (day45)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divisorGame(self, n: int) -> bool: 3 | return ~n%2 4 | -------------------------------------------------------------------------------- /2021-09/2021-09-01 (day45)/caaaaat/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean divisorGame(int n) { 3 | boolean[] dp = new boolean[n+1]; 4 | for (int i = 2; i <= n; i++) { 5 | for (int j = 1; j < i; j++) { 6 | if (i % j != 0) continue; 7 | if (!dp[i - j]) { 8 | dp[i] = true; 9 | break; 10 | } 11 | } 12 | } 13 | return dp[n]; 14 | } 15 | } -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | # Solution -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function(s, t) { 7 | const sArray = s.split(''); 8 | const tArray = t.split(''); 9 | const sArraySort = sArray.sort().toString(); 10 | const tArraySort = tArray.sort().toString(); 11 | if (sArraySort === tArraySort) { 12 | return true; 13 | } else { 14 | return false; 15 | } 16 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Erica/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function(s, t) { 7 | const compareString = [...s].filter((item) => [...t].indexOf(item) > -1) 8 | return compareString.length === s.length ? true : false 9 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAnagram(self, s: str, t: str) -> bool: 3 | return sorted(s) == sorted(t) 4 | -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Kevin/solution2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function (s, t) { 7 | return sort(s) === sort(t); 8 | }; 9 | 10 | function sort(str) { 11 | return str.split("").sort().join(""); 12 | } 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function(s, t) { 7 | const refactorS = s.split("").sort().join(); 8 | const refacotrT = t.split("").sort().join(); 9 | if (refactorS === refacotrT) { 10 | return true; 11 | } 12 | return false; 13 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day46: [EASY] 242. Valid Anagram
2 |
3 | solution for ascii-solution:
4 | if two strings length is not same early return false,
5 | else compare sum of two strings ascii code whether same 6 | 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-02 (day46)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function(s, t) { 7 | return s.split("").sort().join() === t.split("").sort().join() 8 | } -------------------------------------------------------------------------------- /2021-09/2021-09-03 (day47)/Kevin/images/solution.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-03 (day47)/Kevin/images/solution.jpg -------------------------------------------------------------------------------- /2021-09/2021-09-04 (day48)/kevin/README.md: -------------------------------------------------------------------------------- 1 | # Isomorphic Strings 2 | 3 | ## Solution 4 | 5 | 1. 跑迴圈 6 | 2. 在每一個索引,取得當前字母 "之前的子字串" 是否有出現過 (indexOf),比對兩字串得到的結果,有不同則 false,走完則 true 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-05 (day49)/kevin/README.md: -------------------------------------------------------------------------------- 1 | # Word Pattern 2 | 3 | ## Solution 4 | 5 | 跟昨天的一樣,用 hash map 來紀錄,用兩個 map 分別記錄 pattern 可以避免有相同字串重複使用的狀況。 6 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function majorityElement(nums: number[]): number { 2 | interface count { 3 | [key: number]: number; 4 | } 5 | 6 | let countMap = {}; 7 | let majorLength = nums.length/2; 8 | 9 | for(let num of nums){ 10 | if(!countMap[num]) countMap[num] = 0; 11 | countMap[num]+=1; 12 | if(countMap[num] > majorLength) return num; 13 | } 14 | return 0; 15 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Alpha/README.md: -------------------------------------------------------------------------------- 1 | ## solution -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Alpha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var majorityElement = function(nums) { 6 | let maxNum = 0; 7 | let maxEl = 0; 8 | let obj = {}; 9 | nums.forEach((item) => { 10 | obj[item] ? obj[item]+=1 : obj[item] = 1; 11 | }) 12 | 13 | for (let num in obj) { 14 | if ( obj[num] > maxNum ) { 15 | maxNum = obj[num]; 16 | maxEl = num; 17 | } 18 | } 19 | return maxEl; 20 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | function majorityElement(nums) { 6 | nums.sort((a, b) => a - b); 7 | 8 | return nums[Math.floor(nums.length / 2)]; 9 | } 10 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def majorityElement(self, nums: List[int]) -> int: 3 | if len(nums) == 1: 4 | return nums[0] 5 | 6 | hash_count = {} 7 | half = len(nums)//2 8 | for n in nums: 9 | if n in hash_count: 10 | hash_count[n] += 1 11 | if hash_count[n] > half: 12 | return n 13 | else: 14 | hash_count[n] = 1 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Majority Element 2 | 3 | ## Submissions 4 | 5 | Runtime: 80 ms, faster than 70.76% of JavaScript online submissions for Majority Element. 6 | Memory Usage: 41.1 MB, less than 82.64% of JavaScript online submissions for Majority Element. 7 | 8 | ## Solution 9 | 10 | 使用 Hash map,存入各個數字的出現次數,再取最大值即可 11 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/Shaun/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int majorityElement(int[] nums) { 3 | int majorNum=0; 4 | int record=0; 5 | 6 | HashMap dict = new HashMap(); 7 | for(int i:nums){ 8 | if(dict.containsKey(i)){ 9 | dict.replace(i, dict.get(i)+1); 10 | }else dict.put(i, 1); 11 | 12 | if(dict.get(i)>record){ 13 | record=dict.get(i); 14 | majorNum=i; 15 | } 16 | } 17 | return majorNum; 18 | } 19 | } -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 統計兩個list裡元素的數量,傳回過半數者。 3 | 4 | # leetcode 5 | Runtime: 164 ms, faster than 76.79% of Python3 online submissions for Majority Element. 6 | Memory Usage: 15.5 MB, less than 83.02% of Python3 online submissions for Majority Element. 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/White/majority_element.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def majorityElement(self, nums: List[int]) -> int: 3 | 4 | half = len(nums)//2 5 | 6 | for k,v in Counter(nums).items(): 7 | if v > half: 8 | return k -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day50: [EASY] 169. Majority Element
2 |
3 | solution:
4 | use hash table look at whether exist,
5 | true is add 1 , false is 1 , and return largest of them sum 6 | 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-06 (day50)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var majorityElement = function(nums) { 6 | let hash = {} 7 | nums.forEach((el)=>{ 8 | hash[el] ? hash[el]+=1 : hash[el] = 1 9 | }) 10 | let max = Math.max(...Object.values(hash)) 11 | return getKeyByValue(hash, max) 12 | }; 13 | 14 | function getKeyByValue(obj, val) { 15 | return Object.keys(obj).find(key => obj[key] === val); 16 | } -------------------------------------------------------------------------------- /2021-09/2021-09-07 (day51)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums1 3 | * @param {number[]} nums2 4 | * @return {number[]} 5 | */ 6 | function intersect(nums1, nums2) { 7 | const result = []; 8 | 9 | for (const num of nums2) { 10 | const index = nums1.indexOf(num); 11 | 12 | if (index !== -1) { 13 | result.push(num); 14 | 15 | nums1.splice(index, 1); 16 | } 17 | } 18 | 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /2021-09/2021-09-07 (day51)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums1 3 | * @param {number[]} nums2 4 | * @return {number[]} 5 | */ 6 | var intersect = function (nums1, nums2) { 7 | const result = []; 8 | for (num of nums1) { 9 | const repeatNum = nums2.indexOf(num); 10 | if (repeatNum !== -1) { 11 | result.push(nums2.splice(repeatNum, 1)); 12 | } 13 | } 14 | return result; 15 | }; 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-07 (day51)/Shaun/README.md: -------------------------------------------------------------------------------- 1 | # 350. Intersection of Two Arrays II 2 | 3 | `Easy` 4 | 5 | ## Time & Space 6 | Runtime: 2 ms, faster than 93.41% of Java online submissions for Intersection of Two Arrays II. 7 | Memory Usage: 39.1 MB, less than 67.41% of Java online submissions for Intersection of Two Arrays II. 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-07 (day51)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 分別統計兩個list裡元素的數量,最後傳回交集的list。 3 | 4 | # leetcode 5 | Runtime: 36 ms, faster than 99.03% of Python3 online submissions for Intersection of Two Arrays II. 6 | Memory Usage: 14.5 MB, less than 11.24% of Python3 online submissions for Intersection of Two Arrays II. 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-07 (day51)/White/intersection_of_2_arrays.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: 3 | result = Counter(nums1) & Counter(nums2) 4 | return list(result.elements()) -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/AGO/solution1.ts: -------------------------------------------------------------------------------- 1 | function plusOne(digits: number[]): number[] { 2 | return add(digits, digits.length -1); 3 | }; 4 | function add(digits: number[], index: number){ 5 | if(index == -1){ 6 | digits.unshift(1) 7 | return digits; 8 | } 9 | digits[index] = (digits[index] + 1) % 10; 10 | if(digits[index] == 0) return add(digits, index-=1); 11 | return digits; 12 | } -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/AGO/solution2.ts: -------------------------------------------------------------------------------- 1 | function plusOne(digits: number[]): number[] { 2 | let add = 1; 3 | let index = digits.length; 4 | while(add){ 5 | index -=1 6 | if(index == -1) digits.unshift(1); 7 | digits[index] = (digits[index] + add) % 10; 8 | add = (digits[index] == 0) ? 1 : 0; 9 | } 10 | return digits; 11 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/Erica/README.md: -------------------------------------------------------------------------------- 1 | # 66. Plus One 2 | 3 | ## Solution 4 | 5 |
 6 | Use BigInt to prevent numbers larger than 2^53.
 7 | Plus one then convert to String and destructure to Array.
 8 | Map to Number each value.
 9 | 
10 | 11 | --- 12 | Runtime: 88 ms, faster than 20.23% of JavaScript online submissions for Plus One. 13 | Memory Usage: 38.7 MB, less than 82.29% of JavaScript online submissions for Plus One. -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/Erica/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} digits 3 | * @return {number[]} 4 | */ 5 | var plusOne = function(digits) { 6 | const num = BigInt(digits.join('')) + 1n 7 | return [...num.toString()].map(Number) 8 | }; 9 | -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} digits 3 | * @return {number[]} 4 | */ 5 | function plusOne(digits) { 6 | const digit = (digits.pop() || 0) + 1; 7 | 8 | return digit <= 9 ? [...digits, digit] : [...plusOne(digits), 0]; 9 | } 10 | -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def plusOne(self, digits: List[int]) -> List[int]: 3 | return [int(s) for s in str(int(''.join([str(i) for i in digits])) + 1)] 4 | -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/White/plus_one.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def plusOne(self, digits: List[int]) -> List[int]: 3 | temp = "".join([str(x) for x in digits]) 4 | n = int(temp) + 1 5 | 6 | return list(str(n)) -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day53: [EASY] 66. Plus One
2 |
3 | solution:
4 | if number more than 2^53 javascript will have a number problem,
5 | so use BigInt() do change number type and sum of them . 6 | 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} digits 3 | * @return {number[]} 4 | */ 5 | var plusOne = function(digits) { 6 | let sum = (BigInt(digits.join('')) + 1n).toString() 7 | return [...sum].map(Number) 8 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-09 (day53)/kevin/README.md: -------------------------------------------------------------------------------- 1 | # Plus One 2 | 3 | ## Submission 4 | 5 | Runtime: 153 ms, faster than 5.12% of TypeScript online submissions for Plus One. 6 | Memory Usage: 39.8 MB, less than 94.88% of TypeScript online submissions for Plus One. -------------------------------------------------------------------------------- /2021-09/2021-09-11 (day55)/haha/README.md: -------------------------------------------------------------------------------- 1 | Day55: [EASY] 150. Evaluate Reverse Polish Notation
2 |
3 | background : https://zh.wikipedia.org/wiki/%E9%80%86%E6%B3%A2%E5%85%B0%E8%A1%A8%E7%A4%BA%E6%B3%95 4 |
5 | solution:
6 | for loop input array and if element in array is operation and calculation in front of elements,
7 | else to push in the table array to wait the input array element is operation. 8 | 9 | 10 | -------------------------------------------------------------------------------- /2021-09/2021-09-12 (day56)/AGO/README.md: -------------------------------------------------------------------------------- 1 | ## My Thought 2 | 3 | ### Step1 4 | 5 | Break down all numbers and operators and spaces first. 6 | Store each of them into an array. 7 | 8 | ### Step2 9 | 10 | Caculate `*` `/` first and push other in stack. 11 | 12 | ### Step3 13 | 14 | Caculate rest of them. -------------------------------------------------------------------------------- /2021-09/2021-09-12 (day56)/Kevin/README.md: -------------------------------------------------------------------------------- 1 | # Basic Calculator II 2 | 3 | ## Submission 4 | 5 | Runtime: 143 ms, faster than 18.47% of JavaScript online submissions for Basic Calculator II. 6 | Memory Usage: 54.2 MB, less than 6.44% of JavaScript online submissions for Basic Calculator II. 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-13 (day57)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 吃不到的情況只發生在食物與人數數量不同時。 3 | 2. 先就食物偏好計算學生人數,再依食物順序遍歷並扣除人數,當食物發不出去時,剩下的就是沒得吃的人數。 4 | 5 | # leecode 提交結果 6 | Runtime: 40 ms, faster than 49.65% of Python3 online submissions for Number of Students Unable to Eat Lunch. 7 | Memory Usage: 14.3 MB, less than 54.00% of Python3 online submissions for Number of Students Unable to Eat Lunch. 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-13 (day57)/White/eat_lunch.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countStudents(self, students: List[int], sandwiches: List[int]) -> int: 3 | xdict = Counter(students) 4 | for s in sandwiches: 5 | if xdict[s] != 0: 6 | xdict[s] -= 1 7 | else: 8 | break 9 | return sum(xdict.values()) -------------------------------------------------------------------------------- /2021-09/2021-09-14 (day58)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {ListNode} head 3 | * @return {boolean} 4 | */ 5 | function isPalindrome(head) { 6 | function traverse(tail) { 7 | if (!tail) { 8 | return true; 9 | } 10 | 11 | if (!traverse(tail.next) || head.val !== tail.val) { 12 | return false; 13 | } 14 | 15 | head = head.next; 16 | 17 | return true; 18 | } 19 | return traverse(head); 20 | } 21 | -------------------------------------------------------------------------------- /2021-09/2021-09-14 (day58)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 因為數值只有個位數,所以將清單裡的值轉出來當作字串,再比對反轉字串是否相等。結果速度很慢。 3 | 4 | # leecode 提交結果 5 | Runtime: 928 ms, faster than 26.30% of Python3 online submissions for Palindrome Linked List. 6 | Memory Usage: 47.3 MB, less than 27.30% of Python3 online submissions for Palindrome Linked List. 7 | -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function simplifyPath(path: string): string { 2 | let paths = path.split('/'); 3 | let pathStack: string[] = new Array(); 4 | for (let i = 0; i < paths.length; i++) { 5 | if (paths[i] === '..') { 6 | pathStack.pop(); 7 | continue; 8 | } 9 | if (paths[i] !== '' && paths[i] !== '.') pathStack.push(paths[i]); 10 | } 11 | 12 | const root = '/'; 13 | return root + pathStack.join('/'); 14 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} path 3 | * @return {string} 4 | */ 5 | function simplifyPath(path) { 6 | return "/" + path.split("/").reduce(process, []).join("/"); 7 | } 8 | 9 | function process(result, token) { 10 | if (!token || token === ".") return result; 11 | 12 | if (token === "..") return result.slice(0, -1); 13 | 14 | return result.concat(token); 15 | } 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def simplifyPath(self, path: str) -> str: 3 | stack = [] 4 | for p in path.split('/'): 5 | if p in ('', '.'): 6 | continue 7 | 8 | if p == '..': 9 | if len(stack) > 0: 10 | stack.pop() 11 | continue 12 | 13 | stack.append(p) 14 | 15 | return '/' + '/'.join(stack) 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | const pathReducer = (acc, locator) => { 2 | if (locator === '' || locator === '.') return acc 3 | if (locator === '..') return acc.slice(0, -1) 4 | return [...acc, locator] 5 | } 6 | 7 | /** 8 | * @param {string} path 9 | * @return {string} 10 | */ 11 | function simplifyPath(path) { 12 | return '/' + path.split('/').reduce(pathReducer, []).join('/') 13 | } 14 | -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/Tim/README.md: -------------------------------------------------------------------------------- 1 | 2 | ![][fig] 3 | 4 | [fig]:./fig/fig1.png 5 | 6 | -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-15 (day59)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 使用stack模擬路徑,遇到`..`時模擬往上一層(即pop),遇到資料夾名稱則加入stack,最後使用加上 `/` 輸出。 3 | 4 | # leecode 提交結果 5 | Runtime: 28 ms, faster than 91.27% of Python3 online submissions for Simplify Path. 6 | Memory Usage: 14.5 MB, less than 14.67% of Python3 online submissions for Simplify Path. -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/White/simplify_path.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def simplifyPath(self, path: str) -> str: 3 | ans = [] 4 | for p in path.split('/'): 5 | if p == '' or p == '.': 6 | continue 7 | elif p == '..': 8 | if ans: 9 | ans.pop() 10 | else: 11 | ans.append(p) 12 | return '/'+'/'.join(ans) -------------------------------------------------------------------------------- /2021-09/2021-09-15 (day59)/aug/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} path 3 | * @return {string} 4 | */ 5 | var simplifyPath = function (path) { 6 | const simplePath = []; 7 | 8 | path.split('/').forEach((subpath) => { 9 | if (!subpath.length || subpath === '.') return; 10 | 11 | subpath === '..' ? simplePath.pop() : simplePath.push(subpath); 12 | }); 13 | 14 | return '/' + simplePath.join('/'); 15 | }; 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | n, m = len(needle), len(haystack) 4 | if n == 0: 5 | return 0 6 | 7 | for i in range(m - n + 1): 8 | if haystack[i: i + n] == needle: 9 | return i 10 | 11 | return -1 12 | -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} haystack 3 | * @param {string} needle 4 | * @return {number} 5 | */ 6 | var strStr = function(haystack, needle) { 7 | if(needle === "") return 0 8 | const target = haystack.split(needle)[0] 9 | return target === haystack ? -1 : target.length 10 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} haystack 3 | * @param {string} needle 4 | * @return {number} 5 | */ 6 | var strStr = function(haystack, needle) { 7 | 8 | if (!needle) { 9 | return 0; 10 | } 11 | 12 | let isInside = haystack.includes(needle); 13 | 14 | if (isInside) { 15 | let splitItem = haystack.split(needle); 16 | return splitItem[0].length; 17 | } 18 | 19 | return -1; 20 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} haystack 3 | * @param {string} needle 4 | * @return {number} 5 | */ 6 | const strStr = (haystack, needle, index = 0) => { 7 | if (!needle) return 0 8 | 9 | if (index >= haystack.length || !haystack || needle.length > haystack.length) return -1 10 | 11 | if (haystack.slice(index, index + needle.length) === needle) return index 12 | 13 | return strStr(haystack, needle, index + 1) 14 | } 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 用切片比對子字串是否存在字串中。 3 | 4 | # leecode 提交結果 5 | Runtime: 140 ms, faster than 12.23% of Python3 online submissions for Implement strStr(). 6 | Memory Usage: 14.4 MB, less than 61.27% of Python3 online submissions for Implement strStr(). 7 | 8 | # find() 9 | ```python 10 | return haystack.find(needle) 11 | ``` -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/White/implement_str.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | if haystack == "": 4 | return 0 if needle == "" else -1 5 | 6 | k = len(needle) 7 | for i in range(len(haystack)): 8 | if i+k > len(haystack): 9 | break 10 | if haystack[i:i+k] == needle: 11 | return i 12 | return -1 -------------------------------------------------------------------------------- /2021-09/2021-09-16 (day60)/aug/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} haystack 3 | * @param {string} needle 4 | * @return {number} 5 | */ 6 | var strStr = function (haystack, needle) { 7 | if (!needle) return 0; 8 | 9 | const firstLength = haystack.split(needle)[0].length; 10 | 11 | if (firstLength === haystack.length) return -1; 12 | 13 | return firstLength; 14 | }; 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} columnNumber 3 | * @return {string} 4 | */ 5 | function convertToTitle(columnNumber) { 6 | columnNumber -= 1; 7 | 8 | const base = 26; 9 | 10 | const char = String.fromCharCode((columnNumber % base) + 65); 11 | 12 | return base > columnNumber 13 | ? char 14 | : convertToTitle(Math.floor(columnNumber / base)) + char; 15 | } 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, columnNumber: int) -> str: 3 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 4 | title = '' 5 | while columnNumber > 0: 6 | temp = columnNumber % 26 7 | if temp == 0: 8 | temp = 26 9 | title = chars[temp - 1] + title 10 | columnNumber = (columnNumber - temp)//26 11 | 12 | return title 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} columnNumber 3 | * @return {string} 4 | */ 5 | const convertToTitle = (columnNumber, result = '') => { 6 | columnNumber-- 7 | const char = String.fromCharCode((columnNumber % 26) + 65) 8 | 9 | if (columnNumber < 26) return char + result 10 | 11 | return convertToTitle(Math.trunc(columnNumber / 26), char + result) 12 | } 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, columnNumber: int) -> str: 3 | table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 4 | 5 | res = [] 6 | while columnNumber>0: 7 | rem = (columnNumber-1) % 26 8 | res.append(table[rem]) 9 | columnNumber = (columnNumber-1)//26 10 | 11 | return ''.join(res[::-1]) 12 | 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/White/excel_sheet_column_title.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, columnNumber: int) -> str: 3 | ans = '' 4 | while columnNumber > 0: 5 | digit = (columnNumber - 1) % 26 6 | ans = chr(digit + 65) + ans 7 | columnNumber = (columnNumber - digit) // 26 8 | return(ans) 9 | -------------------------------------------------------------------------------- /2021-09/2021-09-17 (day61)/caaaaat/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String convertToTitle(int columnNumber) { 3 | StringBuilder sb = new StringBuilder(); 4 | while (columnNumber > 0) { 5 | columnNumber--; 6 | sb.append((char)(columnNumber % 26 + 'A')); 7 | columnNumber = columnNumber / 26; 8 | } 9 | sb.reverse(); 10 | return sb.toString(); 11 | } 12 | } -------------------------------------------------------------------------------- /2021-09/2021-09-18 (day62)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | class RecentCounter { 2 | pings: number[]; 3 | 4 | constructor() { 5 | this.pings = new Array(); 6 | } 7 | 8 | ping(t: number): number { 9 | this.pings.push(t); 10 | 11 | while (this.pings[0] < t - 3000) { 12 | this.pings.shift(); 13 | } 14 | 15 | return this.pings.length; 16 | } 17 | } -------------------------------------------------------------------------------- /2021-09/2021-09-18 (day62)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | function RecentCounter() { 2 | const past = []; 3 | 4 | /** 5 | * @param {number} t 6 | * @return {number} 7 | */ 8 | function ping(t) { 9 | past.push(t); 10 | 11 | while (past[0] < t - 3000) { 12 | past.shift(); 13 | } 14 | 15 | return past.length; 16 | } 17 | 18 | return { ping }; 19 | } 20 | -------------------------------------------------------------------------------- /2021-09/2021-09-18 (day62)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | class RecentCounter { 2 | queue = [] 3 | ping = t => { 4 | this.queue.push(t) 5 | this.queue.splice(0, this.queue.findIndex(val => t - val <= 3000)) 6 | return this.queue.length 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2021-09/2021-09-18 (day62)/caaaaat/solution.java: -------------------------------------------------------------------------------- 1 | class RecentCounter { 2 | List list; 3 | public RecentCounter() { 4 | list = new ArrayList(); 5 | } 6 | public int ping(int t) { 7 | list.add(t); 8 | int min = t-3000; 9 | int count = 0; 10 | for (Integer num : list) { 11 | if (num >= min && num <= t) { 12 | count++; 13 | } 14 | } 15 | return count; 16 | } 17 | } -------------------------------------------------------------------------------- /2021-09/2021-09-22 (day65)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function countBits(n: number): number[] { 2 | let result: number[] = [0]; 3 | let exp: number = 0; 4 | let lower = Math.pow(2, exp); 5 | let upper = Math.pow(2, exp + 1); 6 | 7 | for (let i = 1; i <= n; i += 1) { 8 | if (i == upper) { 9 | exp += 1; 10 | lower = Math.pow(2, exp); 11 | upper = Math.pow(2, exp + 1) 12 | } 13 | result.push(result[i - lower] + 1); 14 | } 15 | return result; 16 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-22 (day65)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number[]} 4 | */ 5 | function countBits(n) { 6 | const DP = Array(n + 1).fill(0); 7 | let offset = 1; 8 | 9 | for (let index = 1; index <= n; index++) { 10 | if (offset * 2 === index) { 11 | offset = index; 12 | } 13 | 14 | DP[index] = 1 + DP[index - offset]; 15 | } 16 | 17 | return DP; 18 | } 19 | -------------------------------------------------------------------------------- /2021-09/2021-09-22 (day65)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countBits(self, n: int) -> List[int]: 3 | # 1, 2, 4, 8, 16, 32 4 | res = [0]*(n+1) 5 | two_exp = 1 6 | for i in range(1, n + 1): 7 | if i == two_exp*2: 8 | two_exp = i 9 | res[i] = res[i - two_exp] + 1 10 | 11 | return res 12 | -------------------------------------------------------------------------------- /2021-09/2021-09-22 (day65)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number[]} 4 | */ 5 | const countBits = function (num) { 6 | return Array(num + 1) 7 | .fill(0) 8 | .map((n, i) => i.toString(2).match(/1/g)?.length || 0) 9 | } 10 | -------------------------------------------------------------------------------- /2021-09/2021-09-22 (day65)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number[]} 4 | */ 5 | var countBits = function(n) { 6 | let arr = [0] 7 | for(let i=1; i bool: 3 | for t_ in t: 4 | if s == '': 5 | return True 6 | 7 | if t_ == s[0]: 8 | s = s[1:] 9 | 10 | return s == '' 11 | -------------------------------------------------------------------------------- /2021-09/2021-09-23 (day66)/Kevin/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isSubsequence = function (s, t) { 7 | if (!s) return true; 8 | let i = -1; 9 | for (val of t) { 10 | if (val === s[i + 1]) i++; 11 | if (s.length === i + 1) return true; 12 | } 13 | return false; 14 | }; 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-23 (day66)/Sid/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | const isSubsequence = (s, t) => { 7 | if (s.length > t.length) return false 8 | if (!s) return true 9 | 10 | if (t.charAt(0) === s.charAt(0)) s = s.substring(1) 11 | return isSubsequence(s, t.substring(1)) 12 | } 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-23 (day66)/White/README.md: -------------------------------------------------------------------------------- 1 | ## 解題想法 2 | 依序將t字串與s字串做比較,一旦s字串順利讀完,就表示該字串存在於t字串中。 3 | 4 | ## leetcode 提交結果 5 | Runtime: 24 ms, faster than 97.43% of Python3 online submissions for Is Subsequence. 6 | Memory Usage: 14.2 MB, less than 91.34% of Python3 online submissions for Is Subsequence. -------------------------------------------------------------------------------- /2021-09/2021-09-23 (day66)/White/is_subsequence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSubsequence(self, s: str, t: str) -> bool: 3 | if s == '': 4 | return True 5 | 6 | i = 0 7 | for c in t: 8 | if c == s[i]: 9 | i += 1 10 | 11 | if i == len(s): 12 | return True 13 | 14 | return False -------------------------------------------------------------------------------- /2021-09/2021-09-24 (day67)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function getMaximumGenerated(n: number): number { 2 | if(n == 0) return 0; 3 | 4 | let max = 1; 5 | let nums = [0, 1]; 6 | 7 | for(let i = 2;i <= n; i += 1 ){ 8 | const half = Math.trunc(i / 2); 9 | nums[i] = i % 2 == 0 ? nums[half] : nums[half] + nums[half + 1]; 10 | max = Math.max(max, nums[i]); 11 | } 12 | return max; 13 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-24 (day67)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | function getMaximumGenerated(n, i = 1, nums = [0, 1]) { 6 | if (n < i) return 0; 7 | 8 | if (2 * i + 1 > n) return Math.max(...nums); 9 | 10 | nums[2 * i] = nums[i]; 11 | nums[2 * i + 1] = nums[i] + nums[i + 1]; 12 | 13 | return getMaximumGenerated(n, i + 1, nums); 14 | } 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-24 (day67)/Tim/README.md: -------------------------------------------------------------------------------- 1 | ![][fig] 2 | 3 | [fig]:./fig/fig1.png 4 | 5 | -------------------------------------------------------------------------------- /2021-09/2021-09-24 (day67)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-24 (day67)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-09/2021-09-24 (day67)/kevin/README.md: -------------------------------------------------------------------------------- 1 | # Get Maximum in Generated Array 2 | 3 | ## Submission 4 | 5 | Runtime: 80 ms, faster than 45.74% of JavaScript online submissions for Get Maximum in Generated Array. 6 | Memory Usage: 39.1 MB, less than 29.15% of JavaScript online submissions for Get Maximum in Generated Array. -------------------------------------------------------------------------------- /2021-09/2021-09-25 (day68)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | function factorial(n) { 2 | if (n === 0) return 0; 3 | if (n === 1) return 1; 4 | return n * factorial(n - 1); 5 | } 6 | 7 | /** 8 | * @param {number} m 9 | * @param {number} n 10 | * @return {number} 11 | */ 12 | function uniquePaths(m, n) { 13 | const [a, b] = [m - 1, n - 1]; 14 | 15 | if (a === 0 || b === 0) return 1; 16 | 17 | return factorial(a + b) / (factorial(a) * factorial(b)); 18 | } 19 | -------------------------------------------------------------------------------- /2021-09/2021-09-25 (day68)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniquePaths(self, m: int, n: int) -> int: 3 | dp = [[1 if j == 0 or i == 0 else 0 for i in range(n)] for j in range(m)] 4 | 5 | for j in range(1, m): 6 | for i in range(1, n): 7 | dp[j][i] = dp[j - 1][i] + dp[j][i - 1] 8 | 9 | return dp[-1][-1] 10 | -------------------------------------------------------------------------------- /2021-09/2021-09-25 (day68)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: recursion + memorization 2 | 3 | * Path to (m,n) = path to (m-1,n) + (m,n-1) 4 | 5 | * When m or n = 1, there is only 1 way to move. 6 | 7 | ![][fig] 8 | 9 | [fig]:./fig/fig1.png 10 | 11 | -------------------------------------------------------------------------------- /2021-09/2021-09-25 (day68)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-25 (day68)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-09/2021-09-25 (day68)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniquePaths(self, m: int, n: int) -> int: 3 | 4 | memo = {} 5 | def set_move(m,n): 6 | if m==1 or n==1: 7 | return 1 8 | if (m,n) in memo: 9 | return memo[(m,n)] 10 | 11 | memo[(m,n)] = set_move(m-1,n) + set_move(m,n-1) 12 | return memo[(m,n)] 13 | 14 | 15 | return set_move(m,n) 16 | 17 | -------------------------------------------------------------------------------- /2021-09/2021-09-26 (day69)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[][]} triangle 3 | * @return {number} 4 | */ 5 | function minimumTotal(triangle, DP = triangle.shift()) { 6 | if (!triangle.length) return Math.min(...DP); 7 | 8 | DP = triangle.shift().map( 9 | (num, x) => 10 | num + 11 | Math.min( 12 | DP[x - 1] ?? Infinity, 13 | DP[x] ?? Infinity 14 | // 15 | ) 16 | ); 17 | 18 | return minimumTotal(triangle, DP); 19 | } 20 | -------------------------------------------------------------------------------- /2021-09/2021-09-27 (day70)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function maxSubArray(nums: number[]): number { 2 | for (let i = 1; i < nums.length; i++) { 3 | if (nums[i - 1] > 0) { 4 | nums[i] += nums[i - 1]; 5 | } 6 | } 7 | return Math.max(...nums); 8 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-27 (day70)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | function maxSubArray(nums) { 6 | let prev = 0; 7 | let max = -Infinity; 8 | 9 | for (const num of nums) { 10 | prev = Math.max(num, prev + num); 11 | max = Math.max(prev, max); 12 | } 13 | 14 | return max; 15 | } 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-27 (day70)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSubArray(self, nums: List[int]) -> int: 3 | right = nums[0] 4 | max_sum = nums[0] 5 | 6 | for n in nums[1:]: 7 | right = max(n, right + n) 8 | max_sum = max(max_sum, right) 9 | 10 | return max_sum 11 | -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function arrayPairSum(nums: number[]): number { 2 | let result = 0; 3 | 4 | nums.sort((a,b) => a-b); 5 | while(nums.length != 0){ 6 | result += Math.min(nums.shift(), nums.shift()); 7 | } 8 | return result; 9 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | function arrayPairSum(nums) { 6 | nums = nums.sort((a, b) => a - b); 7 | 8 | let sum = 0; 9 | 10 | for (let index = 0; index < nums.length; index += 2) { 11 | sum += Math.min(nums[index], nums[index + 1]); 12 | } 13 | 14 | return sum; 15 | } 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayPairSum(self, nums: List[int]) -> int: 3 | nums = sorted(nums) 4 | return sum([nums[i] for i in range(0, len(nums), 2)]) 5 | -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var arrayPairSum = function(nums) { 6 | 7 | let maxSum = 0 8 | 9 | nums.sort((a, b) => a - b); 10 | 11 | for (let i = 0 ; i < nums.length ; i+=2) { 12 | maxSum = maxSum + nums[i]; 13 | } 14 | 15 | return maxSum; 16 | }; -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayPairSum(self, nums: List[int]) -> int: 3 | 4 | nums.sort() 5 | 6 | res = 0 7 | for i in range(0,len(nums),2): 8 | res += nums[i] 9 | 10 | return res 11 | 12 | -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 總資料排序後取奇數值,相當於於兩兩成對取min值,可達到加總最大。 3 | 4 | # leetcode 提交結果 5 | Runtime: 260 ms, faster than 83.19% of Python3 online submissions for Array Partition I. 6 | Memory Usage: 16.9 MB, less than 29.29% of Python3 online submissions for Array Partition I. 7 | 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-28 (day71)/White/array_partition1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayPairSum(self, nums: List[int]) -> int: 3 | ans = 0 4 | for i,v in enumerate(sorted(nums)): 5 | if i%2 == 0: 6 | ans += v 7 | return ans 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-29 (day72)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | function permute(nums, current = [], result = []) { 2 | if (nums.length === current.length) { 3 | result.push(current); 4 | 5 | return []; 6 | } 7 | 8 | const rest = nums.filter((num) => !current.includes(num)); 9 | 10 | for (const num of rest) { 11 | permute(nums, [...current, num], result); 12 | } 13 | 14 | return result; 15 | } 16 | -------------------------------------------------------------------------------- /2021-09/2021-09-29 (day72)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def permute(self, nums: List[int], prefix = []) -> List[List[int]]: 3 | res = [] 4 | if len(nums) == 1: 5 | res.append(prefix + [nums[0]]) 6 | 7 | for i in range(len(nums)): 8 | nums_ = nums[:] 9 | temp = prefix + [nums_.pop(i)] 10 | 11 | sub_res = self.permute(nums_, temp) 12 | res += sub_res 13 | 14 | return res 15 | -------------------------------------------------------------------------------- /2021-09/2021-09-29 (day72)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Recursion 2 | 3 | 4 | ![][fig] 5 | 6 | [fig]:./fig/fig1.png 7 | 8 | -------------------------------------------------------------------------------- /2021-09/2021-09-29 (day72)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-29 (day72)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-09/2021-09-29 (day72)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題參考自解答 2 | 1. 使用兩個指標 start 跟 i,i 與 start 交換,即可遍歷所有排列可能。 3 | 2. 每算出一個結果後要將nums回到前次狀態,否則會出錯。 4 | 5 | # leetcode 提交結果 6 | Runtime: 28 ms, faster than 99.50% of Python3 online submissions for Permutations. 7 | Memory Usage: 14.4 MB, less than 41.73% of Python3 online submissions for Permutations. -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def letterCasePermutation(self, s: str) -> List[str]: 3 | a_z = 'abcdefghijklmnopqrstuvwxyz' 4 | res = [''] 5 | s = s.lower() 6 | for s_ in s: 7 | if s_ in a_z: 8 | res = [r+s_ for r in res] + [r+s_.upper() for r in res] 9 | else: 10 | res = [r+s_ for r in res] 11 | 12 | return res 13 | -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Two solutions are provided. 2 | 3 | * 1. Loop the s, duplicate the res list when s is an alphabet i.e. lower and capital. 4 | 5 | * 2. Recursion. 6 | 7 | 8 | ![][fig] 9 | 10 | [fig]:./fig/fig1.png 11 | 12 | -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-30 (day73)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 每讀到一個英文字,就將ans陣列裡所有資料取出,新增一筆大寫字母記錄,將原有記錄加上小寫字母。 3 | 4 | # leetcode 提交結果 5 | Runtime: 52 ms, faster than 87.54% of Python3 online submissions for Letter Case Permutation. 6 | Memory Usage: 14.7 MB, less than 75.48% of Python3 online submissions for Letter Case Permutation. -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/aug/runtime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-30 (day73)/aug/runtime.png -------------------------------------------------------------------------------- /2021-09/2021-09-30 (day73)/aug/runtime2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-09/2021-09-30 (day73)/aug/runtime2.png -------------------------------------------------------------------------------- /2021-10/2021-10-01 (day74)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[][]} graph 3 | * @return {number[][]} 4 | */ 5 | function allPathsSourceTarget(graph, index = 0, path = [index], paths = []) { 6 | if (index === graph.length - 1) { 7 | paths.push(path); 8 | 9 | return paths; 10 | } 11 | 12 | for (const next of graph[index]) { 13 | allPathsSourceTarget(graph, next, path.concat(next), paths); 14 | } 15 | 16 | return paths; 17 | } 18 | -------------------------------------------------------------------------------- /2021-10/2021-10-01 (day74)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 遞迴將路徑串連起來,當串連到底的時候加到答案list中。 3 | 4 | # leetcode 提交結果 5 | Runtime: 100 ms, faster than 74.01% of Python3 online submissions for All Paths From Source to Target. 6 | Memory Usage: 15.7 MB, less than 25.21% of Python3 online submissions for All Paths From Source to Target. -------------------------------------------------------------------------------- /2021-10/2021-10-01 (day74)/White/allPathsSourceTarget.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: 3 | def dfs(inx, temp): 4 | if inx == len(graph) -1: 5 | ans.append(temp) 6 | else: 7 | for x in graph[inx]: 8 | dfs(x, temp + [x]) 9 | ans = [] 10 | dfs(0, [0]) 11 | return ans 12 | -------------------------------------------------------------------------------- /2021-10/2021-10-02 (day75)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 題目字串的順序對結果沒有影響 3 | 2. 遞迴字母不同數量的排列可能數,加總起來就是答案 4 | 5 | # leetcode 提交結果 6 | Runtime: 100 ms, faster than 65.76% of Python3 online submissions for Letter Tile Possibilities. 7 | Memory Usage: 14.3 MB, less than 81.40% of Python3 online submissions for Letter Tile Possibilities. -------------------------------------------------------------------------------- /2021-10/2021-10-03 (day76)/aug/runtime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-10/2021-10-03 (day76)/aug/runtime.png -------------------------------------------------------------------------------- /2021-10/2021-10-03 (day76)/aug/runtime2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-10/2021-10-03 (day76)/aug/runtime2.png -------------------------------------------------------------------------------- /2021-10/2021-10-04 (day77)/aug/runtime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-10/2021-10-04 (day77)/aug/runtime.png -------------------------------------------------------------------------------- /2021-10/2021-10-04 (day77)/aug/runtime2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-10/2021-10-04 (day77)/aug/runtime2.png -------------------------------------------------------------------------------- /2021-10/2021-10-05 (day78)/AGO/solition.ts: -------------------------------------------------------------------------------- 1 | function findContentChildren(g: number[], s: number[]): number { 2 | let content = 0; 3 | s.sort((a,b)=>a-b); 4 | g.sort((a,b)=>a-b); 5 | 6 | while(s.length > 0){ 7 | if(s[0] >= g[0]){ 8 | content +=1; 9 | g.shift(); 10 | } 11 | s.shift(); 12 | } 13 | return content; 14 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-05 (day78)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findContentChildren(self, g: List[int], s: List[int]) -> int: 3 | g.sort() 4 | s.sort() 5 | 6 | res = 0 7 | i = 0 8 | for g_ in g: 9 | while i < len(s) and s[i] < g_: 10 | i += 1 11 | if i < len(s) and s[i] >= g_: 12 | i += 1 13 | res += 1 14 | 15 | return res 16 | -------------------------------------------------------------------------------- /2021-10/2021-10-05 (day78)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | var findContentChildren = function(g, s) { 2 | // O ( nlog(n) ) 3 | g = g.sort((a, b) => a-b); 4 | s = s.sort((a, b) => a-b); 5 | 6 | let contentChildren = 0; 7 | 8 | // O ( n ) 9 | for (let i = 0 ; i < s.length ; i++) { 10 | if (g[contentChildren] <= s[i]) { 11 | contentChildren++; 12 | } 13 | } 14 | return contentChildren; 15 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-05 (day78)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 題目給的list可能是未排序的,所以先排序。 3 | 2. 拿餅乾跟小孩做比較,餅乾數大於或等於小孩要吃的數量,再換下一個小孩。 4 | 5 | # leetcode 提交結果 6 | Runtime: 152 ms, faster than 94.43% of Python3 online submissions for Assign Cookies. 7 | Memory Usage: 16 MB, less than 69.85% of Python3 online submissions for Assign Cookies. -------------------------------------------------------------------------------- /2021-10/2021-10-05 (day78)/White/findContentChildren.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findContentChildren(self, g: List[int], s: List[int]) -> int: 3 | if len(s) == 0: 4 | return 0 5 | 6 | g.sort() 7 | s.sort() 8 | ans = 0 9 | 10 | for cookie in s: 11 | if cookie >= g[ans]: 12 | ans += 1 13 | if ans >= len(g): 14 | break 15 | return ans -------------------------------------------------------------------------------- /2021-10/2021-10-06 (day79)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: 3 | res = 0 4 | flowerbed = [0] + flowerbed + [0] 5 | 6 | for i in range(1, len(flowerbed) - 1): 7 | if flowerbed[i] == 0 and flowerbed[i - 1] == 0 and flowerbed[i + 1] == 0: 8 | n -= 1 9 | flowerbed[i] = 1 10 | 11 | return res >= n 12 | -------------------------------------------------------------------------------- /2021-10/2021-10-06 (day79)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | var canPlaceFlowers = function(flowerbed, n) { 2 | let count = 0; 3 | 4 | for (let i = 0 ; i < flowerbed.length ; i++) { 5 | if ((!flowerbed[i-1]) && (!flowerbed[i+1]) && (!flowerbed[i])) { 6 | i++; 7 | count++; 8 | } 9 | } 10 | return count >= n; 11 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-06 (day79)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 排除首尾的特例,其他判斷左右皆為0即可種花。 3 | 4 | # leetcode 提交結果 5 | Runtime: 168 ms, faster than 63.44% of Python3 online submissions for Can Place Flowers. 6 | Memory Usage: 14.6 MB, less than 60.46% of Python3 online submissions for Can Place Flowers. -------------------------------------------------------------------------------- /2021-10/2021-10-06 (day79)/haha/README.md: -------------------------------------------------------------------------------- 1 | 2 | [day79][EASY] 605. Can Place Flowers 3 | 4 | solution: 5 | 1. triad of a group, if they are 0 plant a flower -------------------------------------------------------------------------------- /2021-10/2021-10-06 (day79)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} flowerbed 3 | * @param {number} n 4 | * @return {boolean} 5 | */ 6 | var canPlaceFlowers = function(flowerbed, n) { 7 | let times = 0 8 | for (let i = 0; i < flowerbed.length; i++) { 9 | if(!flowerbed[i-1] && !flowerbed[i] && !flowerbed[i+1]) { 10 | times++ 11 | flowerbed.splice(i,1,1) 12 | } 13 | } 14 | return times >= n 15 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-07 (day80)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 先統計出各字元的數量 3 | 2. 如果大於2的奇數,則只取2的倍數部份,例如 5 取 4: 5//2*2 = 4 4 | 3. 若ans為偶數則可將捨去的1加回 5 | 6 | # leetcode 提交結果 7 | Runtime: 32 ms, faster than 80.32% of Python3 online submissions for Longest Palindrome. 8 | Memory Usage: 14.3 MB, less than 22.92% of Python3 online submissions for Longest Palindrome. -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | function balancedStringSplit(s) { 6 | let balance = 0; 7 | let result = 0; 8 | 9 | for (const char of s) { 10 | if (char === "R") { 11 | balance += 1; 12 | } 13 | if (char === "L") { 14 | balance -= 1; 15 | } 16 | if (balance === 0) { 17 | result += 1; 18 | } 19 | } 20 | 21 | return result; 22 | } 23 | -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def balancedStringSplit(self, s: str) -> int: 3 | 4 | counter = 0 5 | res = 0 6 | for char in s: 7 | counter += (1 if char == 'R' else -1) 8 | if counter == 0: 9 | res += 1 10 | 11 | return res 12 | -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | var balancedStringSplit = function(s) { 2 | 3 | let countStack = new Array(2).fill(0); 4 | let pairCount = 0; 5 | 6 | for (let i = 0 ; i < s.length ; i++) { 7 | countStack[s[i] === "L" ? 0 : 1]++; 8 | if (countStack[0] === countStack[1]) { 9 | pairCount++; 10 | countStack = new Array(2).fill(0); 11 | } 12 | } 13 | return pairCount; 14 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 相同數量的L跟R是一組結果,故當L和R數量相同時,答案數加一。 3 | 4 | # leetcode 提交結果 5 | Runtime: 24 ms, faster than 96.79% of Python3 online submissions for Split a String in Balanced Strings. 6 | Memory Usage: 14.1 MB, less than 69.00% of Python3 online submissions for Split a String in Balanced Strings. -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/White/balancedStringSplit.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def balancedStringSplit(self, s: str) -> int: 3 | ans = l = 0 4 | for c in s: 5 | if c == "L": 6 | l += 1 7 | else: 8 | l -= 1 9 | 10 | if l == 0: 11 | ans += 1 12 | 13 | return ans -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/haha/README.md: -------------------------------------------------------------------------------- 1 | 2 | [day81][EASY] 1221. Split a String in Balanced Strings 3 | 4 | solution: 5 | 1. concat R string and L string, when their length are the same, add once group, return group. -------------------------------------------------------------------------------- /2021-10/2021-10-08 (day81)/haha/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | var balancedStringSplit = function(s) { 6 | let Rstr = '' , Lstr = '', group = 0 7 | for(let el of s){ 8 | el === 'R' ? Rstr+=el : Lstr+=el 9 | if(Rstr.length === Lstr.length) { 10 | group++ 11 | Rstr = '' 12 | Lstr = '' 13 | } 14 | } 15 | return group 16 | }; -------------------------------------------------------------------------------- /2021-10/2021-10-10 (day83)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {string} 4 | */ 5 | function largestNumber(nums) { 6 | nums = nums 7 | .map(String) 8 | .sort((a, b) => b + a - (a + b)) 9 | .join(""); 10 | 11 | return nums[0] === "0" ? "0" : nums; 12 | } 13 | -------------------------------------------------------------------------------- /2021-10/2021-10-10 (day83)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | class K(str): 2 | def __lt__(a, b): 3 | return a + b > b + a 4 | 5 | class Solution: 6 | def largestNumber(self, nums: List[int]) -> str: 7 | 8 | nums = sorted([str(n) for n in nums], key = K) 9 | 10 | return '0' if nums[0] == '0' else ''.join(nums) 11 | -------------------------------------------------------------------------------- /2021-10/2021-10-10 (day83)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 將數字轉為字串排序,由大到小接起來 3 | 2. 光以字串排序相加的結果仍不是解答,因為字串排序為 51, 5 但加總最大應為 551 4 | 3. 以迴圈遍歷比較前後大小,若前者加總的結果小於後者,就將兩者交換以求總和最大 5 | 6 | # leetcode 提交結果 7 | Runtime: 105 ms, faster than 9.58% of Python3 online submissions for Largest Number. 8 | Memory Usage: 14.4 MB, less than 5.89% of Python3 online submissions for Largest Number. -------------------------------------------------------------------------------- /2021-10/2021-10-12 (day84)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} arr 3 | * @return {boolean} 4 | */ 5 | function canThreePartsEqualSum(arr) { 6 | const part = arr.reduce((a, b) => a + b, 0) / 3; 7 | 8 | let sum = 0; 9 | let count = 0; 10 | 11 | for (const num of arr) { 12 | sum += num; 13 | 14 | if (sum === part) { 15 | sum = 0; 16 | count += 1; 17 | } 18 | } 19 | 20 | return count >= 3; 21 | } 22 | -------------------------------------------------------------------------------- /2021-10/2021-10-12 (day84)/Tim/README.md: -------------------------------------------------------------------------------- 1 | #### Idea: Sum of the sub-group = sum(arr)/3 = s 2 | 3 | * 1. Check the accumulated sum cur_sum step-by-step, when cur_sum=s, reset cur_sum and add 1 to number of sub-groups n. 4 | 5 | * 2. When it's done, check if the cur_sum=0, if so, it is due to the last reset where cur_sum=s. 6 | 7 | * 3. Additionally, check if n>=3 (note the sum=0 cases.) 8 | 9 | 10 | 11 | ![][fig] 12 | 13 | [fig]:./fig/fig1.png 14 | 15 | -------------------------------------------------------------------------------- /2021-10/2021-10-12 (day84)/Tim/fig/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/2021-10/2021-10-12 (day84)/Tim/fig/fig1.png -------------------------------------------------------------------------------- /2021-10/2021-10-12 (day84)/Tim/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canThreePartsEqualSum(self, arr: List[int]) -> bool: 3 | s = sum(arr)/3 4 | if int(s)!=s: 5 | return False 6 | 7 | cur_sum = 0 8 | n = 0 9 | while arr: 10 | cur_sum += arr.pop() 11 | if cur_sum==s: 12 | cur_sum = 0 13 | n += 1 14 | 15 | return cur_sum==0 and n>=3 16 | 17 | -------------------------------------------------------------------------------- /2021-10/2021-10-12 (day84)/White/README.md: -------------------------------------------------------------------------------- 1 | # 解題想法 2 | 1. 分成三等份,則總和一定能被3整除,若不能整除者就是 false 3 | 2. 從頭開始相加,每等於一等份時就歸零重計 4 | 3. 只要結果至三份時就回傳 true,避開總合為 0 時結果超出 3 的情況 5 | 6 | # leetcode 提交結果 7 | Runtime: 615 ms, faster than 5.10% of Python3 online submissions for Partition Array Into Three Parts With Equal Sum. 8 | Memory Usage: 21 MB, less than 64.29% of Python3 online submissions for Partition Array Into Three Parts With Equal Sum. -------------------------------------------------------------------------------- /2021-10/2021-10-13 (day85)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {TreeNode} root 3 | * @return {number} 4 | */ 5 | function sumOfLeftLeaves(root, sum = 0) { 6 | if (!root) return sum; 7 | 8 | if (root.left && !root.left.left && !root.left.right) { 9 | sum += root.left.val; 10 | } 11 | 12 | return sum + sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right); 13 | } 14 | -------------------------------------------------------------------------------- /2021-10/2021-10-18 (day88)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {TreeNode} root 3 | * @return {number} 4 | */ 5 | function findTilt(root) { 6 | let sum = 0; 7 | 8 | function traverse(root) { 9 | if (!root) return 0; 10 | 11 | const left = traverse(root.left); 12 | const right = traverse(root.right); 13 | 14 | sum += Math.abs(left - right); 15 | 16 | return root.val + left + right; 17 | } 18 | 19 | traverse(root); 20 | 21 | return sum; 22 | } 23 | -------------------------------------------------------------------------------- /2021-10/2021-10-19 (day89)/Hello/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {TreeNode} root 3 | * @return {boolean} 4 | */ 5 | function isUnivalTree(root) { 6 | if (!root) return true; 7 | 8 | if (root.left && root.val !== root.left.val) { 9 | return false; 10 | } 11 | 12 | if (root.right && root.val !== root.right.val) { 13 | return false; 14 | } 15 | 16 | return isUnivalTree(root.left) && isUnivalTree(root.right); 17 | } 18 | -------------------------------------------------------------------------------- /2021-10/2021-10-19 (day89)/ago/solution.ts: -------------------------------------------------------------------------------- 1 | function isUnivalTree(root: TreeNode | null): boolean { 2 | if(root === null) return true; 3 | 4 | root.val; 5 | const test = (node: TreeNode) => { 6 | if(!node) return true; 7 | if(root.val != node.val) return false; 8 | return test(node.left) && test(node.right); 9 | } 10 | return test(root); 11 | } -------------------------------------------------------------------------------- /2021-10/2021-10-28 (day94)/AGO/solution.ts: -------------------------------------------------------------------------------- 1 | function findCenter(edges: number[][]): number { 2 | return edges[0][edges[1].includes(edges[0][0]) ? 0 : 1]; 3 | }; -------------------------------------------------------------------------------- /2021-11/2021-11-02 (day97)/Ray/solution.js: -------------------------------------------------------------------------------- 1 | var canConstruct = function(ransomNote, magazine) { 2 | let recordNote = ransomNote.split("").sort(); 3 | let recordMag = magazine.split("").sort(); 4 | let count = 0; 5 | for (let i = 0 ; i < recordMag.length ; i++) { 6 | if(recordNote[count] === recordMag[i]) { 7 | count++; 8 | } 9 | } 10 | return count === recordNote.length; 11 | }; -------------------------------------------------------------------------------- /2022-01/2022-01-12 (day98)/Husky/solution.py: -------------------------------------------------------------------------------- 1 | import math 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def coinChange(self, coins: List[int], amount: int) -> int: 7 | pd = [math.inf]*(amount + 1) 8 | pd[0] = 0 9 | 10 | for coin in coins: 11 | for i in range(coin, amount + 1): 12 | pd[i] = min(pd[i], 1 + pd[i - coin]) 13 | 14 | return -1 if math.isinf(pd[-1]) else pd[-1] 15 | -------------------------------------------------------------------------------- /2022-01/2022-01-12 (day98)/kirby/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} coins 3 | * @param {number} amount 4 | */ 5 | function coinChange(coins, amount) { 6 | const upperLimit = amount + 1; 7 | const dp = Array(upperLimit).fill(upperLimit); 8 | dp[0] = 0; 9 | 10 | coins.forEach((coin) => { 11 | for (let i = coin; i < upperLimit; i++) { 12 | dp[i] = Math.min(dp[i], dp[i - coin] + 1); 13 | } 14 | }); 15 | return dp[amount] === upperLimit ? -1 : dp[amount]; 16 | } 17 | -------------------------------------------------------------------------------- /2022-01/2022-01-17 (day100)/kevin/README.md: -------------------------------------------------------------------------------- 1 | # Interleaving String 2 | 3 | ## Submission result 4 | 5 | `Time Limit Exceeded` :) 6 | -------------------------------------------------------------------------------- /DataStructures/HashTable/alpha/contains-duplicate/README.md: -------------------------------------------------------------------------------- 1 | # Design Browser History 2 | 3 | ## Solution 4 | 5 | ### Step 1 6 | 7 | Create a hash table to input word. 8 | 9 | ### Step 2 10 | 11 | Let it run whole array if has the word then return true. If not, add it. 12 | Run others to check. 13 | 14 | ### Complexity 15 | 16 | - Space complexity 17 | 18 | Linked list is `O(1)`, 19 | 20 | - Time complexity 21 | 22 | for loop `O(n)` 23 | -------------------------------------------------------------------------------- /DataStructures/HashTable/alpha/contains-duplicate/Solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {boolean} 4 | */ 5 | var containsDuplicate = function (nums) { 6 | const hashTable = new Set(); 7 | 8 | for (let i of nums) { 9 | if (hashTable.has(i)) { 10 | return true; 11 | } else { 12 | hashTable.add(i); 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /DataStructures/HashTable/kirby/contains-duplicate/hashtable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {boolean} 4 | */ 5 | function containsDuplicate(nums) { 6 | const map = {}; 7 | 8 | for (const num of nums) { 9 | if (num in map) { 10 | return true; 11 | } 12 | 13 | map[num] = true; 14 | } 15 | 16 | return false; 17 | } 18 | -------------------------------------------------------------------------------- /DataStructures/HashTable/kirby/word-break/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string[]} wordDict 4 | * @return {boolean} 5 | */ 6 | function wordBreak(s, wordDict) { 7 | const dp = Array(s.length + 1); 8 | 9 | dp[s.length] = true; 10 | 11 | for (let i = s.length - 1; i >= 0; i--) { 12 | dp[i] = wordDict.some( 13 | (word) => s.startsWith(word, i) && dp[i + word.length] 14 | ); 15 | } 16 | 17 | return dp[0]; 18 | } 19 | -------------------------------------------------------------------------------- /DataStructures/HashTable/pencil/217.ContainsDuplicate/README.md: -------------------------------------------------------------------------------- 1 | # Solutions 2 | 3 | ------ 4 | 5 | 1. create an object 6 | 2. create a for loop to check if current nums[i] value is repeated 7 | 3. if repeated, return true 8 | 4. if it dosen't repeated, return false 9 | -------------------------------------------------------------------------------- /DataStructures/LinkedList/READMD.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/DataStructures/LinkedList/READMD.md -------------------------------------------------------------------------------- /DataStructures/LinkedList/ago/876.middle-of-the-linked-list/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | Use slow fast pointer 3 | If we want to go to middle of a list which length is unknown. We can create two pointers. 4 | First pointer move 1 step each time, second pointer move 2 steps each time. 5 | When second pointer touch end of list, first pointer will locate at middle of list 6 | 7 | # Time Complexity 8 | f(n) = n /2 = O(n) 9 | 10 | # Space Complexity 11 | We declare 2 pointers, so f(n) = 2 = O(2) 12 | -------------------------------------------------------------------------------- /DataStructures/LinkedList/ago/876.middle-of-the-linked-list/solution.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func middleNode(head *ListNode) *ListNode { 9 | fast, slow := head, head; 10 | 11 | for (fast != nil && fast.Next != nil){ 12 | fast = fast.Next.Next 13 | slow = slow.Next 14 | } 15 | 16 | return slow 17 | } -------------------------------------------------------------------------------- /DataStructures/LinkedList/casper/876.middle-of-the-linked-list/main.go: -------------------------------------------------------------------------------- 1 | func middleNode(head *ListNode) *ListNode { 2 | nodeArray := make([]*ListNode,100) 3 | count := 0 4 | 5 | for head != nil { 6 | nodeArray[count] = head 7 | head = head.Next 8 | count++ 9 | } 10 | 11 | return nodeArray[count/2] 12 | } 13 | -------------------------------------------------------------------------------- /DataStructures/LinkedList/recoil/1472.design-browser-history/README.md: -------------------------------------------------------------------------------- 1 | # Solution 2 | 3 | 1. create object via Node class. 4 | 2. record url between prev and next. 5 | 3. find Node item and assign to current page by wile loop. 6 | 7 | ## Time Complexity 8 | * use an operate to reduce or increment counter so `f(n) = O(n)` 9 | 10 | ## Space Complexity 11 | * The record is a chain of Node so `f(n) = O(n)` -------------------------------------------------------------------------------- /DataStructures/Queue/kirby/time-needed-to-buy-tickets/solution.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int timeRequiredToBuy(int *tickets, int ticketsSize, int k) { 4 | int times = 0; 5 | int head = 0; 6 | 7 | while (tickets[k] > 0) { 8 | int *element = &tickets[head]; 9 | if (*element > 0) { 10 | *element -= 1; 11 | times += 1; 12 | } 13 | 14 | head = (head + 1) % ticketsSize; 15 | } 16 | 17 | return times; 18 | } 19 | -------------------------------------------------------------------------------- /DataStructures/Stack/READMD.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rabbittee/leet-codes/3f15073409dfe76eac0ba7d53afb30b698a71667/DataStructures/Stack/READMD.md -------------------------------------------------------------------------------- /DataStructures/Stack/ago/maximum-nesting-depth-of-the-parentheses/solution.go: -------------------------------------------------------------------------------- 1 | func maxDepth(s string) int { 2 | max := 0 3 | stack := []byte{} 4 | 5 | for i := 0 ; i < len(s); i++ { 6 | if s[i] == '(' { 7 | stack = append(stack, s[i]) 8 | }else if s[i] == ')' { 9 | stack = stack[:len(stack) - 1] 10 | } 11 | if len(stack) > max { 12 | max = len(stack) 13 | } 14 | } 15 | 16 | return max 17 | } -------------------------------------------------------------------------------- /DataStructures/Stack/kirby/maximum-nesting-depth-of-the-parentheses/solution.c: -------------------------------------------------------------------------------- 1 | 2 | int maxDepth(char *s) { 3 | int stack_len = 0; 4 | int max_depth = 0; 5 | 6 | for (; *s != '\0'; s++) { 7 | if (*s == '(') { 8 | stack_len += 1; 9 | 10 | if (stack_len > max_depth) { 11 | max_depth = stack_len; 12 | } 13 | } 14 | // 15 | else if (*s == ')') { 16 | stack_len -= 1; 17 | } 18 | } 19 | 20 | return max_depth; 21 | } 22 | -------------------------------------------------------------------------------- /DataStructures/Stack/kirby/maximum-nesting-depth-of-the-parentheses/solution.ex: -------------------------------------------------------------------------------- 1 | defmodule Solution do 2 | @spec max_depth(s :: String.t()) :: integer 3 | def max_depth(s) do 4 | s 5 | |> String.graphemes() 6 | |> Enum.reduce({0, 0}, fn 7 | "(", {stack, depth} -> {stack + 1, max(stack + 1, depth)} 8 | ")", {stack, depth} -> {stack - 1, depth} 9 | _, acc -> acc 10 | end) 11 | |> elem(1) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /DataStructures/Stack/kirby/maximum-nesting-depth-of-the-parentheses/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | function maxDepth(s) { 6 | let stack = 0; 7 | let maxDepth = 0; 8 | 9 | for (const char of s) { 10 | if (char === "(") { 11 | stack += 1; 12 | maxDepth = Math.max(maxDepth, stack); 13 | } 14 | // 15 | else if (char === ")") { 16 | stack -= 1; 17 | } 18 | } 19 | 20 | return maxDepth; 21 | } 22 | -------------------------------------------------------------------------------- /DataStructures/Stack/kirby/maximum-nesting-depth-of-the-parentheses/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, s: str) -> int: 3 | stack_len, max_depth = 0, 0 4 | 5 | for c in s: 6 | if c == '(': 7 | stack_len += 1 8 | max_depth = max(max_depth, stack_len) 9 | if c == ')': 10 | stack_len -= 1 11 | 12 | return max_depth 13 | -------------------------------------------------------------------------------- /DataStructures/Tree/ago/427. Construct Quad Tree/README.md: -------------------------------------------------------------------------------- 1 | # Construct Quad Tree 2 | 3 | 1. Calculate the middle of grid, split it to 4 squares. 4 | 2. Check if all data in squares are same, if true, it is leaf node and return 5 | 3. It is not leaf node, so we need to go further into next 4 pieces square. 6 | 7 | ## Time complexity O(n^3) 8 | ## Space complexity O(n) -------------------------------------------------------------------------------- /DataStructures/Tree/ago/559. Maximum Depth of N-ary Tree/README.md: -------------------------------------------------------------------------------- 1 | # Maximum Depth of N-ary Tree 2 | --- 3 | ## Solution 4 | 5 | 1. Check if end of tree, return 0 6 | 2. Loop all children of this node, and recursive children. 7 | 3. Find the Maximum depth op children then return it. 8 | 9 | ## Time complexity O(n) 10 | ## Space complexity O(n) -------------------------------------------------------------------------------- /DataStructures/Tree/ago/559. Maximum Depth of N-ary Tree/solution.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a Node. 3 | * type Node struct { 4 | * Val int 5 | * Children []*Node 6 | * } 7 | */ 8 | 9 | func maxDepth(root *Node) int { 10 | if root == nil { return 0 } 11 | ans := 0 12 | for _, child := range root.Children { ans = max(ans, maxDepth(child)) } 13 | return ans + 1 14 | } 15 | 16 | func max(a, b int) int { 17 | if a > b { return a } 18 | return b 19 | } -------------------------------------------------------------------------------- /script/COVER_README.template: -------------------------------------------------------------------------------- 1 | # Leet Rabbits Codes 2 | 3 | {{daily_table}} 4 | 5 | --- 6 | 7 | ### Summary 8 | 9 | {{summary}} 10 | 11 | --- 12 | 13 | {{leetcode_url_def}} 14 | 15 | [Easy]: https://img.shields.io/badge/-Easy-brightgreen 16 | [Medium]: https://img.shields.io/badge/-Medium-orange 17 | [Hard]: https://img.shields.io/badge/-Hard-red -------------------------------------------------------------------------------- /script/README.template: -------------------------------------------------------------------------------- 1 | # {{questionId}}. {{title}} 2 | 3 | `{{difficulty}}` 4 | 5 | ## Description 6 | 7 | {{content}} 8 | 9 | --- 10 | 11 | ### Topic Tags 12 | 13 | {{def_tag}} 14 | 15 | {{topic_tags}} 16 | 17 | --- 18 | 19 | ##### [original question](https://leetcode.com/problems/{{titleSlug}}) 20 | -------------------------------------------------------------------------------- /script/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.22.0 --------------------------------------------------------------------------------