diff --git a/jungmyunggi/Maximum Average Subarray i.js b/jungmyunggi/Maximum Average Subarray i.js new file mode 100644 index 0000000..52b0967 --- /dev/null +++ b/jungmyunggi/Maximum Average Subarray i.js @@ -0,0 +1,16 @@ +function findMaxAverage(nums, k) { + let max = -Infinity; + let temp = 0; + + for (let i = 0; i < k; i++) { + temp += nums[i]; + } + max = temp; + + for (let i = k; i < nums.length; i++) { + temp = temp - nums[i-k] + nums[i]; + max = Math.max(max,temp) + } + + return max/k; +} \ No newline at end of file diff --git a/jungmyunggi/Path Sum.js b/jungmyunggi/Path Sum.js new file mode 100644 index 0000000..3af5132 --- /dev/null +++ b/jungmyunggi/Path Sum.js @@ -0,0 +1,21 @@ +/** + * 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 + * @param {number} targetSum + * @return {boolean} + */ +var hasPathSum = function(root, targetSum) { + if(!root) return false; + if(!root.left && !root.right){ + return root.val === targetSum; + } + return hasPathSum(root.left, targetSum-root.val)||hasPathSum(root.right, targetSum-root.val); + +}; \ No newline at end of file