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 ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์นด์นด์ค ์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- suspense ๋์์๋ฆฌ
- js ๋ฌธ์์ด ์์ถ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- emotion RSC
- suspense react-query
- ์ฌ์ฉ์ฑ ๊ฐ์
- ๋ฐฑ์ค 1339๋ฒ nodejs
- js
- next13 emotion
- suspense ๋ณ๋ชฉํ์
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ์ต์ ๋์ฒด์ด๋
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- emtion app router
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ js
- js ์ค์ฝํ
- ๊ตฌ๋ฆํค
- ๋ฐฑ์ค 2108 nodejs
- suspense ๋น๋๊ธฐ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- app router emotion
Archives
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค] (1์ฐจ) ๋ด์ค ํด๋ฌ์คํฐ๋ง (js) ๋ณธ๋ฌธ
๐ฅ Algorithm/Programmers
[ํ๋ก๊ทธ๋๋จธ์ค] (1์ฐจ) ๋ด์ค ํด๋ฌ์คํฐ๋ง (js)
Lennon 2021. 10. 27. 18:23728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/17677?language=javascript
function solution(str1, str2) {
str1 = divideString(str1).map((v) => v.join("").toLowerCase());
str2 = divideString(str2).map((v) => v.join("").toLowerCase());
let denominatorSet = [...new Set([...str1, ...str2])];
let moleculeSet = str1.filter(v => str2.includes(v));
moleculeSet = [...new Set(moleculeSet)];
let molecule = 0;
let denominator = 0;
for(let i = 0; i < denominatorSet.length; i++){
const strOverlap1 = str1.reduce((prev, cur) => prev + (cur===denominatorSet[i]), 0);
const strOverlap2 = str2.reduce((prev, cur) => prev + (cur===denominatorSet[i]), 0);
denominator+= Math.max(strOverlap1, strOverlap2);
}
for(let i = 0; i < moleculeSet.length; i++){
const strOverlap1 = str1.reduce((prev, cur) => prev + (cur===moleculeSet[i]), 0);
const strOverlap2 = str2.reduce((prev, cur) => prev + (cur===moleculeSet[i]), 0);
molecule+= Math.min(strOverlap1, strOverlap2);
}
return denominator===0 ? 65536 : Math.floor((molecule/denominator)*65536)
}
function divideString(str) {
const result = [];
for(let i = 0; i < str.length; i++){
const sliceStr = str.slice(i,i+2);
let matchStr = sliceStr.match(/[A-Z]/gi);
if(matchStr === null) continue;
else if(matchStr.length === 2){
result.push(matchStr);
}
}
return result;
}
matchํจ์๋ฅผ ๋ฐฐ์ด ํ ์ฒ์ ์จ ๋ดค๋ค.
๋ฐฐ์ด ์์์ ๊ฐ์๋ฅผ ์ฐพ๋ ๊ฑฐ์ ์ ์ฉํ๊ฒ ์ฐ์ผ ์ ์์ ๊ฒ ๊ฐ์ divideString ํจ์์ ์์ฑํด๋ดค๋ค.
์ ๊ท์์ ํตํด ์ฝ๋๊ฐ ๊ฐ๊ฒฐํด์ง ์ ์์๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์คํ์ฑํ ๋ฐฉ (js) (0) | 2021.10.28 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฐฉ๊ธ ๊ทธ๊ณก (js) (0) | 2021.10.28 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํด๋ฆฌ์ฑ๋ฆฐ์ง 12์ฃผ์ฐจ (js) (0) | 2021.10.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฒ ์คํธ์จ๋ฒ (js) (0) | 2021.10.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ฐ์ฅ ํฐ ์ (js) (0) | 2021.10.25 |
Comments