์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์นด์นด์ค ์ฝํ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- next13 emotion
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- js
- ์ฌ์ฉ์ฑ ๊ฐ์
- ์ต์ ๋์ฒด์ด๋
- ๋ฐฑ์ค 1339๋ฒ js
- app router emotion
- suspense ๋์์๋ฆฌ
- ์ค์ฝํ
- emotion RSC
- suspense react-query
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- suspense ๋น๋๊ธฐ
- emtion app router
- js ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- suspense ๋ณ๋ชฉํ์
- ๋ฐฑ์ค 2108 nodejs
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- js ์ค์ฝํ
- ๊ตฌ๋ฆํค
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํด๋ฆฌ ์ฑ๋ฆฐ์ง 10์ฃผ์ฐจ ๊ต์ ์ ๋ณ ๋ง๋ค๊ธฐ (js) ๋ณธ๋ฌธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํด๋ฆฌ ์ฑ๋ฆฐ์ง 10์ฃผ์ฐจ ๊ต์ ์ ๋ณ ๋ง๋ค๊ธฐ (js)
Lennon 2021. 10. 30. 00:48https://programmers.co.kr/learn/courses/30/lessons/87377?language=javascript
function isInteger(num) {
return num % 1 === 0;
}
function intersectionPoint(arr1,arr2){
const denominator = (arr1[0]*arr2[1])-(arr1[1]*arr2[0]);
const x = ((arr1[1]*arr2[2])-(arr1[2]*arr2[1])) / denominator;
const y = ((arr1[2]*arr2[0])-(arr1[0]*arr2[2])) / denominator;
return denominator === 0 ? 0 : [y,x]
}
function solution(line) {
let meetPointArr = [];
for(let i = 0; i < line.length; i++){
for(let j = i+1; j < line.length; j++){
const value = intersectionPoint(line[i], line[j]);
if(isInteger(value[0]) && isInteger(value[1])){
meetPointArr.push(value);
}
}
}
meetPointArr.sort((a,b) => a[0]-b[0]);
const [columnMin, columnMax] = [meetPointArr[0][0],meetPointArr[meetPointArr.length-1][0]];
meetPointArr.sort((a,b) => a[1]-b[1]);
const [rowMin,rowMax] = [meetPointArr[0][1],meetPointArr[meetPointArr.length-1][1]];
meetPointArr = meetPointArr.map(v=>v.join(""));
const answer = [];
for(let i = columnMin; i <= columnMax; i++){
let str = '';
for(let j = rowMin; j <= rowMax; j++){
if(meetPointArr.includes(i.toString()+j.toString())) str+="*";
else str+=".";
}
answer.push(str);
}
return answer.reverse();
}
์ ์ฝ๋๋ก ํ๋ฉด ๊ณ์ ํ ์คํธ์ผ์ด์ค 2๋ฒ๋ง ์๋๋ค. ์ด์ ๋ ์์ง๋ ๋ชป ์ฐพ์์ง๋ง
3์ค ํฌ๋ฌธ์ ์ฐ๊ธฐ๊ฐ ์ซ์ด์ includes ๋น๊ต๋ฅผ ์ํด ๋ชจ๋ ์ ์ ์ ์ ๊ต์ ๋ค์ ๋ชจ์๋์
30 Line์์ meetPointArr ๋ฐฐ์ด์ ๊ต์ ์ ๋ฌธ์์ด๋ก ๋ณํ ํ ํ
ex) meetPointArr => [[-4, -4], [-1, -2]] => ["-4-4", "-1-2"]
(i์ j๋ ๊ต์ ๋ค ์ค ๊ฐ์ฅ min๊ฐ~๊ฐ์ฅ max๊ฐ์ผ๋ก ์ด๋ฃจ์ด์ ธ์์ ex)-4~4)
(37 Line) ๋ฐ๋ณต๋ฌธ์ i, j๋ ๋ฌธ์๋ก ๋ณํํ ํ ๋ํด meetPointArr์ includes๋์ด์๋ค๋ฉด str+="*"์ผ๋ก,
์์ผ๋ฉด str+="." ์ ๋ฆฌํ๋๋ฐ
(์ค๋ณต๋๋ ๊ต์ ์ ์์ด๋ ์ฒ๋ฆฌ๊ฐ ๋๋ค๊ณ ์๊ฐํจ)
(์ค์ ๋ก ์ค๋ณต๋๋ ๊ต์ ์ ์ฒซ๋ฒ์งธ meetPointArr pushํ๋ for๋ฌธ์์ ์ฒ๋ฆฌํด๋ ์๋๋ค.)
2๋ฒ๋ง ๊ณ์ ํต๊ณผ๊ฐ ์๋๋ค.
ํน์๋ ํ๊ณ meetPointArr๋ ๋ฌธ์๋ณํ์ด ์๋ ๊ทธ๋๋ก [[-4, -4], [-1, -2]] ์ ์งํ๊ณ
์๋ ์ฝ๋์ฒ๋ผ includes๊ฐ ์๋ forEach๋ฅผ ํตํด ๋น๊ตํ๋ ํต๊ณผ๊ฐ ๋๋ค.
function isInteger(num) {
return num % 1 === 0;
}
function intersectionPoint(arr1,arr2){
const denominator = (arr1[0]*arr2[1])-(arr1[1]*arr2[0]);
const x = ((arr1[1]*arr2[2])-(arr1[2]*arr2[1])) / denominator;
const y = ((arr1[2]*arr2[0])-(arr1[0]*arr2[2])) / denominator;
return denominator === 0 ? 0 : [y,x]
}
function solution(line) {
let meetPointArr = [];
for(let i = 0; i < line.length; i++){
for(let j = i+1; j < line.length; j++){
const value = intersectionPoint(line[i], line[j]);
if(isInteger(value[0]) && isInteger(value[1])){
meetPointArr.push(value);
}
}
}
meetPointArr.sort((a,b) => a[0]-b[0]);
const [columnMin, columnMax] = [meetPointArr[0][0],meetPointArr[meetPointArr.length-1][0]];
meetPointArr.sort((a,b) => a[1]-b[1]);
const [rowMin,rowMax] = [meetPointArr[0][1],meetPointArr[meetPointArr.length-1][1]];
const answer = [];
for(let i = columnMin; i <= columnMax; i++){
let str = '';
for(let j = rowMin; j <= rowMax; j++){
str += "."
meetPointArr.forEach(v => {
if(v[0] === i && v[1] === j){
str = str.slice(0, -1);
str += "*";
}
})
}
answer.push(str);
}
return answer.reverse();
}
2๋ฒ ์ผ์ด์ค๊ฐ ๋๋ฌด๋๋ฌด ๊ถ๊ธํ๋ค. ์ค๋ณต๋๋ ๊ต์ ์ด ์๋ ์๋ includes๋ ์๊ด์ด ์์ํ ๋ฐ..
๋ง์ฝ ์ค์ ์ฝ๋ฉํ ์คํธ ์ํ์ ์ด๊ฒ ๋์๋ค๋ฉด ์๊ฐ์ ๋ง์ด ์ก์๋จน์์ ๊ฒ ๊ฐ๋ค..
์ด์ ์์ธ๋ ๋ฌด์กฐ๊ฑด ์์ ์ ์๋ค๊ณ ์๊ฐํ๊ณ ํ์คํ๊ฒ ํ์ด์ผ๊ฒ ๋ค!
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ (js) (0) | 2021.10.30 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฉ๋ด ๋ฆฌ๋ด์ผ (js) (0) | 2021.10.30 |
[ํ๋ก๊ทธ๋๋จธ์ค] 3์ฐจ ์์ถ (js) (0) | 2021.10.29 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์คํ์ฑํ ๋ฐฉ (js) (0) | 2021.10.28 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฐฉ๊ธ ๊ทธ๊ณก (js) (0) | 2021.10.28 |