diff --git "a/\353\260\225\354\244\200\354\233\220/Marathon (solution).txt" "b/\353\260\225\354\244\200\354\233\220/etc/Marathon (solution).txt" similarity index 100% rename from "\353\260\225\354\244\200\354\233\220/Marathon (solution).txt" rename to "\353\260\225\354\244\200\354\233\220/etc/Marathon (solution).txt" diff --git "a/\353\260\225\354\244\200\354\233\220/Marathon.py" "b/\353\260\225\354\244\200\354\233\220/etc/Marathon.py" similarity index 100% rename from "\353\260\225\354\244\200\354\233\220/Marathon.py" rename to "\353\260\225\354\244\200\354\233\220/etc/Marathon.py" diff --git "a/\353\260\225\354\244\200\354\233\220/etc/TargetNumber solution.txt" "b/\353\260\225\354\244\200\354\233\220/etc/TargetNumber solution.txt" new file mode 100644 index 0000000..b0dc319 --- /dev/null +++ "b/\353\260\225\354\244\200\354\233\220/etc/TargetNumber solution.txt" @@ -0,0 +1,36 @@ +Ÿ°Ù ³Ñ¹ö + +[input] +numbers +target + +[output] +¹æ¹ýÀÇ °³¼ö + +-------------------------------------------------------- + +´õÇÏ°í »©±â µÎ°¡Áö °æ¿ì + +{a, b, c, d} + +struct node { +node left +node right +int value +} + + + 0 +2 a -a +4 b -b b -b +8 c -c c -c c -c c -c +16 d -d d -d d -d d -d d -d + + +1 + 2 + 4 + 8 + 16 +==> maketree + +==> find target +rootºÎÅÍ leaf±îÁö °¡´Â ¸ðµç °æ¿ìÀÇ ¼ö¸¦ Ž»öÇÔ +¸ðµç °æ¿ìÀÇ ¼öÀÇ sumÀ» ±¸ÇÔ +target°ú °°À¸¸é count \ No newline at end of file diff --git "a/\353\260\225\354\244\200\354\233\220/etc/TargetNumber.py" "b/\353\260\225\354\244\200\354\233\220/etc/TargetNumber.py" new file mode 100644 index 0000000..e8abe42 --- /dev/null +++ "b/\353\260\225\354\244\200\354\233\220/etc/TargetNumber.py" @@ -0,0 +1,35 @@ +class Node: + def __init__(self, num): + self.value = num + self.left = None + self.right = None + +def buildTree(node, num): + if node.left == None and node.right == None: + node.left = Node(num) + node.right = Node(-num) + return + + buildTree(node.left, num) + buildTree(node.right, num) + +def count(node, sum, target): + if node.left == None and node.right == None: + temp = sum + node.value + if temp == target: + return 1 + else: + return 0 + + return count(node.left, node.value + sum, target) + count(node.right, node.value + sum, target) + + +numbers = [1, 2, 3, 4, 5] +target = 15 + +root = Node(0) + +for num in numbers: + buildTree(root, num) + +print(count(root, 0, target)) \ No newline at end of file