~๋ชฉ์ฐจ~
๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/81301?language=java
๋ฌธ์ ํด๊ฒฐ ํฌ์ธํธ
- Python์ ๋์ ๋๋ฆฌ์ฒ๋ผ ์์ฑํ ์ ์์๊น ์๊ฐํ๋ค.
- ๊ฐ ์ซ์์ ๋ํ ๋ฌธ์์ด ๋ฐฐ์ด์ ์์ฑํ๊ณ , ๋๋ค๋ฅธ ๋ฐฐ์ด์ ๋์ผํ ์ธ๋ฑ์ค๋ฒํธ๋ฅผ ๊ฐ๋ ๋ณ๊ฒฝํ ๋ฌธ์์ด์ ๊ฐ๊ฐ ์ ๋ ฅํ๋ค.(word, wordI)
- ํด๋น ๋ฐฐ์ด์ ๋๋ฉฐ ํด๋น ๋ฌธ์์ด์ด ์๋ค๋ฉด replaceAll ๋ฉ์๋๋ฅผ ์ด์ฉํ์ฌ ๋ณ๊ฒฝํ๋ค.
์์ฑ ์ฝ๋
class Solution {
public int solution(String s) {
int answer = 0;
String[] word = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
String[] wordI = {"0","1","2","3","4","5","6","7","8","9"};
for(int i=0; i<word.length; i++){
s = s.replaceAll(word[i], wordI[i]);
}
return Integer.parseInt(s);
}
}
๋์์ด ๋์ จ๋ค๋ฉด ์ข์์ ๋๋ฌ์ฃผ์ธ์๐
'๐๋ฌธ์ ํ์ด > ๐งฉProgrammers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ํธ๋ํ์ดํธ ๋ํ (0) | 2023.05.05 |
---|---|
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ผ ๋ฌธ์ (0) | 2023.05.05 |
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ (0) | 2023.05.05 |
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ์ต์์ง์ฌ๊ฐํ (0) | 2023.05.05 |
[Python] ํ๋ก๊ทธ๋๋จธ์ค ํคํจ๋ ๋๋ฅด๊ธฐ | 2020 ์นด์นด์ค ์ธํด์ญ (2) | 2023.05.03 |