๋ฐ์ํ
Problem Description
๋จธ์ฑ์ด๋ ์น๊ตฌ๋ค๊ณผ 369๊ฒ์์ ํ๊ณ ์์ต๋๋ค. 369๊ฒ์์ 1๋ถํฐ ์ซ์๋ฅผ ํ๋์ฉ ๋๋ฉฐ 3, 6, 9๊ฐ ๋ค์ด๊ฐ๋ ์ซ์๋ ์ซ์ ๋์ 3, 6, 9์ ๊ฐ์๋งํผ ๋ฐ์๋ฅผ ์น๋ ๊ฒ์์ ๋๋ค. ๋จธ์ฑ์ด๊ฐ ๋งํด์ผํ๋ ์ซ์ order๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ๋จธ์ฑ์ด๊ฐ ์ณ์ผํ ๋ฐ์ ํ์๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์.
Restrictions.
- 1 ≤ order ≤ 1,000,000
Input/Output Example
- ์ ์ถ๋ ฅ ์ #1 3์ 3์ด 1๊ฐ ์์ผ๋ฏ๋ก 1์ ์ถ๋ ฅํฉ๋๋ค.
- ์ ์ถ๋ ฅ ์ #2 29423์ 3์ด 1๊ฐ, 9๊ฐ 1๊ฐ ์์ผ๋ฏ๋ก 2๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
My solution
function solution(order) {
const array = order.toString().split("");
return array.filter((x) => parseFloat(x) >= 0 && x == '3' || x == '6' || x == '9').length;
}
Another solutions
function solution(order) {
var answer = [...order.toString().matchAll(/[3|6|9]/g)].length;
return answer;
}
function solution(order) {
return (''+order).split(/[369]/).length-1;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120891
https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Regular_expressions
๋ฐ์ํ
'Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๋ฌธ์์ด ์ ๋ ฌํ๊ธฐ (2) (1) | 2023.10.21 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ซ์ ์ฐพ๊ธฐ (0) | 2023.10.21 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๋ฐฐ์ด ํ์ ์ํค๊ธฐ (0) | 2023.10.20 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ฃผ์ฌ์์ ๊ฐ์ (0) | 2023.10.19 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๊ฐ๋ฏธ ๊ตฐ๋จ โ (0) | 2023.10.19 |