๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/131701
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(elements) {
const circular = elements.concat(elements);
const set = new Set();
for (let i = 0; i < elements.length; i++) {
let sum = 0;
for (let j = 0; j < elements.length; j++) {
sum += circular[i + j];
set.add(sum);
}
}
return set.size;
}
๋ดํ์ด๐ฝ
1. ์คํจ โ => ( ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ๋ค .. )
function solution(elements) {
var answer = 0;
let stack = []
for(let i=1; i<=elements.length; i++){
for(let j=0; j<elements.length; j++){
let sum =0;
for(let z=j; z<j+i; z++){
if(z>=elements.length){
sum+=elements[z-elements.length+1]
}else{
sum+=elements[z]
}
}
stack.push(sum)
}
}
answer = new Set(stack)
answer = [...answer]
return answer.length;
}
2. ์ฑ๊ณต โญ =>
function solution(elements) {
var answer = 0;
let set = new Set()
for(let i=0; i<elements.length; i++){
let sum =0;
for(let j=1; j<=elements.length; j++){
sum+=elements[(i+j-1)%elements.length]
set.add(sum)
}
}
return set.size;
}
๋๋์ ๐ฝ
set ๊ฐ์ฒด์ ๋ํ ๊ณต๋ถ๋ฅผ ํ ์ ์์๋ค.
set ๊ฐ์ฒด๋ฅผ ํ๋ง๋๋ก ์ ์ํ๋ฉด ์ ์ผ๊ฐ๋ง์ ์ ์ฅํ๋ ๊ฐ์ฒด์ด๋ค
์์ธํ ์ฌํญ์ MDN์ ํตํด ํ์ธํด๋ณด์!
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Set