├── src
├── reverse_linkedlist
│ ├── README.md
│ └── Solution.java
├── 3sum_smaller
│ ├── Makefile
│ └── README.md
├── 400_nth_digit
│ ├── Makefile
│ └── README.md
├── 403_frog_jump
│ └── Makefile
├── bomb_enemy
│ ├── Makefile
│ └── README.md
├── cloneGraph
│ └── Makefile
├── decode_string
│ └── Makefile
├── flip_game_ii
│ ├── Makefile
│ └── README.md
├── insertionSortList
│ └── README.md
├── is_subsequence
│ └── Makefile
├── setMatrixZero
│ ├── Makefile
│ └── README.md
├── 263_ugly_number
│ ├── Makefile
│ └── README.md
├── 401_binary_watch
│ └── Makefile
├── 402_remove_k_digits
│ └── Makefile
├── elimination_game
│ └── Makefile
├── evaluate_division
│ └── Makefile
├── find_the_difference
│ └── Makefile
├── integer_replacement
│ └── Makefile
├── perfect_rectangle
│ └── Makefile
├── random_pick_index
│ ├── Makefile
│ └── README.md
├── rotate_function
│ └── Makefile
├── utf_8_validation
│ └── Makefile
├── wiggle_sequence
│ └── Makefile
├── 404_sum_of_left_leaves
│ ├── Makefile
│ └── README.md
├── buildTreePreOrderInOrder
│ ├── Makefile
│ └── README.md
├── contains_duplicate_ii
│ ├── Makefile
│ └── README.md
├── sortColors
│ └── main.pyc
├── 405_convert_a_number_to_hex
│ └── Makefile
├── 407_trapping_rain_water_ii
│ └── Makefile
├── 408_valid_word_abbreviation
│ └── Makefile
├── buildTreeInOrderPostOrder
│ ├── Makefile
│ └── README.md
├── find_the_duplicate_number
│ ├── Makefile
│ └── README.md
├── guess_number_higher_or_lower
│ └── Makefile
├── longest_absolute_file_path
│ └── Makefile
├── 406_queue_reconstruction_by_height
│ └── Makefile
├── first_unique_character_in_a_string
│ ├── Makefile
│ └── README.md
├── guess_number_higher_or_lower_ii
│ └── Makefile
├── 2328_number_of_increasing_path_in_a_grid
│ └── Makefile
├── containerWithMostWater
│ ├── main.pyc
│ └── README.md
├── squareRoot
│ ├── README.md
│ └── main.py
├── implement_trie_prefix_tree
│ └── README.md
├── power_of_two
│ ├── README.md
│ └── Solution.java
├── longest_substring_with_at_least_k_repeating_characters
│ └── Makefile
├── implement_queue_using_stacks
│ ├── Makefile
│ └── README.md
├── 3Sum
│ ├── Makefile
│ └── README.md
├── anagram
│ ├── Makefile
│ ├── README.md
│ └── solution.py
├── atoi
│ └── Makefile
├── h_index
│ └── Makefile
├── increasing_triplet_subsequence
│ ├── README.md
│ └── Makefile
├── largestRectangleHistogram
│ ├── histogram.png
│ └── histogram_area.png
├── two_sum
│ ├── Makefile
│ └── README.md
├── 3SumClosest
│ ├── Makefile
│ └── README.md
├── addBinary
│ ├── Makefile
│ ├── README.md
│ └── main.py
├── add_digits
│ ├── Makefile
│ ├── main.cpp
│ └── README.md
├── coin_change
│ ├── Makefile
│ └── README.md
├── flip_game
│ └── Makefile
├── game_of_life
│ └── Makefile
├── h_index_ii
│ ├── Makefile
│ └── README.md
├── mergeKSorted
│ ├── Makefile
│ └── README.md
├── nim_game
│ └── Makefile
├── paint_fence
│ ├── Makefile
│ └── README.md
├── paint_house
│ └── Makefile
├── sortedArrayToBST
│ └── README.md
├── super_pow
│ ├── Makefile
│ └── README.md
├── wiggle_sort
│ ├── Makefile
│ └── README.md
├── word_pattern
│ └── Makefile
├── add_two_numbers
│ ├── Makefile
│ └── README.md
├── additive_number
│ └── Makefile
├── alien_dictionary
│ └── Makefile
├── basic_calculator
│ └── makefile
├── binary_tree_paths
│ ├── Makefile
│ └── README.md
├── bulb_switcher
│ └── Makefile
├── bulls_and_cows
│ └── Makefile
├── counting_bits
│ └── Makefile
├── design_snake_game
│ └── Makefile
├── design_twitter
│ └── Makefile
├── first_bad_version
│ ├── Makefile
│ └── README.md
├── flatten_2d_vector
│ ├── Makefile
│ └── README.md
├── graph_valid_tree
│ └── Makefile
├── house_robber_iii
│ └── Makefile
├── integer_break
│ ├── Makefile
│ └── README.md
├── line_reflection
│ ├── Makefile
│ └── README.md
├── meeting_rooms
│ ├── Makefile
│ └── README.md
├── meeting_rooms_ii
│ ├── Makefile
│ └── README.md
├── missing_number
│ ├── Makefile
│ └── README.md
├── moving_zeroes
│ ├── Makefile
│ └── README.md
├── paint_house_ii
│ └── Makefile
├── palindrome_pairs
│ ├── Makefile
│ └── README.md
├── patching_array
│ └── Makefile
├── peeking_iterator
│ └── Makefile
├── perfect_squares
│ ├── Makefile
│ └── README.md
├── power_of_four
│ ├── Makefile
│ └── README.md
├── power_of_three
│ ├── Makefile
│ └── README.md
├── range_addition
│ └── Makefile
├── reverse_string
│ ├── Makefile
│ └── README.md
├── self_crossing
│ └── Makefile
├── single_number_iii
│ └── Makefile
├── sortList
│ └── README.md
├── super_ugly_number
│ ├── Makefile
│ └── README.md
├── ugly_number_ii
│ └── Makefile
├── valid_anagram
│ ├── Makefile
│ ├── README.md
│ └── main.cpp
├── walls_and_gates
│ └── Makefile
├── wiggle_sort_ii
│ ├── Makefile
│ └── README.md
├── word_pattern_ii
│ ├── Makefile
│ └── README.md
├── zigzag_iterator
│ └── Makefile
├── best_meeting_point
│ ├── Makefile
│ └── README.md
├── create_maximum_number
│ └── Makefile
├── design_hit_counter
│ └── Makefile
├── design_tic_tac_toe
│ └── Makefile
├── factor_combinations
│ └── Makefile
├── find_the_celebrity
│ └── Makefile
├── group_shifted_strings
│ ├── Makefile
│ └── README.md
├── largest_bst_subtree
│ └── Makefile
├── logger_rate_limiter
│ └── Makefile
├── minimum_height_trees
│ └── Makefile
├── nested_list_weight_sum
│ ├── Makefile
│ └── README.md
├── number_of_digit_one
│ ├── Makefile
│ └── README.md
├── number_of_islands_ii
│ └── Makefile
├── odd_even_linked_list
│ ├── Makefile
│ └── README.md
├── palindrome_linked_list
│ ├── Makefile
│ └── README.md
├── palindrome_permutation
│ ├── Makefile
│ └── README.md
├── plus_one_linked_list
│ ├── Makefile
│ └── README.md
├── reconstruct_itinerary
│ └── Makefile
├── russian_doll_envelopes
│ ├── Makefile
│ └── README.md
├── search_a_2d_matrix_ii
│ ├── Makefile
│ └── README.md
├── shortest_word_distance
│ ├── Makefile
│ └── README.md
├── sliding_window_maximum
│ └── Makefile
├── sort_transformed_array
│ ├── Makefile
│ └── README.md
├── sortedListToBST
│ └── README.md
├── strobogrammatic_number
│ ├── Makefile
│ └── README.md
├── sum_of_two_integers
│ ├── Makefile
│ └── README.md
├── valid_perfect_square
│ ├── Makefile
│ └── README.md
├── water_and_jug_problem
│ └── Makefile
├── android_unlock_patterns
│ └── Makefile
├── count_univalue_subtrees
│ ├── Makefile
│ └── README.md
├── encode_and_decode_strings
│ └── Makefile
├── expression_add_operators
│ ├── Makefile
│ └── README.md
├── find_leaves_of_binary_tree
│ └── Makefile
├── generalized_abbreviation
│ ├── Makefile
│ └── README.md
├── inorder_successor_in_bst
│ ├── Makefile
│ └── README.md
├── integer_to_english_words
│ ├── Makefile
│ └── README.md
├── intersection_of_two_arrays
│ ├── Makefile
│ └── README.md
├── isValidSudoku
│ ├── 250px-Sudoku-by-L2G-20050714.svg.png
│ └── README.md
├── largest_divisible_subset
│ ├── Makefile
│ └── README.md
├── mini_parser
│ └── Makefile
├── nested_list_weight_sum_ii
│ └── Makefile
├── palindrome_permutation_ii
│ ├── Makefile
│ └── README.md
├── range_sum_query_2d_mutable
│ └── Makefile
├── range_sum_query_immutable
│ ├── Makefile
│ └── README.md
├── range_sum_query_mutable
│ ├── Makefile
│ └── README.md
├── ransom_note
│ └── Makefile
├── remove_duplicate_letters
│ ├── Makefile
│ └── README.md
├── remove_invalid_parentheses
│ ├── Makefile
│ └── README.md
├── reverse_vowels_of_a_string
│ ├── Makefile
│ └── README.md
├── shortest_word_distance_ii
│ └── Makefile
├── shortest_word_distance_iii
│ ├── Makefile
│ └── README.md
├── strobogrammatic_number_ii
│ ├── Makefile
│ └── README.md
├── strobogrammatic_number_iii
│ └── Makefile
├── top_k_frequent_elements
│ ├── Makefile
│ └── README.md
├── unique_word_abbreviation
│ └── Makefile
├── closest_binary_search_tree_value
│ ├── Makefile
│ └── README.md
├── combination_sum_iv
│ └── Makefile
├── count_numbers_with_unique_digits
│ └── Makefile
├── delete_node_in_a_linked_list
│ ├── Makefile
│ ├── README.md
│ └── main.cpp
├── find_k_pairs_with_smallest_sums
│ ├── Makefile
│ └── README.md
├── flatten_nested_list_iterator
│ ├── Makefile
│ └── README.md
├── integerToRoman
│ └── README.md
├── intersection_of_two_arrays_ii
│ ├── Makefile
│ └── README.md
├── longest_increasing_subsequence
│ ├── Makefile
│ └── README.md
├── maximum_product_of_word_lengths
│ └── Makefile
├── moving_average_from_data_stream
│ ├── Makefile
│ └── README.md
├── number_of_connected_components
│ └── Makefile
├── pow_x_n
│ └── README.md
├── product_of_array_except_self
│ ├── Makefile
│ └── README.md
├── range_sum_query_2d_immutable
│ └── Makefile
├── shuffle_an_array
│ └── Makefile
├── sparse_matrix_multiplication
│ ├── Makefile
│ └── README.md
├── stock2
│ ├── README.md
│ ├── Solution.java
│ └── main.py
├── binary_tree_vertical_order_traversal
│ └── Makefile
├── closest_binary_search_tree_value_ii
│ └── Makefile
├── count_of_smaller_number_after_self
│ └── Makefile
├── design_phone_directory
│ └── Makefile
├── different_ways_to_add_parentheses
│ ├── Makefile
│ └── README.md
├── lexicographical_numbers
│ ├── Makefile
│ └── README.md
├── linked_list_random_node
│ └── Makefile
├── longest_increasing_path_in_a_matrix
│ └── Makefile
├── max_sum_of_rectangle_no_larger_than_k
│ └── Makefile
├── maximum_size_subarray_sum_equals_k
│ └── Makefile
├── rearrange_string_k_distance_apart
│ └── Makefile
├── serialize_and_deserialize_binary_tree
│ └── Makefile
├── shortest_distance_from_all_buildings
│ └── Makefile
├── binary_tree_longest_consecutive_sequence
│ └── Makefile
├── find_median_from_data_stream
│ └── Makefile
├── insert_delete_getrandom_o1
│ └── Makefile
├── kth_smallest_sorted_matrix
│ └── Makefile
├── longestSubstringWithoutRepeatingCharacters
│ ├── Makefile
│ └── README.md
├── lowest_common_ancestor_of_a_binary_tree
│ └── Makefile
├── nQueensII
│ └── README.md
├── smallest_rectangle_enclosing_black_pixels
│ ├── Makefile
│ └── README.md
├── best_time_to_buy_and_sell_stock_with_cooldown
│ └── Makefile
├── letterCombinationPhoneNumber
│ ├── 200px-Telephone-keypad2.svg.png
│ └── README.md
├── lowest_common_ancestor_of_a_binary_search_tree
│ └── Makefile
├── verify_preorder_sequence_in_binary_search_tree
│ └── Makefile
├── verify_preorder_serialization_of_a_binary_tree
│ └── Makefile
├── implement_strstr
│ └── README.md
├── insert_delete_getrandom_o1_duplicate
│ └── Makefile
├── longest_substring_with_at_most_k_distinct_characters
│ ├── Makefile
│ └── README.md
├── summary_ranges
│ └── README.md
├── majority_element_ii
│ └── README.md
├── linkedListCycleII
│ └── README.md
├── climbStairs
│ ├── README.md
│ └── Solution.java
├── maxDepthOfBinaryTree
│ ├── README.md
│ └── Solution.java
├── plusOne
│ └── README.md
├── burst_balloons
│ └── Makefile
├── count_of_range_sum
│ └── Makefile
├── pascalII
│ └── README.md
├── sameTree
│ ├── README.md
│ └── Solution.java
├── remove_duplicate_sorted_list
│ └── README.md
├── sudokuSolver
│ └── README.md
├── data_stream_as_disjoint_intervals
│ ├── Makefile
│ └── README.md
├── minDepthOfTree
│ └── README.md
├── permutations
│ └── README.md
├── removeElement
│ └── README.md
├── remove_linkedlist_element
│ ├── README.md
│ └── Solution.java
├── merge2Sorted
│ └── README.md
├── missingRanges
│ └── README.md
├── contains_duplicate
│ ├── README.md
│ └── Solution.java
├── divideTwoInteger
│ └── README.md
├── balanced_binary_tree
│ └── README.md
├── pascal
│ └── README.md
├── romanToInt
│ └── README.md
├── singleNumber
│ ├── README.md
│ ├── Solution.java
│ └── main.py
├── restoreIPaddress
│ └── README.md
├── stock1
│ ├── README.md
│ └── Solution.java
├── binaryTreeMaxPathSum
│ └── README.md
├── longestCommonPrefix
│ └── README.md
├── number_1_bits
│ ├── README.md
│ └── Solution.java
├── preOrderTraversal
│ ├── README.md
│ └── main.py
├── mergeIntervals
│ └── README.md
├── remove_duplicate_from_sorted_array_ii
│ └── README.md
├── minPathSum
│ └── README.md
├── multiplyString
│ ├── Solution.java
│ └── README.md
├── valid_parentheses
│ └── README.md
├── factorial_trailing_zeroes
│ ├── README.md
│ └── Solution.java
├── rotateImage
│ └── README.md
├── combination
│ └── README.md
├── spiralMatrixII
│ └── README.md
├── rectangle_area
│ ├── README.md
│ └── Solution.java
├── spiralMatrix
│ └── README.md
├── swapInPairs
│ └── README.md
├── maxSubArray
│ ├── README.md
│ └── Solution.java
├── reverseLinkedList2
│ └── README.md
├── rotateList
│ └── README.md
├── bitwiseAndRange
│ ├── README.md
│ └── Solution.java
├── searchInRotatedList
│ └── README.md
├── inOrderTraversal
│ └── README.md
├── palindromePartition
│ └── README.md
├── excel_sheet_column_number
│ ├── README.md
│ └── Solution.java
├── recoverBinarySearchTree
│ └── README.md
├── linkedListCycle
│ └── README.md
├── interleaveString
│ └── README.md
├── reorderList
│ └── README.md
├── reverseInteger
│ └── main.py
├── shortest_palindrome
│ ├── main.py
│ └── README.md
├── partitionList
│ └── README.md
├── subset
│ └── README.md
├── jumpGame
│ ├── Solution.java
│ └── README.md
├── searchInsert
│ └── README.md
├── searchRange
│ └── README.md
├── nutsInOasis
│ └── NutsInOasisTest.java
├── removeNthNodeList
│ └── README.md
├── contains_duplicate_iii
│ └── README.md
├── lengthOfLastWord
│ └── README.md
├── reverseWordsInString
│ ├── README.md
│ └── solution.py
├── validNumber
│ └── README.md
├── kth_largest_element_in_an_array
│ └── README.md
├── postOrderTraversal
│ ├── README.md
│ └── main.py
├── excel_sheet_column_title
│ └── README.md
├── maximal_square
│ └── README.md
├── remove_duplicate_from_sorted_array
│ ├── README.md
│ └── main.py
├── permutationSequence
│ └── README.md
├── minimum_size_subarray_sum
│ └── README.md
├── largest_number
│ └── README.md
├── levelOrderII
│ └── README.md
├── remove_duplicate_sorted_list_ii
│ └── README.md
├── edit_distance
│ └── README.md
├── stock3
│ └── README.md
├── wordBreak
│ └── README.md
├── mergeSortedArray
│ ├── README.md
│ └── Solution.java
├── maximum_gap
│ └── README.md
├── min_stack
│ └── README.md
├── generateParentheses
│ └── README.md
├── wordBreakII
│ └── README.md
├── basic_calculator_ii
│ └── README.md
├── max_product_subarray
│ └── README.md
├── uniquePaths
│ └── README.md
├── longestValidParentheses
│ └── README.md
├── maximalRectangle
│ └── README.md
├── combination_sum_iii
│ └── README.md
├── count_complete_tree_nodes
│ └── README.md
├── longestSubstringWith2UniqueChars
│ └── README.md
├── pathSumII
│ └── README.md
├── validPalindrome
│ └── README.md
├── levelOrder
│ └── README.md
├── pathSum
│ └── README.md
├── triangle
│ ├── README.md
│ └── main.py
├── number_of_islands
│ └── README.md
├── uniqueBST
│ ├── README.md
│ └── Solution.java
├── decodeWays
│ └── README.md
├── simplifyPath
│ └── README.MD
├── uniquePathsII
│ └── README.md
├── sumRootToLeaf
│ └── README.md
├── invert_binary_tree
│ ├── README.md
│ └── Solution.java
├── longestConsecutiveSequence
│ └── README.md
├── reverse_bits
│ ├── README.md
│ └── Solution.java
├── firstMissingPositive
│ └── README.md
├── palindromeNumber
│ └── palindrome.cpp
├── singleNumberII
│ ├── Solution.java
│ └── README.md
├── uniqueBST2
│ └── README.md
├── zigzagConversion
│ └── README.md
├── count_primes
│ └── README.md
├── substringWithCatAllWords
│ └── README.md
├── binaryTreeZigzag
│ └── README.md
├── house_robber
│ └── Solution.java
├── validBST
│ ├── README.md
│ └── Solution.java
├── readNCharactersGivenRead4
│ └── README.md
├── wordSearch
│ └── README.md
├── binaryTreeRightSideView
│ └── README.md
├── longestPalindromeSubstring
│ └── README.md
├── reverseKgroup
│ └── README.md
├── searchInRotatedListII
│ └── README.md
├── symmetricTree
│ └── README.md
├── countAndSay
│ └── README.md
├── candy
│ ├── main.py
│ └── README.md
├── searchInMatrix
│ └── README.md
├── isomorphic_strings
│ └── README.md
├── binary_search_tree_iterator
│ └── README.md
├── find_minimum_in_rotated_sorted_array
│ └── README.md
├── find_minimum_in_rotated_sorted_array_II
│ └── README.md
├── copyListWithRandomPointer
│ └── README.md
├── partitionPainter
│ └── README.md
├── populateNextRightII
│ └── README.md
├── happy_number
│ └── README.md
├── rotate_array
│ └── README.md
├── fraction_to_recurring_decimal
│ └── README.md
├── insertInterval
│ └── README.md
├── repeated_DNA_sequences
│ └── README.md
├── surroundedRegions
│ └── README.md
├── wordLadderII
│ └── README.md
├── add_and_search_word_data_structure_design
│ └── README.md
├── maxPointsOnALine
│ └── README.md
└── trappingRainWater
│ └── README.md
├── xcode-project
└── leetcode-debugger
│ ├── leetcode-debugger
│ ├── README.md
│ ├── Makefile
│ └── main.cpp
│ └── leetcode-debugger.xcodeproj
│ ├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── xcuserdata
│ └── yubin.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
└── common_questions
├── lowest_common_ancestor
└── README.md
├── largest_slope
└── README.md
├── replace_word_in_string
└── README.md
├── number_all_factors
└── README.md
├── text_file_iterable
└── README.md
├── prime_count_in_range
└── README.md
├── print_one_to_hundred
└── Print.java
└── intimate_numbers
└── README.md
/src/reverse_linkedlist/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Reverse a singly linked list.
--------------------------------------------------------------------------------
/src/3sum_smaller/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/400_nth_digit/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/403_frog_jump/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/bomb_enemy/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/cloneGraph/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/decode_string/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/flip_game_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/insertionSortList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Sort a linked list using insertion sort.
--------------------------------------------------------------------------------
/src/is_subsequence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/setMatrixZero/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/263_ugly_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/401_binary_watch/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/402_remove_k_digits/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/elimination_game/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/evaluate_division/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/find_the_difference/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/integer_replacement/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/perfect_rectangle/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/random_pick_index/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/rotate_function/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/utf_8_validation/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/wiggle_sequence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/404_sum_of_left_leaves/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/buildTreePreOrderInOrder/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/contains_duplicate_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/sortColors/main.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/sortColors/main.pyc
--------------------------------------------------------------------------------
/src/405_convert_a_number_to_hex/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/407_trapping_rain_water_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/408_valid_word_abbreviation/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/buildTreeInOrderPostOrder/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/find_the_duplicate_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/guess_number_higher_or_lower/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/longest_absolute_file_path/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/xcode-project/leetcode-debugger/leetcode-debugger/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Solution
5 | ===
6 |
--------------------------------------------------------------------------------
/src/406_queue_reconstruction_by_height/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/first_unique_character_in_a_string/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/guess_number_higher_or_lower_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/2328_number_of_increasing_path_in_a_grid/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/containerWithMostWater/main.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/containerWithMostWater/main.pyc
--------------------------------------------------------------------------------
/src/squareRoot/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement int sqrt(int x).
4 |
5 | Compute and return the square root of x.
--------------------------------------------------------------------------------
/src/implement_trie_prefix_tree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement a trie with insert, search, and startsWith methods
4 |
--------------------------------------------------------------------------------
/src/power_of_two/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an integer, write a function to determine if it is a power of two.
5 |
--------------------------------------------------------------------------------
/xcode-project/leetcode-debugger/leetcode-debugger/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/longest_substring_with_at_least_k_repeating_characters/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
--------------------------------------------------------------------------------
/src/implement_queue_using_stacks/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o
3 | run:
4 | clang++ main.cpp -o main.o
5 | ./main.o
6 |
--------------------------------------------------------------------------------
/src/3Sum/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/anagram/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/atoi/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/h_index/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/increasing_triplet_subsequence/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/increasing_triplet_subsequence/README.md
--------------------------------------------------------------------------------
/src/largestRectangleHistogram/histogram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/largestRectangleHistogram/histogram.png
--------------------------------------------------------------------------------
/src/two_sum/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/3SumClosest/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/addBinary/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/add_digits/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/coin_change/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/flip_game/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/game_of_life/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/h_index_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/mergeKSorted/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/nim_game/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/paint_fence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/paint_house/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sortedArrayToBST/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
--------------------------------------------------------------------------------
/src/super_pow/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/wiggle_sort/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/word_pattern/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/add_two_numbers/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/additive_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/alien_dictionary/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/basic_calculator/makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/binary_tree_paths/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/bulb_switcher/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/bulls_and_cows/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/counting_bits/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/design_snake_game/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/design_twitter/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/first_bad_version/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/flatten_2d_vector/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/graph_valid_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/house_robber_iii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/integer_break/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/largestRectangleHistogram/histogram_area.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/largestRectangleHistogram/histogram_area.png
--------------------------------------------------------------------------------
/src/line_reflection/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/meeting_rooms/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/meeting_rooms_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/missing_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/moving_zeroes/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/paint_house_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/palindrome_pairs/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/patching_array/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/peeking_iterator/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/perfect_squares/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/power_of_four/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/power_of_three/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/range_addition/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/reverse_string/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/self_crossing/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/single_number_iii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sortList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Sort a linked list in O(n log n) time using constant space complexity.
4 |
5 | Solution
6 | ===
7 | Merge sort
--------------------------------------------------------------------------------
/src/super_ugly_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/ugly_number_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/valid_anagram/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/walls_and_gates/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/wiggle_sort_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/word_pattern_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/zigzag_iterator/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/best_meeting_point/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/create_maximum_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/design_hit_counter/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/design_tic_tac_toe/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/factor_combinations/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/find_the_celebrity/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/group_shifted_strings/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/largest_bst_subtree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/logger_rate_limiter/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/minimum_height_trees/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/nested_list_weight_sum/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/number_of_digit_one/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/number_of_islands_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/odd_even_linked_list/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/palindrome_linked_list/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/palindrome_permutation/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/plus_one_linked_list/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/reconstruct_itinerary/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/russian_doll_envelopes/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/search_a_2d_matrix_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/shortest_word_distance/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sliding_window_maximum/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sort_transformed_array/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sortedListToBST/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
--------------------------------------------------------------------------------
/src/strobogrammatic_number/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/sum_of_two_integers/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/valid_perfect_square/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/water_and_jug_problem/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/android_unlock_patterns/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/count_univalue_subtrees/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/encode_and_decode_strings/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/expression_add_operators/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/find_leaves_of_binary_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/generalized_abbreviation/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/inorder_successor_in_bst/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/integer_to_english_words/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/intersection_of_two_arrays/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/isValidSudoku/250px-Sudoku-by-L2G-20050714.svg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/isValidSudoku/250px-Sudoku-by-L2G-20050714.svg.png
--------------------------------------------------------------------------------
/src/largest_divisible_subset/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/mini_parser/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/nested_list_weight_sum_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/palindrome_permutation_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/power_of_two/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public boolean isPowerOfTwo(int n) {
3 | return n > 0 && (n & (n - 1)) == 0;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/src/range_sum_query_2d_mutable/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/range_sum_query_immutable/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/range_sum_query_mutable/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/ransom_note/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/remove_duplicate_letters/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/remove_invalid_parentheses/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/reverse_vowels_of_a_string/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/shortest_word_distance_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/shortest_word_distance_iii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/strobogrammatic_number_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/strobogrammatic_number_iii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/top_k_frequent_elements/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/unique_word_abbreviation/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/closest_binary_search_tree_value/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/combination_sum_iv/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/count_numbers_with_unique_digits/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/delete_node_in_a_linked_list/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/find_k_pairs_with_smallest_sums/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/flatten_nested_list_iterator/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/increasing_triplet_subsequence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/integerToRoman/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an integer, convert it to a roman numeral.
4 |
5 | Input is guaranteed to be within the range from 1 to 3999.
--------------------------------------------------------------------------------
/src/intersection_of_two_arrays_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/longest_increasing_subsequence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/maximum_product_of_word_lengths/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/moving_average_from_data_stream/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/number_of_connected_components/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/pow_x_n/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement pow(x, n).
4 |
5 | Solution
6 | ===
7 | Edge case guarding:
8 |
9 | x == 0?
10 |
11 | n < 0 ?
12 |
--------------------------------------------------------------------------------
/src/product_of_array_except_self/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/range_sum_query_2d_immutable/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/reverse_string/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
--------------------------------------------------------------------------------
/src/shuffle_an_array/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/sparse_matrix_multiplication/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/stock2/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Say you have an array for which the ith element is the price of a given
4 | stock on day i.
5 |
6 | unlimited buy and sell
7 |
--------------------------------------------------------------------------------
/src/binary_tree_vertical_order_traversal/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/closest_binary_search_tree_value_ii/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/count_of_smaller_number_after_self/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/design_phone_directory/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/different_ways_to_add_parentheses/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/lexicographical_numbers/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/linked_list_random_node/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/longest_increasing_path_in_a_matrix/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/max_sum_of_rectangle_no_larger_than_k/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/maximum_size_subarray_sum_equals_k/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/rearrange_string_k_distance_apart/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/serialize_and_deserialize_binary_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/shortest_distance_from_all_buildings/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/binary_tree_longest_consecutive_sequence/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/find_median_from_data_stream/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/insert_delete_getrandom_o1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/kth_smallest_sorted_matrix/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/longestSubstringWithoutRepeatingCharacters/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/lowest_common_ancestor_of_a_binary_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/nQueensII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Follow up for N-Queens problem.
4 |
5 | Now, instead outputting board configurations, return the total number of distinct solutions.
--------------------------------------------------------------------------------
/src/smallest_rectangle_enclosing_black_pixels/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/best_time_to_buy_and_sell_stock_with_cooldown/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/letterCombinationPhoneNumber/200px-Telephone-keypad2.svg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yubinbai/leetcode/HEAD/src/letterCombinationPhoneNumber/200px-Telephone-keypad2.svg.png
--------------------------------------------------------------------------------
/src/lowest_common_ancestor_of_a_binary_search_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/verify_preorder_sequence_in_binary_search_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/verify_preorder_serialization_of_a_binary_tree/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/common_questions/lowest_common_ancestor/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | find the lowest common ancestor of two nodes in a tree
5 |
6 | Solution
7 | ===
8 |
9 | post-order traversal
--------------------------------------------------------------------------------
/src/implement_strstr/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement strStr().
4 |
5 | Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
--------------------------------------------------------------------------------
/src/insert_delete_getrandom_o1_duplicate/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 | ./main.o
4 |
5 | run:
6 | clang++ main.cpp -o main.o -std=c++11
7 | ./main.o
8 |
--------------------------------------------------------------------------------
/src/longest_substring_with_at_most_k_distinct_characters/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
--------------------------------------------------------------------------------
/src/palindrome_linked_list/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a singly linked list, determine if it is a palindrome.
4 |
5 | Follow up:
6 | Could you do it in O(n) time and O(1) space?
--------------------------------------------------------------------------------
/src/buildTreeInOrderPostOrder/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given inorder and postorder traversal of a tree, construct the binary tree.
4 |
5 | Solution
6 | ===
7 | Post order to find root, divide and conquer
--------------------------------------------------------------------------------
/src/buildTreePreOrderInOrder/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given inorder and preorder traversal of a tree, construct the binary tree.
4 |
5 | Solution
6 | ===
7 | Pre order to find root, divide and conquer
--------------------------------------------------------------------------------
/src/summary_ranges/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a sorted integer array without duplicates, return the summary of its ranges.
5 |
6 | For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].
--------------------------------------------------------------------------------
/common_questions/largest_slope/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | There are N points on a plane. Each pair of points determines a line.
4 |
5 | Fine the line that has the largest slope
6 |
7 | Solution
8 | ===
9 |
--------------------------------------------------------------------------------
/src/majority_element_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.
5 |
--------------------------------------------------------------------------------
/src/sum_of_two_integers/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
4 |
5 | Example:
6 | Given a = 1 and b = 2, return 3.
7 |
8 |
--------------------------------------------------------------------------------
/src/linkedListCycleII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a linked list, return the node where the cycle begins. If there is no cycle, return *null*.
4 |
5 | Follow up:
6 | Can you solve it without using extra space?
--------------------------------------------------------------------------------
/src/palindrome_permutation/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string, determine if a permutation of the string could form a palindrome.
4 |
5 | For example,
6 | "code" -> False, "aab" -> True, "carerac" -> True.
--------------------------------------------------------------------------------
/src/climbStairs/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | You are climbing a stair case. It takes n steps to reach to the top.
4 |
5 | Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
--------------------------------------------------------------------------------
/src/maxDepthOfBinaryTree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, find its maximum depth.
4 |
5 | The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
--------------------------------------------------------------------------------
/src/plusOne/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a non-negative number represented as an array of digits, plus one to the number.
4 |
5 | The digits are stored such that the most significant digit is at the head of the list.
--------------------------------------------------------------------------------
/src/burst_balloons/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
8 | run1:
9 | clang++ main1.cpp -o main1.o -std=c++11
10 | ./main1.o
11 |
--------------------------------------------------------------------------------
/src/count_of_range_sum/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
8 | run2:
9 | clang++ main2.cpp -o main2.o -std=c++11
10 | ./main2.o
11 |
--------------------------------------------------------------------------------
/src/pascalII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an index k, return the kth row of the Pascal's triangle.
4 |
5 | For example, given k = 3,
6 | Return [1,3,3,1].
7 |
8 | Note: Could you optimize your algorithm to use only O(k) extra space?
--------------------------------------------------------------------------------
/src/reverse_vowels_of_a_string/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
--------------------------------------------------------------------------------
/src/sameTree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given two binary trees, write a function to check if they are equal or not.
5 |
6 | Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
--------------------------------------------------------------------------------
/src/inorder_successor_in_bst/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a binary search tree and a node in it, find the in-order successor of that node in the BST.
5 | Note: If the given node has no in-order successor in the tree, return null.
6 |
--------------------------------------------------------------------------------
/src/remove_duplicate_sorted_list/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a sorted linked list, delete all duplicates such that each element appear only once.
4 |
5 | For example,
6 | Given 1->1->2, return 1->2.
7 | Given 1->1->2->3->3, return 1->2->3.
--------------------------------------------------------------------------------
/src/sudokuSolver/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Write a program to solve a Sudoku puzzle by filling the empty cells.
5 |
6 | Empty cells are indicated by the character '.'.
7 |
8 | You may assume that there will be only one unique solution.
--------------------------------------------------------------------------------
/src/wiggle_sort/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]....
4 | For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].
5 |
--------------------------------------------------------------------------------
/common_questions/replace_word_in_string/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ====
3 | replaces every instances of string 'find' with string 'repl'
4 | returned the modified string
5 |
6 | Solution
7 | ===
8 | String builder, keeping finding next needle in long string
--------------------------------------------------------------------------------
/src/data_stream_as_disjoint_intervals/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | clang++ main.cpp -o main.o -std=c++11
3 |
4 | run:
5 | clang++ main.cpp -o main.o -std=c++11
6 | ./main.o
7 |
8 | run2:
9 | clang++ main2.cpp -o main.o -std=c++11
10 | ./main.o
11 |
--------------------------------------------------------------------------------
/src/minDepthOfTree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, find its minimum depth.
4 |
5 | The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
6 |
7 | Solution
8 | ===
9 | BFS
--------------------------------------------------------------------------------
/src/permutations/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a collection of numbers, return all possible permutations.
4 |
5 | For example,
6 |
7 | [1,2,3] have the following permutations:
8 |
9 | [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
--------------------------------------------------------------------------------
/src/power_of_four/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
--------------------------------------------------------------------------------
/src/removeElement/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an array and a value, remove all instances of that value in place and return the new length.
5 |
6 | The order of elements can be changed. It doesn't matter what you leave beyond the new length.
--------------------------------------------------------------------------------
/src/remove_linkedlist_element/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Remove all elements from a linked list of integers that have value val.
4 |
5 | Example
6 | Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
7 | Return: 1 --> 2 --> 3 --> 4 --> 5
8 |
9 |
--------------------------------------------------------------------------------
/src/merge2Sorted/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
4 |
5 | Solution
6 | ===
7 | Keep track of two lists and generate
--------------------------------------------------------------------------------
/src/missingRanges/README.md:
--------------------------------------------------------------------------------
1 | Missing Ranges
2 | ===
3 |
4 | Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing ranges.
5 |
6 | For example, given [0, 1, 3, 50, 75], return [“2”, “4->49”, “51->74”, “76->99”]
--------------------------------------------------------------------------------
/src/contains_duplicate/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
--------------------------------------------------------------------------------
/src/divideTwoInteger/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Divide two integers without using multiplication, division and mod operator.
4 |
5 | Solution
6 | ===
7 | Long division in binary [Wikipedia](http://www.wikiwand.com/en/Division_algorithm#/Long_division)
8 |
--------------------------------------------------------------------------------
/src/intersection_of_two_arrays/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
Note:
Each element in the result must be unique.
The result can be in any order.
--------------------------------------------------------------------------------
/xcode-project/leetcode-debugger/leetcode-debugger.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/common_questions/number_all_factors/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ====
3 |
4 |
5 | Given a number, return all ways it can be factorized
6 |
7 | example:
8 |
9 | 12
10 |
11 | 1 * 12
12 | 2 * 2 * 3
13 | 2 * 6
14 | 3 * 4
15 |
16 | Solution
17 | ===
18 | Backtracking
--------------------------------------------------------------------------------
/src/balanced_binary_tree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, determine if it is height-balanced.
4 |
5 | For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
--------------------------------------------------------------------------------
/src/longest_substring_with_at_most_k_distinct_characters/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.
For example, Given s = "eceba",
T is "ece" which its length is 3.
Solution
===
Sliding pointers
--------------------------------------------------------------------------------
/src/pascal/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given numRows, generate the first numRows of Pascal's triangle.
4 |
5 | For example, given numRows = 5,
6 | Return
7 |
8 | [
9 | [1],
10 | [1,1],
11 | [1,2,1],
12 | [1,3,3,1],
13 | [1,4,6,4,1]
14 | ]
15 |
--------------------------------------------------------------------------------
/src/romanToInt/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a roman numeral, convert it to an integer.
5 |
6 | Input is guaranteed to be within the range from 1 to 3999.
7 |
8 | Solution
9 | ===
10 |
11 | Scan from last char, determine what the value is based on current value
--------------------------------------------------------------------------------
/src/singleNumber/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of integers, every element appears twice except for one.
4 | Find that single one.
5 |
6 | Note:
7 | Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
8 |
9 |
--------------------------------------------------------------------------------
/src/addBinary/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given two binary strings, return their sum (also a binary string).
4 |
5 | For example,
6 | a = "11"
7 | b = "1"
8 | Return "100".
9 |
10 | Solution
11 | ===
12 | Scan from end of strings, keep track of carry, use StringBuilder
--------------------------------------------------------------------------------
/src/restoreIPaddress/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string containing only digits, restore it by returning all possible valid IP address combinations.
4 |
5 | For example:
6 | Given "25525511135",
7 |
8 | return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
--------------------------------------------------------------------------------
/src/stock1/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Say you have an array for which the i-th element is the price of a given stock on day i.
4 |
5 | If you were only permitted to buy one share of the stock and sell one share of the stock, design an algorithm to find the best times to buy and sell.
--------------------------------------------------------------------------------
/src/binaryTreeMaxPathSum/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, find the maximum path sum.
4 |
5 | The path may start and end at any node in the tree.
6 |
7 | For example:
8 | Given the below binary tree,
9 |
10 | 1
11 | / \
12 | 2 3
13 | Return 6.
--------------------------------------------------------------------------------
/src/binary_tree_paths/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a binary tree, return all root-to-leaf paths.
5 |
6 | For example, given the following binary tree:
7 |
8 | 1
9 | / \
10 | 2 3
11 | \
12 | 5
13 | All root-to-leaf paths are:
14 |
15 | ["1->2->5", "1->3"]
--------------------------------------------------------------------------------
/src/longestCommonPrefix/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Longest Common Prefix
4 | Write a function to find the longest common prefix string amongst an array of strings.
5 |
6 | Solution
7 | ===
8 |
9 | Find common prefix of two strs, then reduce the function to the whole list
10 |
--------------------------------------------------------------------------------
/src/meeting_rooms/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
4 |
5 | For example,
6 |
7 | Given [[0, 30],[5, 10],[15, 20]],
8 |
9 | return false.
--------------------------------------------------------------------------------
/src/meeting_rooms_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.
5 |
6 | For example,
7 | Given [[0, 30],[5, 10],[15, 20]],
8 | return 2.
--------------------------------------------------------------------------------
/src/number_1_bits/README.md:
--------------------------------------------------------------------------------
1 | Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
2 |
3 | For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.
--------------------------------------------------------------------------------
/src/perfect_squares/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.
4 |
5 | For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return 2 because 13 = 4 + 9.
6 |
--------------------------------------------------------------------------------
/src/preOrderTraversal/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, return the preorder traversal of its nodes' values.
4 |
5 | For example:
6 | Given binary tree {1,#,2,3},
7 | 1
8 | \
9 | 2
10 | /
11 | 3
12 | return [1,2,3].
--------------------------------------------------------------------------------
/src/mergeIntervals/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a collection of intervals, merge all overlapping intervals.
4 |
5 | For example,
6 | Given [1,3],[2,6],[8,10],[15,18],
7 | return [1,6],[8,10],[15,18].
8 |
9 | Solution
10 | ===
11 |
12 | Sort and merge adjacent ones, O(n logn)
--------------------------------------------------------------------------------
/src/remove_duplicate_from_sorted_array_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Follow up for "Remove Duplicates":
4 | What if duplicates are allowed at most twice?
5 |
6 | For example,
7 | Given sorted array A = [1,1,1,2,2,3],
8 |
9 | Your function should return length = 5, and A is now [1,1,2,2,3].
--------------------------------------------------------------------------------
/src/contains_duplicate_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.
4 |
5 | Solution
6 | ===
7 |
8 | LRU cache
--------------------------------------------------------------------------------
/src/minPathSum/README.md:
--------------------------------------------------------------------------------
1 | Problem
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 |
7 | Solution
8 | ===
9 | DP
--------------------------------------------------------------------------------
/src/multiplyString/Solution.java:
--------------------------------------------------------------------------------
1 | import java.math.*;
2 | public class Solution {
3 | public String multiply(String num1, String num2) {
4 | BigInteger b1 = new BigInteger(num1);
5 | BigInteger b2 = new BigInteger(num2);
6 | return b1.multiply(b2).toString();
7 | }
8 | }
--------------------------------------------------------------------------------
/src/valid_parentheses/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Valid Parentheses
4 | Given a string containing just the characters '(', ')', '{', '}', '['and ']', determine if the input string is valid.
5 |
6 | The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
--------------------------------------------------------------------------------
/src/factorial_trailing_zeroes/README.md:
--------------------------------------------------------------------------------
1 | Factorial Trailing Zeroes
2 | ===
3 |
4 | Given an integer n, return the number of trailing zeroes in n!.
5 |
6 | Note: Your solution should be in logarithmic time complexity.
7 |
8 | Solution
9 | ===
10 | 5 occurs much more frequently than 2. Count 5s.
11 |
--------------------------------------------------------------------------------
/src/rotateImage/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | You are given an n x n 2D matrix representing an image.
5 |
6 | Rotate the image by 90 degrees (clockwise).
7 |
8 | Follow up:
9 | Could you do this in-place?
10 |
11 | Solution
12 | ===
13 | Use a graph to figure out the cooridinates of each point
--------------------------------------------------------------------------------
/src/top_k_frequent_elements/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
For example,
MovingAverage m = new MovingAverage(3);
m.next(1) = 1
m.next(10) = (1 + 10) / 2
m.next(3) = (1 + 10 + 3) / 3
m.next(5) = (10 + 3 + 5) / 3
--------------------------------------------------------------------------------
/src/combination/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
4 |
5 | For example,
6 | If n = 4 and k = 2, a solution is:
7 |
8 | [
9 | [2,4],
10 | [3,4],
11 | [2,3],
12 | [1,2],
13 | [1,3],
14 | [1,4],
15 | ]
16 |
--------------------------------------------------------------------------------
/src/moving_average_from_data_stream/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
For example,
MovingAverage m = new MovingAverage(3);
m.next(1) = 1
m.next(10) = (1 + 10) / 2
m.next(3) = (1 + 10 + 3) / 3
m.next(5) = (10 + 3 + 5) / 3
--------------------------------------------------------------------------------
/src/spiralMatrixII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
4 |
5 | For example,
6 | Given n = 3,
7 |
8 | You should return the following matrix:
9 |
10 | [
11 | [ 1, 2, 3 ],
12 | [ 8, 9, 4 ],
13 | [ 7, 6, 5 ]
14 | ]
--------------------------------------------------------------------------------
/src/implement_queue_using_stacks/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement the following operations of a queue using stacks.
4 |
5 | push(x) -- Push element x to the back of queue.
6 | pop() -- Removes the element from in front of queue.
7 | peek() -- Get the front element.
8 | empty() -- Return whether the queue is empty.
9 |
--------------------------------------------------------------------------------
/src/multiplyString/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given two numbers represented as strings, return multiplication of the numbers as a string.
4 |
5 | Note: The numbers can be arbitrarily large and are non-negative.
6 |
7 | Solution
8 | ===
9 |
10 | Long multiplication, already implemented in Java and Python libraries
--------------------------------------------------------------------------------
/src/palindrome_permutation_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.
5 |
6 | For example:
7 |
8 | Given s = "aabb", return ["abba", "baab"].
9 |
10 | Given s = "abc", return [].
--------------------------------------------------------------------------------
/src/rectangle_area/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Find the total area covered by two rectilinear rectangles in a 2D plane.
5 |
6 | Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.
7 |
8 | Rectangle Area
9 | Assume that the total area is never beyond the maximum possible value of int.
--------------------------------------------------------------------------------
/src/spiralMatrix/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
4 |
5 | For example,
6 | Given the following matrix:
7 |
8 | [
9 | [ 1, 2, 3 ],
10 | [ 4, 5, 6 ],
11 | [ 7, 8, 9 ]
12 | ]
13 | You should return [1,2,3,6,9,8,7,4,5].
--------------------------------------------------------------------------------
/src/swapInPairs/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a linked list, swap every two adjacent nodes and return its head.
4 | For example,
5 | Given 1->2->3->4, you should return the list as 2->1->4->3.
6 | Your algorithm should use only constant space. You may not modify the
7 | values in the list, only nodes itself can be changed.
8 |
--------------------------------------------------------------------------------
/common_questions/text_file_iterable/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement a (Java) Iterable object that iterates lines one by one from a text file.
4 | A reference to a file.
5 |
6 |
7 | Solution
8 | ===
9 |
10 | Use BufferedReader to get file in
11 |
12 | Note: *array* or *Iterable* can be used in for..each loop
13 |
14 |
--------------------------------------------------------------------------------
/src/anagram/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of strings, return all groups of strings that are anagrams.
4 |
5 | Note: All inputs will be in lower-case.
6 |
7 | Solution
8 | ===
9 |
10 | Group strings by their char counts, an easy way to implement is to sort the char array of the string and use this as key of hash map.
--------------------------------------------------------------------------------
/src/closest_binary_search_tree_value/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.
5 | Note:
6 | Given target value is a floating point.
7 | You are guaranteed to have only one unique value in the BST that is closest to the target.
8 |
9 |
--------------------------------------------------------------------------------
/src/plus_one_linked_list/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a non-negative number represented as a singly linked list of digits, plus one to the number.
5 |
6 | The digits are stored such that the most significant digit is at the head of the list.
7 |
8 | Example:
9 | Input:
10 | 1->2->3
11 |
12 | Output:
13 | 1->2->4
14 |
--------------------------------------------------------------------------------
/src/delete_node_in_a_linked_list/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
5 |
6 | Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.
--------------------------------------------------------------------------------
/src/integer_break/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.
For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).
Note: you may assume that n is not less than 2.
--------------------------------------------------------------------------------
/src/maxSubArray/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
4 |
5 | For example, given the array [−2,1,−3,4,−1,2,1,−5,4],
6 | the contiguous subarray [4,−1,2,1] has the largest sum = 6.
7 |
8 | Solution
9 | ===
10 | Kadane's algorithm, from CLRS
--------------------------------------------------------------------------------
/src/reverseLinkedList2/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Reverse a linked list from position m to n. Do it in-place and in one-pass.
5 |
6 | For example:
7 | Given 1->2->3->4->5->NULL, m = 2 and n = 4,
8 |
9 | return 1->4->3->2->5->NULL.
10 |
11 | Note:
12 | Given m, n satisfy the following condition:
13 | 1 ≤ m ≤ n ≤ length of list.
--------------------------------------------------------------------------------
/src/strobogrammatic_number/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
4 | Write a function to determine if a number is strobogrammatic. The number is represented as a string.
5 | For example, the numbers "69", "88", and "818" are all strobogrammatic.
6 |
--------------------------------------------------------------------------------
/src/super_pow/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Your task is to calculate a ** b mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
5 |
6 | Example1:
7 |
8 | a = 2
9 | b = [3]
10 |
11 | Result: 8
12 | Example2:
13 |
14 | a = 2
15 | b = [1,0]
16 |
17 | Result: 1024
18 |
--------------------------------------------------------------------------------
/src/valid_anagram/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given two strings s and t, write a function to determine if t is an anagram of s.
5 |
6 | For example,
7 | s = "anagram", t = "nagaram", return true.
8 | s = "rat", t = "car", return false.
9 |
10 | Note:
11 | You may assume the string contains only lowercase alphabets.
--------------------------------------------------------------------------------
/src/263_ugly_number/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Write a program to check whether a given number is an ugly number.
4 |
5 | Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
6 |
7 | Note that 1 is typically treated as an ugly number.
--------------------------------------------------------------------------------
/src/contains_duplicate/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 | public boolean containsDuplicate(int[] nums) {
5 | Arrays.sort(nums);
6 | for (int i = 1; i < nums.length; ++i) {
7 | if (nums[i] == nums[i - 1]) return true;
8 | }
9 | return false;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/rotateList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a list, rotate the list to the right by k places, where k is non-negative.
5 |
6 | For example:
7 | Given 1->2->3->4->5->NULL and k = 2,
8 | return 4->5->1->2->3->NULL.
9 |
10 | Solution
11 | ===
12 |
13 | Count the length of list, break list into two lists and cat.
14 |
--------------------------------------------------------------------------------
/src/bitwiseAndRange/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.
4 |
5 | For example, given the range [5, 7], you should return 4.
6 |
7 | Solution
8 | ===
9 |
10 | only possible for the prefix in the binary form, iterate to find prefix
11 |
--------------------------------------------------------------------------------
/src/searchInRotatedList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Suppose a sorted array is rotated at some pivot unknown to you beforehand.
4 |
5 | (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
6 |
7 | You are given a target value to search. If found in the array return its index, otherwise return -1.
8 |
9 | You may assume no duplicate exists in the array.
--------------------------------------------------------------------------------
/src/shortest_word_distance/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given two strings s and t, write a function to determine if t is an anagram of s.
5 |
6 | For example,
7 | s = "anagram", t = "nagaram", return true.
8 | s = "rat", t = "car", return false.
9 |
10 | Note:
11 | You may assume the string contains only lowercase alphabets.
--------------------------------------------------------------------------------
/src/valid_perfect_square/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a positive integer num, write a function which returns True if num is a perfect square else False.
4 |
5 | Note: Do not use any built-in library function such as sqrt.
6 |
7 | Example 1:
8 |
9 | Input: 16
10 | Returns: True
11 | Example 2:
12 |
13 | Input: 14
14 | Returns: False
15 |
--------------------------------------------------------------------------------
/src/flatten_2d_vector/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement an iterator to flatten a 2d vector.
4 |
5 | For example,
6 |
7 | Given 2d vector =
8 |
9 | [
10 | [1,2],
11 | [3],
12 | [4,5,6]
13 | ]
14 |
15 | By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,2,3,4,5,6].
--------------------------------------------------------------------------------
/src/generalized_abbreviation/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Write a function to generate the generalized abbreviations of a word.
5 |
6 | Example:
7 | Given word = "word", return the following list (order does not matter):
8 | ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]
9 |
10 |
--------------------------------------------------------------------------------
/src/inOrderTraversal/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, return the inorder traversal of its nodes' values.
4 |
5 | For example:
6 | Given binary tree {1,#,2,3},
7 | 1
8 | \
9 | 2
10 | /
11 | 3
12 | return [1,3,2].
13 |
14 | Note: Recursive solution is trivial, could you do it iteratively?
--------------------------------------------------------------------------------
/src/palindromePartition/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string s, partition s such that every substring of the partition is a palindrome.
4 |
5 | Return all possible palindrome partitioning of s.
6 |
7 | For example, given s = "aab",
8 | Return
9 |
10 | [
11 | ["aa","b"],
12 | ["a","a","b"]
13 | ]
14 |
15 | Solution
16 | ===
17 | Backtrack
--------------------------------------------------------------------------------
/src/addBinary/main.py:
--------------------------------------------------------------------------------
1 | class Solution:
2 | # @param a, a string
3 | # @param b, a string
4 | # @return a string
5 |
6 | def addBinary(self, a, b):
7 | aBin = int(a, 2)
8 | bBin = int(b, 2)
9 | return bin(aBin + bBin)[2:]
10 |
11 | if __name__ == '__main__':
12 | s = Solution()
13 | print s.addBinary("11", "1")
14 |
--------------------------------------------------------------------------------
/src/count_univalue_subtrees/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, count the number of uni-value subtrees.
4 |
5 | A Uni-value subtree means all nodes of the subtree have the same value.
6 |
7 | For example:
8 |
9 | Given binary tree,
10 |
11 | 5
12 | / \
13 | 1 5
14 | / \ \
15 | 5 5 5
16 |
17 | return 4.
18 |
--------------------------------------------------------------------------------
/src/excel_sheet_column_number/README.md:
--------------------------------------------------------------------------------
1 | Excel Sheet Column Number
2 | ===
3 |
4 | Related to question Excel Sheet Column Title
5 |
6 | Given a column title as appear in an Excel sheet, return its corresponding column number.
7 |
8 | For example:
9 |
10 | A -> 1
11 | B -> 2
12 | C -> 3
13 | ...
14 | Z -> 26
15 | AA -> 27
16 | AB -> 28
--------------------------------------------------------------------------------
/src/paint_fence/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | There is a fence with n posts, each post can be painted with one of the k colors.
4 |
5 | You have to paint all the posts such that no more than two adjacent fence posts have the same color.
6 |
7 | Return the total number of ways you can paint the fence.
8 |
9 | Note:
10 | n and k are non-negative integers.
11 |
--------------------------------------------------------------------------------
/src/recoverBinarySearchTree/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Two elements of a binary search tree (BST) are swapped by mistake.
4 |
5 | Recover the tree without changing its structure.
6 |
7 | Note:
8 | A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?
9 |
10 | Solution
11 | ===
12 | In-order traversal with validations
--------------------------------------------------------------------------------
/common_questions/prime_count_in_range/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given ints *a* and *b*, how many primes are there in the interval [*a*, *b*) ?
5 |
6 | a < b <= 1e12
7 | b - a <= 1e6
8 |
9 | Solution
10 | ===
11 |
12 | all numbers small than *b* will have factors smaller than sqrt(b)
13 |
14 | use sieve between a and b, for all primes in [ 2, sqrt(b) )
15 |
--------------------------------------------------------------------------------
/src/linkedListCycle/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a linked list, determine if it has a cycle in it.
4 |
5 | Follow up:
6 | Can you solve it without using extra space?
7 |
8 | Solution
9 | ===
10 |
11 | [http://en.wikipedia.org/wiki/Floyd%27s_cycle-finding_algorithm#Tortoise_and_hare](http://en.wikipedia.org/wiki/Floyd%27s_cycle-finding_algorithm#Tortoise_and_hare)
--------------------------------------------------------------------------------
/src/missing_number/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
5 |
6 | For example,
7 | Given nums = [0, 1, 3] return 2.
8 |
9 | Note:
10 | Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
--------------------------------------------------------------------------------
/src/nested_list_weight_sum/README.md:
--------------------------------------------------------------------------------
1 | Problem
===
Given a nested list of integers, returns the sum of all integers in the list weighted by their depth
For example, given the list {{1,1},2,{1,1}} the function should return 10 (four 1's at depth 2, one *2 at depth 1)
Given the list {1,{4,{6}}} the function should return 27 (one 1 at depth 1, one 4 at depth 2, and *one 6 at depth 3)
--------------------------------------------------------------------------------
/src/integer_to_english_words/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.
4 |
5 | For example,
6 | 123 -> "One Hundred Twenty Three"
7 | 12345 -> "Twelve Thousand Three Hundred Forty Five"
8 | 1234567 -> "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
9 |
--------------------------------------------------------------------------------
/src/interleaveString/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
4 |
5 | For example,
6 | Given:
7 | s1 = "aabcc",
8 | s2 = "dbbca",
9 |
10 | When s3 = "aadbbcbcac", return true.
11 | When s3 = "aadbbbaccc", return false.
12 |
13 | Solution
14 | ===
15 |
16 | DP, construct s3 from s1 and s2
17 |
18 |
--------------------------------------------------------------------------------
/src/reorderList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a singly linked list L: L0→L1→…→Ln-1→Ln,
4 | reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
5 |
6 | You must do this in-place without altering the nodes' values.
7 |
8 | For example,
9 | Given {1,2,3,4}, reorder it to {1,4,2,3}.
10 |
11 | Solution
12 | ===
13 | Split list in two, reverse second part, and interleave the two parts
--------------------------------------------------------------------------------
/src/reverseInteger/main.py:
--------------------------------------------------------------------------------
1 | class Solution:
2 | # @return an integer
3 | def reverse(self, x):
4 | s = str(x)
5 | if s[0] == '-':
6 | return int("-" + s[-1:0:-1])
7 | else:
8 | return int(s[::-1])
9 |
10 | if __name__ == '__main__':
11 | s = Solution()
12 | print s.reverse(123)
13 | print s.reverse(-123)
14 |
--------------------------------------------------------------------------------
/src/shortest_palindrome/main.py:
--------------------------------------------------------------------------------
1 | class Solution:
2 | def shortestPalindrome(self, s):
3 | r = s[::-1]
4 | for i in range(len(s) + 1):
5 | if s.startswith(r[i:]):
6 | return(r[:i] + s)
7 |
8 | if __name__ == '__main__':
9 | s = Solution()
10 | print s.shortestPalindrome("a")
11 | print s.shortestPalindrome("abcd")
12 |
--------------------------------------------------------------------------------
/xcode-project/leetcode-debugger/leetcode-debugger.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/partitionList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Partition List
4 | Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
5 |
6 | You should preserve the original relative order of the nodes in each of the two partitions.
7 |
8 | For example,
9 | Given 1->4->3->2->5->2 and x = 3,
10 | return 1->2->2->4->3->5.
--------------------------------------------------------------------------------
/src/subset/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a collection of integers that might contain duplicates, S, return all possible subsets.
4 |
5 | Note:
6 | Elements in a subset must be in non-descending order.
7 | The solution set must not contain duplicate subsets.
8 |
9 | For example,
10 | If S = [1,2,2], a solution is:
11 | [[2], [1], [1,2,2], [2,2], [1,2], [] ]
12 |
--------------------------------------------------------------------------------
/src/jumpGame/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public boolean canJump(int[] A) {
3 | int curr = A[0];
4 | for (int i = 0; i < A.length; i++)
5 | if (i > curr) {
6 | return false;
7 | } else {
8 | curr = Math.max(curr, i + A[i]);
9 | }
10 | return curr >= A.length - 1;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/remove_duplicate_letters/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.
4 |
5 | Example:
6 | Given "bcabc"
7 | Return "abc"
8 |
9 | Given "cbacdcbc"
10 | Return "acdb"
11 |
--------------------------------------------------------------------------------
/src/searchInsert/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
5 |
6 | You may assume no duplicates in the array.
7 |
8 | Here are few examples.
9 |
10 | [1,3,5,6], 5 → 2
11 | [1,3,5,6], 2 → 1
12 | [1,3,5,6], 7 → 4
13 | [1,3,5,6], 0 → 0
--------------------------------------------------------------------------------
/src/searchRange/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a sorted array of integers, find the starting and ending position of a given target value.
5 |
6 | Your algorithm's runtime complexity must be in the order of O(log n).
7 |
8 | If the target is not found in the array, return [-1, -1].
9 |
10 | For example,
11 | Given [5, 7, 7, 8, 8, 10] and target value 8,
12 | return [3, 4].
--------------------------------------------------------------------------------
/src/h_index_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
4 |
5 | Hint:
6 |
7 | Expected runtime complexity is in O(log n) and the input is sorted.
8 |
9 |
10 | Solution
11 | ===
12 |
13 | Ternary search for unimodal functions: https://en.wikipedia.org/wiki/Ternary_search
14 |
15 |
--------------------------------------------------------------------------------
/src/nutsInOasis/NutsInOasisTest.java:
--------------------------------------------------------------------------------
1 | package leetcode.problem.nutsInOasis;
2 |
3 | import junit.framework.TestCase;
4 |
5 | /**
6 | * Unit test for simple App.
7 | */
8 | public class NutsInOasisTest extends TestCase {
9 | /**
10 | * Rigourous Test :-)
11 | */
12 | public void testApp() {
13 | assertEquals(46.67, NutsInOasis.getMaxNuts(100, 20, 50, 1), 0.1);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/removeNthNodeList/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a linked list, remove the nth node from the end of list and return its head.
4 |
5 | For example,
6 |
7 | Given linked list: 1->2->3->4->5, and n = 2.
8 |
9 | After removing the second node from the end, the linked list becomes 1->2->3->5.
10 |
11 | Note:
12 | Given n will always be valid.
13 | Try to do this in one pass.
--------------------------------------------------------------------------------
/src/singleNumber/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public int singleNumber(int[] A) {
3 | int ret = 0;
4 | for (int a : A) {
5 | ret ^= a;
6 | }
7 | return ret;
8 | }
9 | public static void main(String[] args) {
10 | Solution s = new Solution();
11 | System.out.println(s.singleNumber(new int[] {1,1,2}));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/stock1/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public int maxProfit(int[] prices) {
3 | if (prices.length == 0) return 0;
4 | int currMin = prices[0];
5 | int ans = 0;
6 | for (int p : prices) {
7 | currMin = Math.min(currMin, p);
8 | ans = Math.max(ans, p - currMin);
9 | }
10 | return ans;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/contains_duplicate_iii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k.
5 |
6 | Solution
7 | ===
8 |
9 | Maintain a treemap of max k nodes, binary search for possible matches. O(n log k)
10 |
--------------------------------------------------------------------------------
/src/lengthOfLastWord/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
4 |
5 | If the last word does not exist, return 0.
6 |
7 | Note: A word is defined as a character sequence consists of non-space characters only.
8 |
9 | For example,
10 | Given s = "Hello World",
11 | return 5.
--------------------------------------------------------------------------------
/src/longestSubstringWithoutRepeatingCharacters/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a string, find the length of the longest substring without repeating characters.
5 |
6 | For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
7 |
8 | Solution
9 | ===
10 | Sliding window
--------------------------------------------------------------------------------
/src/reverseWordsInString/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an input string, reverse the string word by word.
4 |
5 | For example,
6 | Given s = "the sky is blue",
7 | return "blue is sky the".
8 |
9 | Solution
10 | ===
11 |
12 | Soluton 1. Split by regex, then rearrange and concat into sentence
13 |
14 | Soluton 2. Reverse the sentence by character, then reverse each word by character
--------------------------------------------------------------------------------
/src/validNumber/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Validate if a given string is numeric.
4 |
5 | Some examples:
6 | "0" => true
7 | " 0.1 " => true
8 | "abc" => false
9 | "1 a" => false
10 | "2e10" => true
11 |
12 | Note: It is intended for the problem statement to be ambiguous. You
13 | should gather all requirements up front before implementing one
14 | import re
15 |
--------------------------------------------------------------------------------
/src/kth_largest_element_in_an_array/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
4 |
5 | For example,
6 | Given [3,2,1,5,6,4] and k = 2, return 5.
7 |
8 | Note:
9 | You may assume k is always valid, 1 ≤ k ≤ array's length.
10 |
11 | Solution
12 | ===
13 |
14 | Quick select
--------------------------------------------------------------------------------
/src/postOrderTraversal/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, return the postorder traversal of its nodes' values.
4 |
5 | For example:
6 |
7 | Given binary tree {1,#,2,3},
8 | 1
9 | \
10 | 2
11 | /
12 | 3
13 | return [3,2,1].
14 |
15 |
16 | Solution
17 | ===
18 |
19 | use a stack and a prev pointer
20 |
21 | solution at leetcode forum is over-complicated
--------------------------------------------------------------------------------
/src/jumpGame/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of non-negative integers, you are initially positioned
4 | at the first index of the array.
5 |
6 | Each element in the array represents your maximum jump length at that
7 | position.
8 |
9 | Determine if you are able to reach the last index.
10 |
11 | For example:
12 | A = [2,3,1,1,4], return true.
13 |
14 | A = [3,2,1,0,4], return false.
--------------------------------------------------------------------------------
/src/remove_invalid_parentheses/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.
4 |
5 | Note: The input string may contain letters other than the parentheses ( and ).
6 |
7 | Examples:
8 |
9 | "()())()" -> ["()()()", "(())()"]
10 | "(a)())()" -> ["(a)()()", "(a())()"]
11 | ")(" -> [""]
12 |
--------------------------------------------------------------------------------
/common_questions/print_one_to_hundred/Print.java:
--------------------------------------------------------------------------------
1 | class Print {
2 | /**
3 | * print 1..10 without using loop and conditional stmts
4 | * @param
5 | * @return
6 | */
7 | public int print(int a) {
8 | int b = (a == 1) ? 0 : print(a - 1);
9 | System.out.println(a);
10 | return 0;
11 | }
12 | public static void main(String[] args) {
13 | Print p = new Print();
14 | p.print(10);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/excel_sheet_column_title/README.md:
--------------------------------------------------------------------------------
1 | Excel Sheet Column Title
2 | ===
3 | Given a positive integer, return its corresponding column title as appear in an Excel sheet.
4 |
5 | For example:
6 |
7 | 1 -> A
8 | 2 -> B
9 | 3 -> C
10 | ...
11 | 26 -> Z
12 | 27 -> AA
13 | 28 -> AB
14 |
15 | Solution
16 | ===
17 |
18 | Convert to 26-based number in each step of digit extraction
19 |
--------------------------------------------------------------------------------
/src/maximal_square/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.
5 |
6 | For example, given the following matrix:
7 |
8 | 1 0 1 0 0
9 | 1 0 1 1 1
10 | 1 1 1 1 1
11 | 1 0 0 1 0
12 |
13 | Return 4.
14 |
15 |
16 | Solution
17 | ===
18 |
19 | Same as 'maximal rectangle', with limitation to be square
20 |
--------------------------------------------------------------------------------
/src/shortest_palindrome/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.
5 |
6 | For example:
7 |
8 | Given "aacecaaa", return "aaacecaaa".
9 |
10 | Given "abcd", return "dcbabcd".
11 |
12 |
13 | Solution
14 | ===
15 | Expand from center
--------------------------------------------------------------------------------
/src/number_of_digit_one/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
4 |
5 | For example:
6 | Given n = 13,
7 | Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
8 |
9 | Solution
10 | ===
11 |
12 | Break number into digits, for each digit, calculate the number of 1's appearances
13 |
--------------------------------------------------------------------------------
/src/remove_duplicate_from_sorted_array/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
5 |
6 | Do not allocate extra space for another array, you must do this in place with constant memory.
7 |
8 | For example,
9 | Given input array A = [1,1,2],
10 |
11 | Your function should return length = 2, and A is now [1,2].
--------------------------------------------------------------------------------
/src/permutationSequence/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | The set [1,2,3,…,n] contains a total of n! unique permutations.
5 |
6 | By listing and labeling all of the permutations in order,
7 | We get the following sequence (ie, for n = 3):
8 |
9 | "123"
10 | "132"
11 | "213"
12 | "231"
13 | "312"
14 | "321"
15 | Given n and k, return the kth permutation sequence.
16 |
17 | Note: Given n will be between 1 and 9 inclusive.
--------------------------------------------------------------------------------
/common_questions/intimate_numbers/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | find intimate number under 5e6
5 |
6 | factors of 220: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
7 | factors of 284: 1, 2, 4, 71, 142
8 |
9 |
10 | Sum of factors: f(n)
11 |
12 | f(220) => 284
13 | f(f(220)) => f(284) => 220
14 |
15 | Solution
16 | ===
17 |
18 | Like prime sieve, do the factors of each number in O(n logn) (result of harmonic sum)
19 |
20 |
--------------------------------------------------------------------------------
/src/minimum_size_subarray_sum/README.md:
--------------------------------------------------------------------------------
1 | Minimum Size Subarray Sum
2 | ===
3 |
4 | Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.
5 |
6 | For example, given the array [2,3,1,2,4,3] and s = 7,
7 | the subarray [4,3] has the minimal length under the problem constraint.
8 |
9 | Solution
10 | ===
11 | Sliding window
--------------------------------------------------------------------------------
/src/moving_zeroes/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
5 |
6 | For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].
7 |
8 | Note:
9 | You must do this in-place without making a copy of the array.
10 | Minimize the total number of operations.
11 |
--------------------------------------------------------------------------------
/src/largest_number/README.md:
--------------------------------------------------------------------------------
1 | Largest Number
2 | ===
3 |
4 | Given a list of non negative integers, arrange them such that they form the largest number.
5 |
6 | For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
7 |
8 | Note: The result may be very large, so you need to return a string instead of an integer.
9 |
10 | Solution
11 | ===
12 |
13 | Class greedy algorithm question, use sorting and partial results
--------------------------------------------------------------------------------
/src/levelOrderII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
4 |
5 | For example:
6 | Given binary tree {3,9,20,#,#,15,7},
7 | 3
8 | / \
9 | 9 20
10 | / \
11 | 15 7
12 | return its bottom-up level order traversal as:
13 | [
14 | [15,7],
15 | [9,20],
16 | [3]
17 | ]
--------------------------------------------------------------------------------
/src/remove_duplicate_sorted_list_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
4 |
5 | For example,
6 | Given 1->2->3->3->4->4->5, return 1->2->5.
7 | Given 1->1->1->2->3, return 2->3.
8 |
9 |
10 | Solution
11 | ===
12 |
13 | Iterate through list, look at following node of current node to decide whether keep the curr.
--------------------------------------------------------------------------------
/src/strobogrammatic_number_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
4 | For example, the numbers "69", "88", and "818" are all strobogrammatic.
5 |
6 | Find all strobogrammatic numbers that are of length = n.
7 |
8 | For example,
9 |
10 | Given n = 2, return ["11","69","88","96"].
11 |
12 | Solution
13 | ===
14 | Construct iteratively
--------------------------------------------------------------------------------
/src/edit_distance/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
4 |
5 | You have the following 3 operations permitted on a word:
6 |
7 | a) Insert a character
8 | b) Delete a character
9 | c) Replace a character
10 |
11 | Solution
12 | ===
13 |
14 | Example from CLRS "Introduction to Algorithms"
--------------------------------------------------------------------------------
/src/containerWithMostWater/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
4 |
5 | Note: You may not slant the container.
6 |
7 | Solution
8 | ====
9 | Two pointers sliding
--------------------------------------------------------------------------------
/src/delete_node_in_a_linked_list/main.cpp:
--------------------------------------------------------------------------------
1 | struct ListNode {
2 | int val;
3 | ListNode *next;
4 | ListNode(int x) : val(x), next(nullptr) {}
5 | };
6 |
7 | class Solution {
8 | public:
9 | void deleteNode(ListNode* node) {
10 | if (node->next == nullptr) {
11 | return;
12 | }
13 | node->val = node->next->val;
14 | node->next = node->next->next;
15 | }
16 | };
17 |
18 | int main() {
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/src/range_sum_query_immutable/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
4 |
5 | Example:
6 |
7 | Given nums = [-2, 0, 3, -5, 2, -1]
8 |
9 | sumRange(0, 2) -> 1
10 | sumRange(2, 5) -> -1
11 | sumRange(0, 5) -> -3
12 |
13 | Note:
14 | You may assume that the array does not change.
15 | There are many calls to sumRange function.
16 |
--------------------------------------------------------------------------------
/src/stock3/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Say you have an array for which the ith element is the price of a given
4 | stock on day i.
5 |
6 | Design an algorithm to find the maximum profit. You may complete at most
7 | two transactions.
8 |
9 | Solution
10 | ===
11 | Divide list into two halves. For each half find one best transaction, and combine.
12 |
13 | Note the edge case that one good transaction can make more money than two common ones
--------------------------------------------------------------------------------
/src/wordBreak/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string s and a dictionary of words dict, determine if s can be
4 | segmented into a space-separated sequence of one or more dictionary
5 | words.
6 |
7 | For example, given
8 | s = "leetcode",
9 | dict = ["leet", "code"].
10 |
11 | Return true because "leetcode" can be segmented as "leet code".
12 |
13 | Solution
14 | ===
15 |
16 | classic dynamic programming in 2D, fulfilled with hashmap
--------------------------------------------------------------------------------
/src/maxDepthOfBinaryTree/Solution.java:
--------------------------------------------------------------------------------
1 | class TreeNode {
2 | int val;
3 | TreeNode left;
4 | TreeNode right;
5 | TreeNode(int x) {
6 | val = x;
7 | }
8 | }
9 | public class Solution {
10 | public int maxDepth(TreeNode root) {
11 | if (root != null) {
12 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
13 | } else {
14 | return 0;
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/mergeSortedArray/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given two sorted integer arrays A and B, merge B into A as one sorted array.
4 |
5 | Note:
6 | You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
7 |
8 | Solution
9 | ===
10 | Start from the end of A, fill bigger of A or B. Loop until pointers reach heads of arrays
--------------------------------------------------------------------------------
/src/maximum_gap/README.md:
--------------------------------------------------------------------------------
1 | Maximum Gap
2 | ===
3 | Given an unsorted array, find the maximum difference between the successive elements in its sorted form.
4 |
5 | Try to solve it in linear time/space.
6 |
7 | Return 0 if the array contains less than 2 elements.
8 |
9 | You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
10 |
11 | Solution
12 | ===
13 |
14 | radix sort
15 |
16 | scan to find gap
--------------------------------------------------------------------------------
/src/reverseWordsInString/solution.py:
--------------------------------------------------------------------------------
1 | import re
2 | class Solution:
3 | # @param s, a string
4 | # @return a string
5 | def reverseWords(self, s):
6 | return ' '.join(re.split('\s+', s)[::-1]).strip()
7 |
8 | if __name__ == '__main__':
9 | s = Solution()
10 | print '___' + s.reverseWords('the sky is blue') + '___'
11 | print '___' + s.reverseWords(' a b ') + '___'
12 | print '___' + s.reverseWords(' ') + '___'
13 |
--------------------------------------------------------------------------------
/src/find_k_pairs_with_smallest_sums/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
5 |
6 | Define a pair (u,v) which consists of one element from the first array and one element from the second array.
7 |
8 | Find the k pairs (u1,v1),(u2,v2) ...(uk,vk) with the smallest sums.
9 |
10 |
11 | Solution
12 | ===
13 |
14 | Find all possible pairs and sort
15 |
16 | O(k^2 logk)
17 |
--------------------------------------------------------------------------------
/src/mergeSortedArray/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public void merge(int A[], int m, int B[], int n) {
3 | int i = m - 1;
4 | int j = n - 1;
5 | int k = m + n - 1;
6 |
7 | while (k >= 0) {
8 | if (j < 0) break;
9 | if (i >= 0 && A[i] > B[j]) A[k--] = A[i--];
10 | else A[k--] = B[j--];
11 | }
12 | }
13 | public static void main(String[] args) {
14 |
15 | }
16 | }
--------------------------------------------------------------------------------
/src/min_stack/README.md:
--------------------------------------------------------------------------------
1 | Min Stack
2 | ===
3 |
4 | Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
5 |
6 | push(x) -- Push element x onto stack.
7 | pop() -- Removes the element on top of the stack.
8 | top() -- Get the top element.
9 | getMin() -- Retrieve the minimum element in the stack.
10 |
11 | Solution
12 | ===
13 |
14 | Keep an auxilary stack for the min, update as elements are moved around
--------------------------------------------------------------------------------
/src/generateParentheses/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
5 |
6 | For example, given n = 3, a solution set is:
7 |
8 | "((()))", "(()())", "(())()", "()(())", "()()()"
9 |
10 | Solution
11 | ===
12 |
13 | Brute force, backtrack and prune impossible branch
14 |
15 | memoize current left and right parentheses count (as parameters)
16 | for fast condition eval
--------------------------------------------------------------------------------
/src/setMatrixZero/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
5 |
6 |
7 | Follow up:
8 | Did you use extra space?
9 | A straight forward solution using O(mn) space is probably a bad idea.
10 | A simple improvement uses O(m + n) space, but still not the best solution.
11 | Could you devise a constant space solution?
12 |
13 | Solution
14 | ====
15 |
16 | Use first row and first col as markers
--------------------------------------------------------------------------------
/src/3sum_smaller/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
4 |
5 | For example, given nums = [-2, 0, 1, 3], and target = 2.
6 |
7 | Return 2. Because there are two triplets which sums are less than 2:
8 |
9 | [-2, 0, 1]
10 | [-2, 0, 3]
11 |
12 | Follow up:
13 | Could you solve it in O(n^2) runtime?
--------------------------------------------------------------------------------
/src/remove_linkedlist_element/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public ListNode removeElements(ListNode head, int val) {
3 | if (head == null) return null;
4 | ListNode hook = new ListNode(0);
5 | hook.next = head;
6 | ListNode prev = hook, curr = head;
7 | while (curr != null) {
8 | if (curr.val == val) {
9 | prev.next = curr.next;
10 | } else {
11 | prev = prev.next;
12 | }
13 | curr = curr.next;
14 | }
15 | return hook.next;
16 | }
17 | }
--------------------------------------------------------------------------------
/src/wordBreakII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
4 |
5 | Return all such possible sentences.
6 |
7 | For example, given
8 | s = "catsanddog",
9 | dict = ["cat", "cats", "and", "sand", "dog"].
10 |
11 | A solution is ["cats and dog", "cat sand dog"].
12 |
13 | Solution
14 | ===
15 |
16 | Brute force search with memoization for pruning
--------------------------------------------------------------------------------
/src/basic_calculator_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Implement a basic calculator to evaluate a simple expression string.
4 |
5 | The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.
6 |
7 | You may assume that the given expression is always valid.
8 |
9 | Some examples:
10 | "3+2*2" = 7
11 | " 3/2 " = 1
12 | " 3+5 / 2 " = 5
13 |
14 | Note: Do not use the eval built-in library function.
--------------------------------------------------------------------------------
/src/max_product_subarray/README.md:
--------------------------------------------------------------------------------
1 | Maximum Product Subarray
2 | ===
3 | Find the contiguous subarray within an array (containing at least one number) which has the largest product.
4 |
5 | For example, given the array [2,3,-2,4],
6 | the contiguous subarray [2,3] has the largest product = 6.
7 |
8 | Solution
9 | ===
10 | Iterate through the array, maintain a running max (positive product) and a running min (negative product).
11 |
12 | If element is zero, clear previous product
13 |
--------------------------------------------------------------------------------
/src/bitwiseAndRange/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public int rangeBitwiseAnd(int m, int n) {
3 | int count = 0;
4 | while (n > m) {
5 | n >>= 1;
6 | m >>= 1;
7 | count++;
8 | }
9 | return (m & n) << (count);
10 | }
11 | public static void main(String[] args) {
12 | Solution s = new Solution();
13 | System.out.println(s.rangeBitwiseAnd(1, 3));
14 | System.out.println(s.rangeBitwiseAnd(5, 7));
15 | System.out.println(s.rangeBitwiseAnd(3, 3));
16 | }
17 | }
--------------------------------------------------------------------------------
/src/uniquePaths/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
4 |
5 | The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
6 |
7 | How many possible unique paths are there?
8 |
9 |
10 | Above is a 3 x 7 grid. How many possible unique paths are there?
11 |
12 | Note: m and n will be at most 100
--------------------------------------------------------------------------------
/src/longestValidParentheses/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string containing just the characters '(' and ')', find the
4 | length of the longest valid (well-formed) parentheses substring.
5 |
6 | For "(()", the longest valid parentheses substring is "()", which has
7 | length = 2.
8 |
9 | Another example is ")()())", where the longest valid parentheses
10 | substring is "()()", which has length = 4.
11 |
12 | Solution
13 | ===
14 |
15 | Maintain stack of last unmatched index in string
--------------------------------------------------------------------------------
/src/maximalRectangle/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
4 |
5 | Solution
6 | ===
7 |
8 | Very difficult problem, need to utilize the method in question "largest rectangle histogram"
9 |
10 | 1. make a new matrix, where each value is the number of consecutive '1's above it
11 |
12 | 2. apply "largest rectangle histogram" on each row
13 |
14 | 3. compare and return max from all rows
--------------------------------------------------------------------------------
/src/product_of_array_except_self/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].
4 |
5 | Solve it without division and in O(n).
6 |
7 | For example, given [1,2,3,4], return [24,12,8,6].
8 |
9 | Follow up:
10 | Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)
--------------------------------------------------------------------------------
/src/combination_sum_iii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
4 |
5 | Ensure that numbers within the set are sorted in ascending order.
6 |
7 |
8 | Example 1:
9 |
10 | Input: k = 3, n = 7
11 |
12 | Output:
13 |
14 | [[1,2,4]]
15 |
16 | Example 2:
17 |
18 | Input: k = 3, n = 9
19 |
20 | Output:
21 |
22 | [[1,2,6], [1,3,5], [2,3,4]]
--------------------------------------------------------------------------------
/src/count_complete_tree_nodes/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a complete binary tree, count the number of nodes.
5 |
6 | Definition of a complete binary tree from Wikipedia:
7 | In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
8 |
9 | Solution
10 | ===
11 |
12 | Binary search + serialization of binary tree
13 |
14 | O(h^2)
15 |
--------------------------------------------------------------------------------
/src/longestSubstringWith2UniqueChars/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given a string, find the longest substring that contains only two unique characters. For example, given "abcbbbbcccbdddadacb", the longest substring that contains 2 unique character is "bcbbbbcccb".
5 |
6 | Solution
7 | ===
8 | Two pointers slider, maintain a valid solution containing only two chars, by:
9 |
10 | 1. inc counter if char is like the two
11 |
12 | 2. remove until string contains the current char and the previous char
--------------------------------------------------------------------------------
/src/number_1_bits/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | // you need to treat n as an unsigned value
3 | public int hammingWeight(int n) {
4 | int cnt = 0;
5 | while (n != 0) {
6 | n &= n - 1;
7 | cnt++;
8 | }
9 | return cnt;
10 | }
11 | public static void main(String[] args) {
12 | Solution s = new Solution();
13 | System.out.println(s.hammingWeight(11));
14 | System.out.println(s.hammingWeight(-1));
15 | }
16 | }
--------------------------------------------------------------------------------
/src/pathSumII/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
4 |
5 | For example:
6 | Given the below binary tree and sum = 22,
7 |
8 | 5
9 | / \
10 | 4 8
11 | / / \
12 | 11 13 4
13 | / \ / \
14 | 7 2 5 1
15 |
16 | return
17 |
18 | [
19 | [5,4,11,2],
20 | [5,8,4,5]
21 | ]
22 |
23 | Solution
24 | ===
25 | Backtrack
--------------------------------------------------------------------------------
/src/power_of_three/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
5 |
6 | Example:
7 | (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].
8 | (2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].
9 |
10 | Note:
11 | You may assume all input has valid answer.
12 |
13 | Follow Up:
14 | Can you do it in O(n) time and/or in-place with O(1) extra space?
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/squareRoot/main.py:
--------------------------------------------------------------------------------
1 | class Solution:
2 | # @param x, an integer
3 | # @return an integer
4 |
5 | def sqrt(self, x):
6 | if x == 0:
7 | return 0
8 | if x == 1:
9 | return 1
10 | x0 = 1.0
11 | while True:
12 | x1 = (x0 + x / x0) / 2.0
13 | if (abs(x1 - x0) < 1):
14 | return int(x1)
15 | x0 = x1
16 |
17 | if __name__ == '__main__':
18 | s = Solution()
19 | print s.sqrt(9)
20 |
--------------------------------------------------------------------------------
/src/stock2/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public int maxProfit(int[] prices) {
3 | int prev = prices[0];
4 | int ans = 0;
5 | for (int p : prices) {
6 | if (p > prev) ans += p - prev;
7 | prev = p;
8 | }
9 | return ans;
10 | }
11 | public static void main(String[] args) {
12 | Solution s = new Solution();
13 | int res = s.maxProfit(new int[] {1, 2, 15, 4, 9, 2});
14 | System.out.println(res);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/wiggle_sort_ii/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 |
4 | Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
5 |
6 | Example:
7 | (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].
8 | (2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].
9 |
10 | Note:
11 | You may assume all input has valid answer.
12 |
13 | Follow Up:
14 | Can you do it in O(n) time and/or in-place with O(1) extra space?
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/validPalindrome/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a string, determine if it is a palindrome, considering only
4 | alphanumeric characters and ignoring cases.
5 |
6 | For example,
7 | "A man, a plan, a canal: Panama" is a palindrome.
8 | "race a car" is not a palindrome.
9 |
10 | Note:
11 | Have you consider that the string might be empty? This is a good
12 | question to ask during an interview.
13 |
14 | For the purpose of this problem, we define empty string as valid palindrome.
15 |
--------------------------------------------------------------------------------
/src/letterCombinationPhoneNumber/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a digit string, return all possible letter combinations that the number could represent.
4 |
5 | A mapping of digit to letters (just like on the telephone buttons) is given below.
6 |
7 | 
8 |
9 |
10 | Input:Digit string "23"
11 | Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
12 | Note:
13 | Although the above answer is in lexicographical order, your answer could be in any order you want.
--------------------------------------------------------------------------------
/src/levelOrder/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
4 |
5 | For example:
6 | Given binary tree {3,9,20,#,#,15,7},
7 | 3
8 | / \
9 | 9 20
10 | / \
11 | 15 7
12 | return its level order traversal as:
13 | [
14 | [3],
15 | [9,20],
16 | [15,7]
17 | ]
18 |
19 | Solution
20 | ===
21 |
22 | BFS, use a counter to track the size of current level, and break output into levels
--------------------------------------------------------------------------------
/src/pathSum/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
4 |
5 | For example:
6 | Given the below binary tree and sum = 22,
7 |
8 | 5
9 | / \
10 | 4 8
11 | / / \
12 | 11 13 4
13 | / \ \
14 | 7 2 1
15 |
16 | return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
--------------------------------------------------------------------------------
/src/triangle/README.md:
--------------------------------------------------------------------------------
1 | Problem
2 | ===
3 | Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
4 |
5 | For example, given the following triangle
6 | [
7 | [2],
8 | [3,4],
9 | [6,5,7],
10 | [4,1,8,3]
11 | ]
12 | The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
13 |
14 | Note:
15 | Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
--------------------------------------------------------------------------------
/xcode-project/leetcode-debugger/leetcode-debugger/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include