diff --git a/go/easy/two_sum.go b/go/easy/two_sum.go new file mode 100644 index 0000000..b06c970 --- /dev/null +++ b/go/easy/two_sum.go @@ -0,0 +1,29 @@ +package main + +import "fmt" + +func twoSum(nums []int, target int) []int { + result := make([]int, 0) + seen := make(map[int]int) + for i, v := range nums { + complement := target - v + comp_indx, ok := seen[complement] + if ok { + result = append(result, i, comp_indx) + return result + } + _, ok = seen[v] + if ! ok { + seen[v] = i + } + } + result = append(result, 9,9) + return result +} + +func main() { + nums := []int{3,2,4} + target := 6 + answer := twoSum(nums, target) + fmt.Println(answer) +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..91ef199 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,3 @@ +module myshkins_grind_problems + +go 1.23.1 diff --git a/easy_OT_catchup_replit.py b/python/easy/easy_OT_catchup_replit.py similarity index 100% rename from easy_OT_catchup_replit.py rename to python/easy/easy_OT_catchup_replit.py diff --git a/easy_add_binary.py b/python/easy/easy_add_binary.py similarity index 100% rename from easy_add_binary.py rename to python/easy/easy_add_binary.py diff --git a/easy_anagram.py b/python/easy/easy_anagram.py similarity index 100% rename from easy_anagram.py rename to python/easy/easy_anagram.py diff --git a/easy_backspace_compare.py b/python/easy/easy_backspace_compare.py similarity index 100% rename from easy_backspace_compare.py rename to python/easy/easy_backspace_compare.py diff --git a/easy_bad_version.py b/python/easy/easy_bad_version.py similarity index 100% rename from easy_bad_version.py rename to python/easy/easy_bad_version.py diff --git a/easy_balanced_tree.py b/python/easy/easy_balanced_tree.py similarity index 100% rename from easy_balanced_tree.py rename to python/easy/easy_balanced_tree.py diff --git a/easy_best_time_buy.py b/python/easy/easy_best_time_buy.py similarity index 100% rename from easy_best_time_buy.py rename to python/easy/easy_best_time_buy.py diff --git a/easy_binary_search.py b/python/easy/easy_binary_search.py similarity index 100% rename from easy_binary_search.py rename to python/easy/easy_binary_search.py diff --git a/easy_climbing_stairs.py b/python/easy/easy_climbing_stairs.py similarity index 100% rename from easy_climbing_stairs.py rename to python/easy/easy_climbing_stairs.py diff --git a/easy_contains_dup.py b/python/easy/easy_contains_dup.py similarity index 100% rename from easy_contains_dup.py rename to python/easy/easy_contains_dup.py diff --git a/easy_counting_bits.py b/python/easy/easy_counting_bits.py similarity index 100% rename from easy_counting_bits.py rename to python/easy/easy_counting_bits.py diff --git a/easy_flood_fill.py b/python/easy/easy_flood_fill.py similarity index 100% rename from easy_flood_fill.py rename to python/easy/easy_flood_fill.py diff --git a/easy_hamming_weight.py b/python/easy/easy_hamming_weight.py similarity index 100% rename from easy_hamming_weight.py rename to python/easy/easy_hamming_weight.py diff --git a/easy_invert_binary_tree.py b/python/easy/easy_invert_binary_tree.py similarity index 100% rename from easy_invert_binary_tree.py rename to python/easy/easy_invert_binary_tree.py diff --git a/easy_linked_list_cycle.py b/python/easy/easy_linked_list_cycle.py similarity index 100% rename from easy_linked_list_cycle.py rename to python/easy/easy_linked_list_cycle.py diff --git a/easy_longest_common_prefix.py b/python/easy/easy_longest_common_prefix.py similarity index 100% rename from easy_longest_common_prefix.py rename to python/easy/easy_longest_common_prefix.py diff --git a/easy_longest_palindrome.py b/python/easy/easy_longest_palindrome.py similarity index 100% rename from easy_longest_palindrome.py rename to python/easy/easy_longest_palindrome.py diff --git a/easy_majority_element.py b/python/easy/easy_majority_element.py similarity index 100% rename from easy_majority_element.py rename to python/easy/easy_majority_element.py diff --git a/easy_max_depth.py b/python/easy/easy_max_depth.py similarity index 100% rename from easy_max_depth.py rename to python/easy/easy_max_depth.py diff --git a/easy_merge_lists.py b/python/easy/easy_merge_lists.py similarity index 100% rename from easy_merge_lists.py rename to python/easy/easy_merge_lists.py diff --git a/easy_middle_linked_list.py b/python/easy/easy_middle_linked_list.py similarity index 100% rename from easy_middle_linked_list.py rename to python/easy/easy_middle_linked_list.py diff --git a/easy_queue_with_fifo.py b/python/easy/easy_queue_with_fifo.py similarity index 100% rename from easy_queue_with_fifo.py rename to python/easy/easy_queue_with_fifo.py diff --git a/easy_ransom_note.py b/python/easy/easy_ransom_note.py similarity index 100% rename from easy_ransom_note.py rename to python/easy/easy_ransom_note.py diff --git a/easy_remove_digit.py b/python/easy/easy_remove_digit.py similarity index 100% rename from easy_remove_digit.py rename to python/easy/easy_remove_digit.py diff --git a/easy_reverse_linked.py b/python/easy/easy_reverse_linked.py similarity index 100% rename from easy_reverse_linked.py rename to python/easy/easy_reverse_linked.py diff --git a/easy_roman_int.py b/python/easy/easy_roman_int.py similarity index 100% rename from easy_roman_int.py rename to python/easy/easy_roman_int.py diff --git a/easy_same_tree.py b/python/easy/easy_same_tree.py similarity index 100% rename from easy_same_tree.py rename to python/easy/easy_same_tree.py diff --git a/easy_tree_diameter.py b/python/easy/easy_tree_diameter.py similarity index 100% rename from easy_tree_diameter.py rename to python/easy/easy_tree_diameter.py diff --git a/easy_tree_diameter2.py b/python/easy/easy_tree_diameter2.py similarity index 100% rename from easy_tree_diameter2.py rename to python/easy/easy_tree_diameter2.py diff --git a/easy_two_sum.py b/python/easy/easy_two_sum.py similarity index 100% rename from easy_two_sum.py rename to python/easy/easy_two_sum.py diff --git a/easy_valid_palindrome.py b/python/easy/easy_valid_palindrome.py similarity index 100% rename from easy_valid_palindrome.py rename to python/easy/easy_valid_palindrome.py diff --git a/easy_valid_parenthesis.py b/python/easy/easy_valid_parenthesis.py similarity index 100% rename from easy_valid_parenthesis.py rename to python/easy/easy_valid_parenthesis.py diff --git a/med_01_matrix.py b/python/medium/med_01_matrix.py similarity index 100% rename from med_01_matrix.py rename to python/medium/med_01_matrix.py diff --git a/med_3sum.py b/python/medium/med_3sum.py similarity index 100% rename from med_3sum.py rename to python/medium/med_3sum.py diff --git a/med_3sum_b.py b/python/medium/med_3sum_b.py similarity index 100% rename from med_3sum_b.py rename to python/medium/med_3sum_b.py diff --git a/med_LCA.py b/python/medium/med_LCA.py similarity index 100% rename from med_LCA.py rename to python/medium/med_LCA.py diff --git a/python/medium/med_bt_level_order_trav.py b/python/medium/med_bt_level_order_trav.py new file mode 100644 index 0000000..8b6ff7b --- /dev/null +++ b/python/medium/med_bt_level_order_trav.py @@ -0,0 +1,49 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +class Solution: + def levelOrder(self, root: TreeNode) -> list[list[int]]: + level = [root] + res = [] + while True: + temp = [] + for node in level: + if node.right: + temp.append(node.right) + if node.left: + temp.append(node.left) + level_values = [node.val for node in level] + res.append(level_values) + level = temp + if len(temp) == 0: + break + return res + +root = TreeNode( + val=3, + left=TreeNode( + val=9, + left=None, + right=None + ), + right=TreeNode( + val=20, + left=TreeNode( + val=15, + left=None, + right=None + ), + right=TreeNode( + val=7, + left=None, + right=None + ) +) +) + +s = Solution() +print(s.levelOrder(root)) \ No newline at end of file diff --git a/med_insert_interval.py b/python/medium/med_insert_interval.py similarity index 100% rename from med_insert_interval.py rename to python/medium/med_insert_interval.py diff --git a/med_k_closest_origin.py b/python/medium/med_k_closest_origin.py similarity index 100% rename from med_k_closest_origin.py rename to python/medium/med_k_closest_origin.py diff --git a/med_longest_substring_wo_repeat.py b/python/medium/med_longest_substring_wo_repeat.py similarity index 100% rename from med_longest_substring_wo_repeat.py rename to python/medium/med_longest_substring_wo_repeat.py diff --git a/med_max_subarray.py b/python/medium/med_max_subarray.py similarity index 100% rename from med_max_subarray.py rename to python/medium/med_max_subarray.py diff --git a/med_two_sum_arr.py b/python/medium/med_two_sum_arr.py similarity index 100% rename from med_two_sum_arr.py rename to python/medium/med_two_sum_arr.py diff --git a/med_two_sum_arr2.py b/python/medium/med_two_sum_arr2.py similarity index 100% rename from med_two_sum_arr2.py rename to python/medium/med_two_sum_arr2.py