Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- js
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ๋ฐฑ์ค 1339๋ฒ js
- emtion app router
- js ์ค์ฝํ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- suspense ๋น๋๊ธฐ
- suspense ๋์์๋ฆฌ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- suspense react-query
- ๋ฐฑ์ค 2108 nodejs
- suspense ๋ณ๋ชฉํ์
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- emotion RSC
- ์นด์นด์ค ์ฝํ
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ๋ฌธ์์ด ์์ถ
- ์ต์ ๋์ฒด์ด๋
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- app router emotion
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค
- next13 emotion
Archives
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํ๋ฆฐํฐ (js) ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/42587
function solution(priorities, location) {
let result = [];
let prior = [];
let max = 0;
let answer;
for(let i = 0; i < priorities.length; i++){
prior.push({idx : i, value : priorities[i]});
}
for(let j = 1; j < prior.length; j++){
for(let i = 0; i < prior.length; i++){
max = Math.max(prior[i].value, max);
}
if(max === prior[0].value){
result.push(prior[0]);
prior.shift();
j = 0;
}
else if(prior[0].value < prior[j].value){
prior.push(prior[0]);
prior.shift();
j = 0;
}
max = 0;
}
const ans = [...result, ...prior].filter((a,b) => {
if(a.value === priorities[location] && a.idx === location){
answer = b;
}
});
return answer+1;
}
์ธ๋ฑ์ค๋ ๊ธฐ๋กํด์ผํ๊ณ , ์์๋ ์ ๋๋ก ๊ตฌํด์ผ๋ผ์ ๊ฐ์ฒด๋ก ํ์๋ค.
๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ์ ํ ์์์ ํ๋ ์ฉ shiftํ๋ฉฐ ๋ค์ ๊ฐ์ ๋น๊ตํด result ๋ฐฐ์ด์ ์ฑ์๋๊ฐ๋ค.
๊ณ์ j=0์ผ๋ก ์ด๋ ํ ์ต๋๊ฐ์ ๊ตฌํ ํ ์ฒ์๋ถํฐ ๋ฐ๋ณตํด ํจ์จ์ ์ธ ์ฝ๋๋ ์๋ ๊ฒ ๊ฐ๋ค.
(์ต๋๊ฐ 100๊ฐ ์ดํ๋ผ์ ๊ทธ๋ฅ ํ์)
๋ค์์ ๋ ์ข์ ์ฝ๋ ๋ฐ ์๊ณ ๋ฆฌ์ฆ์ ์๊ฐํด๋ด์ผ๊ฒ ๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํํ (js) (0) | 2021.11.18 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ์์ ์ฐพ๊ธฐ (js) (0) | 2021.11.12 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฐฉ๋ฌธ ๊ธธ์ด (js) (0) | 2021.11.08 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์คํฌํธ๋ฆฌ (js) (0) | 2021.11.07 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ ๊ท ์์ด๋ ์ถ์ฒ (js) (0) | 2021.11.05 |
Comments