diff --git a/invert-binary-tree/robinyoon-dev.js b/invert-binary-tree/robinyoon-dev.js new file mode 100644 index 0000000000..e386e65b8f --- /dev/null +++ b/invert-binary-tree/robinyoon-dev.js @@ -0,0 +1,36 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {TreeNode} + */ +var invertTree = function (root) { + + let node = root; + + let result = changeLeftAndRight(node); + + return result; + + function changeLeftAndRight(root) { + // 종료 조건 + if (root === null) return root; + + tempLeft = root.left; + tempRight = root.right; + + root.left = tempRight; + root.right = tempLeft; + + changeLeftAndRight(root.left); + changeLeftAndRight(root.right); + + return root; + } +}; diff --git a/search-in-rotated-sorted-array/robinyoon-dev.js b/search-in-rotated-sorted-array/robinyoon-dev.js new file mode 100644 index 0000000000..6c4cbc54c0 --- /dev/null +++ b/search-in-rotated-sorted-array/robinyoon-dev.js @@ -0,0 +1,16 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number} + */ +var search = function(nums, target) { + let targetIndex = -1; + + for(let i = 0; i < nums.length; i++){ + if(nums[i] === target){ + targetIndex = i; + break; + } + } + return targetIndex; +};