Skip to content

Commit

Permalink
restart v3 search, add golang
Browse files Browse the repository at this point in the history
  • Loading branch information
myshkins committed Nov 25, 2024
1 parent 42631cd commit 43a5e02
Show file tree
Hide file tree
Showing 45 changed files with 81 additions and 0 deletions.
29 changes: 29 additions & 0 deletions go/easy/two_sum.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module myshkins_grind_problems

go 1.23.1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions python/medium/med_bt_level_order_trav.py
Original file line number Diff line number Diff line change
@@ -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))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 43a5e02

Please sign in to comment.