Skip to content

zh-wang/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

578 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solutions for Leetcode problems

Problem Solutions
0001_Two_Sum one_hash.py
brute_force.java
0002_Add_Two_Numbers trival.java
0003_Longest_Substring_Without_Repeating_Characters prob.md hashmap_one_pass.java ⭐️
hashmap_and_two_points.py
0004_Median_of_Two_Sorted_Arrays prob.md binary_search.java ⭐️
0005_Longest_Palindromic_Substring dp_linear_space.py
trick_expand_center.java ⭐️
0006_ZigZag_Conversion trival.java
0007_Reverse_Integer trival_overflow_checking.java
0008_String_to_Integer_atoi trival.java
0009_Palindrome_Number overflow_check.java
0010_Regular_Expression_Matching dp.java
0011_Container_With_Most_Water trick_greedy.java
0012_Integer_to_Roman trival.java
0013_Roman_to_Integer trival.java
0014_Longest_Common_Prefix divide_conquer.py
trie.py
trival.java
0015_3Sum shrink_both_side.py
0016_3Sum_Closest shrink_both_side.py
0017_Letter_Combinations_of_a_Phone_Number backtracking.java
list_expanding.py ⭐️
backtracking.py
0018_4Sum def_2sum_as_method.py
k_sum_generized_and_hashset.java
0019_Remove_Nth_Node_From_End_of_List trival.java
0020_Valid_Parentheses stack.py
0021_Merge_Two_Sorted_Lists trival_recur.py
0022_Generate_Parentheses backtracking.java
backtracking.py
0023_Merge_K_Sorted_Lists priority_queue.java
divide_conquer.py
0030_Substring_with_Concatenation_of_All_Words sliding_window.py
0031_Next_Permutation iter.java
trival.py
0032_Longest_Valid_Parentheses dp.java
stack_two_pass.py
0033_Search_in_Rotated_Sorted_Array binary_search.py
binary_search_recur.py
0034_Find_First_and_Last_Position_of_Element_in_Sorted_Array binary_search.py
0035_Search_Insert_Position binary_search.py
0036_Valid_Sudoku hashset.py
0037_Sudoku_Solver dfs.py
0038_Count_and_Say counting.java
trival_counting.py
0039_Combination_Sum backtracking.py
0040_Combination_Sum_II backtracking.py
0041_First_Missing_Positive trick_in_slot_check.py
0042_Trapping_Rain_Water brute.py
dp.py
stack.py
trick_two_pointers.py ⭐️
0043_Multiply_Strings trival_reversed_list.py
0044_Wildcard_Matching dp.py
0045_Jump_Game_II greedy.py
0046_Permutations list_concat.py
dfs_modify_input_array.py
0047_Permutations_II dfs.kt
list_concat_pythonic.py
list_concat.py
list_concat.java
0048_Rotate_Image iter_by_layer_in_space.py
0049_Group_Anagrams concise_tuple_sorted.py
0050_Pow_x_n recur.py
iter_with_bit_opts.py ⭐️
recur.java
0051_N_Queens backtracking.py
0052_N_Queens_II backtracking.py
0053_Maximum_Subarray dp.py
divide_conquer.py
trival.py
0054_Spiral_Matrix check_table.py
iter_by_layer.java
0055_Jump_Game dp.py
greedy.java
0056_Merge_Intervals sort_and_iter.py
sort_and_iter_comparator.java
0057_Insert_Interval sort_and_iter.py
0058_Length_of_Last_Word trival_fast.java
trival.py
0059_Spiral_Matrix_II iter_by_layer.py
0060_Permutation_Sequence iter_by_group.py
0061_Rotate_List double_pointer.py
0062_Unique_Paths math.cpp
dp_1D.java
dp_2D.py
0063_Unique_Paths_II dp_2D.java
0064_Minimum_Path_Sum dp_2D.java
0065_Valid_Number DFA.py
regex.py
0066_Plus_One iter.java
trival.py
0067_Add_Binary trival.py
0068_Text_Justification trival.py
0069_Sqrt_x newton.py
0070_Climbing_Stairs backtracking_memo.java
dp.py
backtracking.java
0071_Simplify_Path stack.py
0072_Edit_Distance dp.py
0073_Set_Matrix_Zeroes in_space.swift
in_space_faster.py
trival.java
0074_Search_a_2D_Matrix binary_search.py
0075_Sort_Colors inc_start_index_1_loop.py
both_side_1_loop.py
exchange_3_loops.py
0076_Minimum_Window_Substring sliding_window.py
record_index_by_dict_of_arr.py
0077_Combinations backtracking_with_marks.py
recur_self.java
recur_self.py
0078_Subsets iter.py
recur.py
bit_check.py
0079_Word_Search dfs.py
0080_Remove_Duplicates_from_Sorted_Array_II prob.md trival_in_place_quodratic.py
trick_linear_in_place.py ⭐️
0081_Search_in_Rotated_Sorted_Array_II binary_search.py
0082_Remove_Duplicates_from_Sorted_List_II prob.md linked_list.py
0083_Remove_Duplicates_from_Sorted_List prob.md linked_list.py
0084_Largest_Rectangle_in_Histogram min_segment_tree.py
stack.py
recur.java
0085_Maximal_Rectangle recur_as_0084.java
0086_Partition_List linked_list_ops.java
0087_Scramble_String recur_with_memo_faster.java
recur_with_memo.java
0088_Merge_Sorted_Array two_points_from_end.java
0089_Gray_Code backtracking.java
0090_Subsets_II repeat_on_final_list_pythonic.py
repeat_on_final_list.java
0091_Decode_Ways dp.py
dp.java
0092_Reverse_Linked_List_II linked_list_recur.py
linked_list_recur_v2.py
0093_Restore_IP_Addresses backtracking.py
0094_Binary_Tree_Inorder_Traversal iter_with_stack.py
double_stacks.java
0095_Unique_Binary_Search_Trees_II recur_with_memo.py ⭐️
0096_Unique_Binary_Search_Trees prob.md recur_with_memo.py ⭐️
0097_Interleaving_String dp_2d.py
0098_Validate_Binary_Search_Tree recur.py
recur_quick.java ⭐️
0099_Recover_Binary_Search_Tree recur_linear_space.java
recur_const_space.py
0100_Same_Tree recur.py
iter_bfs.java
iter_dfs.java
0101_Symmetric_Tree recur.java
0102_Binary_Tree_Level_Order_Traversal iter_bfs_each_level.py
0103_Binary_Tree_Zigzag_Level_Order_Traversal iter_bfs_each_level.py
0104_Maximum_Depth_of_Binary_Tree recur.py
0105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal recur.py
recur.java
0106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal recur.py
0107_Binary_Tree_Level_Order_Traversal_II iter_bfs_each_level.py
0108_Convert_Sorted_Array_to_Binary_Search_Tree recur.py
recur.java
0109_Convert_Sorted_List_to_Binary_Search_Tree recur_linear.java ⭐️
recur_two_points.py
0110_Balanced_Binary_Tree recur.py
0111_Minimum_Depth_of_Binary_Tree recur.py
iter_with_priority_queue.java
iter_bfs.swift
0112_Path_Sum recur.py
0113_Path_Sum_II recur.py
0114_Flatten_Binary_Tree_to_Linked_List recur_with_stack.py
0115_Distinct_Subsequences dp_2d.py
dp_1d.py
0116_Populating_Next_Right_Pointers_in_Each_Node prob.md iter_by_level.py
recur_1_param.py
recur_2_params.py ⭐️
0117_Populating_Next_Right_Pointers_in_Each_Node_II prob.md recur_bfs.py ⭐️
0118_Pascals_Triangle iter.py
0119_Pascals_Triangle_II iter_1d_space.py
recur_with_memo_2d_space.py
0120_Triangle dp_1d_space.py
0121_Best_Time_to_Buy_and_Sell_Stock prob.md iter_1d_space.py
iter_const_space.py
0122_Best_Time_to_Buy_and_Sell_Stock_II prob.md iter.py
0123_Best_Time_to_Buy_and_Sell_Stock_III prob.md dp_kn.py ⭐️
dp_kn2.py
dp_kn_swapped.py ⭐️
0124_Binary_Tree_Maximum_Path_Sum dfs.py
0125_Valid_Palindrome two_pointer.py
two_pointer_compact.py
pythonic.py
0126_Word_Ladder_II prob.md bfs_by_layer.py ⭐️
0127_Word_Ladder bfs_faster.java ⭐️
bfs_quad.java
bfs_faster.py
0128_Longest_Consecutive_Sequence disjoint_set.py
0129_Sum_Root_to_Leaf_Numbers dfs.py
0130_Surrounded_Regions bfs_with_memo.py
0131_Palindrome_Partitioning dfs_with_memo.py
0132_Palindrome_Partitioning_II dp_with_memo.py ⭐️
0133_Clone_Graph bfs.py
0134_Gas_Station iter.py
0135_Candy prob.md iter_both_sides.py ⭐️
0136_Single_Number xor.py
0137_Single_Number_II prob.md mod3_add.py ⭐️
0138_Copy_List_with_Random_Pointer iter.py
0139_Word_Break prob.md dp.py
0140_Word_Break_II prob.md dfs_with_dp.py ⭐️
0141_Linked_List_Cycle iter_with_hash.py
two_points.java
0142_Linked_List_Cycle two_points.java
0143_Reorder_List two_points_with_recur.py
0144_Binary_Tree_Preorder_Traversal iter_with_stack.java
iter_with_stack.py
iter_with_stack2.java
0145_Binary_Tree_Postorder_Traversal iter_with_stack.py
0146_LRU_Cache double_linked_list_with_hash.java
0147_Insertion_Sort_List double_loop.java
0148_Sort_List two_points.java
two_points_const_space.java
0149_Max_Points_on_a_Line hash_slope_n2.py
hash_slope_n2_gcd_fast.py
0150_Evaluate_Reverse_Polish_Notation stack.java
0151_Reverse_Words_in_a_String one_liner.py
const_space.cpp
0152_Maximum_Product_Subarray iter_longer_impl.java
both_end.swift ⭐️
both_sides.swift ⭐️
dp_n_space.py
iter_keep_min_max.cpp ⭐️
0153_Find_Minimum_in_Rotated_Sorted_Array binary_search.java
0154_Find_Minimum_in_Rotated_Sorted_Array_II binary_search_with_shrink.java
0155_Min_Stack two_stacks.java
0156_Binary_Tree_Upside_Down LintCode dfs.java
0157_Read_N_Characters_Given_Read4 LintCode iter_keep_last.java
0158_Read_N_Characters_Given_Read4_II_Call_multiple_times LintCode iter_keep_last.java ⭐️
0159_Longest_Substring_with_At_Most_Two_Distinct_Characters sliding_window.java
0160_Intersection_of_Two_Linked_Lists hash.java
two_pointers.py
0161_One_Edit_Distance LintCode iter_linear_time.java ⭐️
dp_2d.java
dp_1d.java
0162_Find_Peak_Element binary_search.cpp ⭐️
iter_linear_time_simple.java
iter_linear_time.py
0163_Missing_Ranges LintCode iter_range_check.java
iter_range_check_modified.py ⭐️
0164_Maximum_Gap radix_sort.java
sort_NlogN.java
0165_Compare_Version_Numbers iter.py
0166_Fraction_to_Recurring_Decimal math_hash.py
math.py
0167_Two_Sum_II_Input_array_is_sorted two_sides.py
0168_Excel_Sheet_Column_Title iter.py
0169_Majority_Element Boyer_Moore_Voting.py
0171_Excel_Sheet_Column_Number
0172_Factorial_Trailing_Zeroes math.java
0173_Binary_Search_Tree_Iterator bst_one_stack_simpler.java
bst_one_stack.py
0174_Dungeon_Game simulation_with_dp.java
binary_search_with_dp.java
0179_Largest_Number custom_sort.java
0186_Reverse_Words_in_a_String_II LintCode const_space.cpp
0187_Repeated_DNA_Sequences sliding_window.java
sliding_window_with_hash.py ⭐️
0188_Best_Time_to_Buy_and_Sell_Stock_IV dp_kn.py ⭐️
0189_Rotate_Array cycle_swap.java
triple_reverse.py
vector_ops.cpp
0190_Reverse_Bits iter.java
both_sides.cpp
0191_Number_of_1_Bits bit_trick.java
iter.cpp
0192_Word_Frequency one_line.sh
0193_Valid_Phone_Numbers one_line.sh
0194_Transpose_File awk
0195_Tenth_Line awk
0196_Delete_Duplicate_Emails sql
0197_Rising_Temperature sql
0198_House_Robber dp.py
0199_Binary_Tree_Right_Side_View dfs.py
0200_Number_of_Islands bfs.py
0201_Bitwise_AND_of_Numbers_Range iter_bits.py
iter_bits_modified.py
0201_Happy_Number iter.java
0203_Remove_Linked_List_Elements iter.java
0204_Count_Primes prime_table.java
0205_Isomorphic_Strings iter_faster.py
iter.java
0206_Reverse_Linked_List recur.py
0207_Course_Schedule dfs_dag_find_cycle.py
0208_Implement_Trie simple_trie.py
0209_Minimum_Size_Subarray_Sum binary_search.py
two_pointers.kt ⭐️
0210_Course_Schedule_II prob.md dfs_dag_topological_sort.py
bfs_topological_sort.java
0211_Add_and_Search_Word hashmap_reverse_check.kt
trie_by_hashmap.py
trie_based_dfs.py
0212_Word_Search_II trie_with_dfs.py
0213_House_Robber_II dp_two_pass.py
0214_Shortest_Palindrome kmp.py ⭐️
brute_force_pythonic.py
0215_Kth_Largest_Element_in_an_Array quick_select.py
priority_queue.java
0216_Combination_Sum_III backtracking.py
0217_Contains_Duplicate set.java
0218_The_Skyline_Problem priority_queue_NLogN.java
coordinate_compression.java
0219_Contains_Duplicate_II hash.py
0220_Contains_Duplicate_III treeset.java ⭐️
0221_Maximal_Square dp_2d.py
0222_Count_Complete_Tree_Nodes binary_search.py
brute_force.java
0223_Rectangle_Area math.py
0224_Basic_Calculator stack.py
0225_Implement_Stack_using_Queues two_queues.py
one_queue.py
0226_Invert_Binary_Tree recur.py
0227_Basic_Calculator_II simu_with_stack.py
0228_Summary_Ranges iter.java
iter_with_exp_inc.java ⭐️
0229_Majority_Element_II boyer_moore.py
0230_Kth_Smallest_Element_in_a_BST iter_with_stack.py ⭐️
dfs.py
0231_Power_of_Two math.py
0232_Implement_Queue_using_Stacks double_stacks.py
0233_Number_of_Digit_One math.py
0234_Palindrome_Linked_List iter.py
0235_Lowest_Common_Ancestor_of_a_Binary_Search_Tree dfs_use_BST_property.py
dfs.py
0236_Lowest_Common_Ancestor_of_a_Binary_Tree dfs.py
0237_Delete_Node_in_a_Linked_List swap_value.py
one_swap.py
0238_Product_of_Array_Except_Self iter_const_space.py
0239_Sliding_Window_Maximum deque.py ⭐️
0240_Search_a_2D_Matrix_II binary_search.java
iter.java ⭐️
0241_Different_Ways_to_Add_Parentheses divide_conquer.py ⭐️
pythonic.py
0242_Valid_Anagram dict.py
0243_Shortest_Word_Distance LintCode iter.py
0244_Shortest_Word_Distance_II LintCode hash_and_merge.py
0245_Shortest_Word_Distance_III LintCode iter.py
0246_Strobogrammatic_Number LintCode iter.py
0247_Strobogrammatic_Number_II LintCode iter.py ⭐️
iter.java
0248_Strobogrammatic_Number_III LintCode iter.py ⭐️
0249_Group_Shifted_String LintCode iter_cal_hash.py
iter_cal_diff.py
0250_Count_Univalue_Subtrees LintCode recur.py ⭐️
0251_Flatten_2D_Vector LintCode simu.py
0252_Meeting_Rooms LintCode sort_and_iter.java
0253_Meeting_Rooms_II LintCode sort_and_min_q.java ⭐️
sort_and_iter_quadric.java
0254_Factor_Combinations LintCode dfs_faster_gen_factors.py
dfs.py
0255_Verify_Preorder_Sequence_in_Binary_Search_Tree prob.md LintCode const_space.py ⭐️
stack.py ⭐️
recur_quadric.py
0256_Paint_House dp.py
0257_Binary_Tree_Paths LintCode recur.py
0258_Add_Digits iter.py
math.py
0259_3Sum_Smaller LintCode iter_shrink_both_sides.java
iter_shrink_both_sides_modified.py ⭐️
0260_Single_Number_III bit_opt.py
0261_Graph_Valid_Tree LintCode disjoint_set.py
dfs.py
0263_Ugly_Number iter.py
0264_Ugly_Number_II math.py ⭐️
0265_Paint_House_II LintCode dp_with_second_min.py
dp_with_special_min.py
0266_Palindrome_Permutation LintCode iter.py
0267_Palindrome_Permutation_II unique_permutation.py
0268_Missing_Number math_xor.py
0269_Alien_Dictionary prob.md LintCode topological_sort.py ⭐️
0274_H_index hash.py
0275_H-Index_II binary_search.py
0276_Paint_Fence math.py
0277_Find_the_Celebrity greedy.py
0278_First_Bad_Version binary_search.py
0279_Perfect_Squares static_dp.py
0280_Wiggle_Sort LintCode swap.py
only_swap_N.cpp
sort_and_swap_NLogN.java
0281_Zigzag_Iterator LintCode double_index.java
0282_Expression_Add_Operators dfs.py
0283_Move_Zeroes iter.py
0284_Peeking_Iterator simple.py
0285_Inorder_Successor_in_BST LintCode binary_search.py
0286_Walls_and_Gates LintCode bfs.py
0287_Find_the_Duplicate_Number Floyds_Tortoise_and_Hare.py ⭐️
0288_Unique_Word_Abbreviation prob.md LintCode set.py
0289_Game_of_Life simu.java
0290_Word_Pattern one_dict.py
dict.py
0291_Word_Pattern_II LintCode two_dict_and_dfs.py
one_dict_and_dfs.py
0292_Nim_Game dp.py
math.py
0293_Flip_Game LintCode simple.py
0294_Flip_Game_II LintCode dfs_with_memo.py
0297_Serialize_and_Deserialize_Binary_Tree prob.md bfs.py ⭐️
0299_Bulls_and_Cows iter.py
0300_Longest_Increasing_Subsequence dp_and_binary_search.py
dp.py
dp_bisect.py
0303_Range_Sum_Query_Immutable simple.py
0304_Range_Sum_Query_2D_Immutable 2d_addup.py
0305_Number_of_Islands_II prob.md disjoint_set.py
0306_Additive_Number dfs.py
0307_Range_Sum_Query_Mutable binary_indexed_tree.py ⭐️
segment_tree.py ⭐️
0308_Range_Sum_Query_2D prob.md segment_tree.py ⭐️
0309_Best_Time_to_Buy_and_Sell_Stock_with_Cooldown state_machine.py
dp_quadric.py
0310_Minimum_Height_Trees graph_degree.java ⭐️
0313_Super_Ugly_Number math.py
math.java
0318_Maximum_Product_of_Word_Lengths bit_operations.py
bit_operations.java
0319_Bulb_Switcher math.java
prime_table.java
0322_Coin_Change dp_loop_index.java
dp.py
dp.java
0323_Number_of_Connected_Components_in_an_Undirected_Graph disjoint_set.py
0324_Wiggle_Sort_II median_and_3way_partition.py
sort_and_pick_NLogN_pythonic.py ⭐️
sort_and_module.py
sort_and_pick_NLogN.py
0325_Maximum_Size_Subarray_Sum_Equals_k iter_and_hashmap.java
0326_Power_of_Three iter.java
0327_Count_of_Rnage_Sum prob.md binary_indexed_tree.py ⭐️
0328_Odd_Even_Linked_List linked_list_opt.java
0331_Verify_Preorder_Serialization_of_a_Binary_Tree prob.md iter_by_degrees.py
stack.py
0332_Reconstruct_Itinerary dfs2.java
dfs.java
0334_Increasing_Triplet_Subsequence iter.java
0337_House_Robber_III dfs.java
0338_Counting_Bits math.py
math.java
0342_Power_of_Four math.java
0343_Integer_Break dp.java
math.py
0344_Reverse_String iter.java
0345_Reverse_Vowels_of_a_String iter.java
0347_Top_K_Frequent_Elements kth_partition.py
hash_and_heap.java
0349_Intersection_of_Two_Arrays hashmap.java
two_sets.java
0350_Intersection_of_Two_Arrays_II hashmap.java
0351_Android_Unlock_Patterns prob.md LintCode dfs.java
0360_Sort_Transformed_Array prob.md math.py
two_points.java
0370_Range_Addition LintCode iter_reduce.py
0377_Combination_Sum_IV dp.java
0383_Ransom_Note prob.md hashmap.py
0384_Shuffle_an_Array prob.md iter_with_random.py
0385_Mini_Parser prob.md recur.py
0386_Lexicographical_Numbers prob.md recur.py
0387_First_Unique_Character_in_a_String prob.md hashmap.py
0388_Longest_Absolute_File_Path prob.md stack.py
0389_Find_the_Difference xor.py
hashmap.py
0390_Elimination_Game modified_binary_search.java
0391_Perfect_Rectangle math.py
0392_Is_Subsequence two_pointers.py
0393_UTF-8_Validation iter_with_bit_opts.py
iter_with_bit_opts2.py
0394_Decode_String recur.py
0395_Longest_Substring_with_At_Least_K_Repeating_Characters sliding_window.py ⭐️
divide_conquer.py
0396_Rotate_Function arr_sum_trick.py
0397_Integer_Replacement bfs.py
math.py
0398_Random_Pick_Index hash.py
reservoir_sampling.py
0399_Evaluate_Division bfs.py
dfs.py
0400_Nth_Digit iter.py
0401_Binary_Watch combinations.py
0402_Remove_K_Digits stack.py
0403_Frog_Jump backtracking.py
0404_Sum_of_Left_Leaves recur.py
0405_Convert_a_Number_to_Hexadecimal iter.py
0406_Queue_Reconstruction_by_Height sort_and_insert.kt
sort_and_insert.py ⭐️
0407_Trapping_Rain_Water_II priority_queue.java
priority_queue.py
0409_Longest_Palindrome hash.py
0410_Split_Array_Largest_Sum binary_search.py
0411_Minimum_Unique_Word_Abbreviation prob.md dfs.py ⭐️
0465_Optimal_Account_Balancing prob.md LintCode dp_by_subsets.java ⭐️
backtracking.py
0475_Heaters two_pointers.py
brute_force.java
0485_Max_Consecutive_Ones iter.py
0487_Max_Consecutive_Ones_II iter.py
0494_Target_Sum recur_with_memo.py
recur_brute_force.cpp
dp.java
0498_Diagonal_Traverse iter.kt
iter_with_zip.py
0500_Keyboard_Row bits_opts.py
0542_01_Matrix prob.md bfs.py
0543_Diameter_of_Binary_Tree dfs.py
0572_Subtree_of_Another_Tree binary_tree_opts.py
0598_Range_Addition_II iter.py
0673_Number_of_Longest_Increasing_Subsequence double_dp.java ⭐️
segment_tree.py
0703_Kth_Largest_Element_in_a_Stream heap.py
priority_queue.java
priority_queue.py
1263_Minimum_Moves_to_Move_a_Box_to_Their_Target_Location prob.md double_A_star.py ⭐️
1288_Remove_Covered_Intervals line_sweep.java
1647_Minimum_Deletions_to_Make_Character_Frequencies_Unique prob.md iter_and_count.py

About

solutions for leetcode problem

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors