Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions jungmyunggi/Maximum Average Subarray i.js
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions jungmyunggi/Path Sum.js
Original file line number Diff line number Diff line change
@@ -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);

};
37 changes: 37 additions & 0 deletions jungmyunggi/Restore IP Addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @param {string} s
* @return {string[]}
*/
var restoreIpAddresses = function(s) {
const n = s.length;
if(n >=13){
return [];
}
if(n <= 3){
return [];
}
const result = [];
function isVaild(splitString){
if(Number(splitString) === 0 && splitString.length === 1) return true;
if(splitString[0] === '0') return false;
if(Number(splitString) <= 255) return true;
return false;
}

for(let i1 = 1; i1 < n - 2; i1++){
const part1 = s.slice(0,i1);
if(isVaild(part1) === false) continue;
for(let i2 = i1 + 1; i2 < n - 1; i2++){
const part2 = s.slice(i1,i2);
if(isVaild(part2) === false) continue;
for(let i3 = i2 + 1; i3 < n; i3++){
const part3 = s.slice(i2,i3);
if(isVaild(part3) === false) continue;
const part4 = s.slice(i3);
if(isVaild(part4) === false) continue;
result.push(part1+"."+part2+"."+part3+"."+part4);
}
}
}
return result;
};
Loading