Skip to content

Instantly share code, notes, and snippets.

View sphilee's full-sized avatar

Gwanhyeong Lee sphilee

View GitHub Profile
function solution(S) {
// write your code in JavaScript (Node.js 8.9.4)
const stack = [];
for(let s of S){
switch(s){
case '(':
stack.push(s);
break;
case ')':
if(stack.slice(-1)[0] === '(') stack.pop();
function solution(S) {
// write your code in JavaScript (Node.js 8.9.4)
const stack = [];
for(let s of S){
switch(s){
case '{':
case '[':
case '(':
stack.push(s);
break;
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const left = A[0];
const right = A.slice(1).reduce((a,b)=>a+b);
const min = Math.abs(left-right);
return A.slice(1,-1).reduce(({left,right,min},cur)=>
new Object({
left : left+cur,
right : right-cur,
min : Math.min(min, Math.abs(left-right))
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
return [...new Array(A.length+2).keys()].concat(A).reduce((pre,cur)=>pre^cur);
}
function solution(A, K) {
// write your code in JavaScript (Node.js 8.9.4)
while(A.length && K--){
A.unshift(A.pop());
}
return A;
}
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
A.sort((a,b)=>a-b);
return A.slice(0,-2).reduce((cnt,v,i)=>{
let [Q,R] = [i+1,i+2];
while(R < A.length){
if(v + A[Q] > A[R]){
cnt += R - Q;
R++;
} else if(Q < R-1){
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const result = new Set();
for(let i of A){
result.add(Math.abs(i));
}
return result.size
}
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
return A.reduce((cnt,v,i)=>hasSameFactors(v,B[i]) ? cnt+1 : cnt, 0);
}
function gcd(p, q){
return q ? gcd(q, p % q) : p;
}
function hasSameFactors(p, q){
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return lcm(N,M)/M;
}
function gcd(p, q){
return q ? gcd(q, p % q) : p;
}
function lcm(p,q){
function solution(K, A) {
// write your code in JavaScript (Node.js 8.9.4)
const maxList = [];
let acc = 0;
let cnt = 0;
for(let i =0; i<A.length; i++){
acc += A[i];
maxList[i] = acc;
if(acc >= K){
cnt++;