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 |
Tags
- 파이썬
- implement
- SQL
- Number Theory
- string
- Method
- bit manipulation
- simulation
- geometry
- hash table
- database
- Tree
- array
- Binary Tree
- Stack
- Math
- sorting
- Data Structure
- dynamic programming
- 코딩테스트
- Counting
- 코테
- 구현
- 자바
- Binary Search
- two pointers
- greedy
- Matrix
- java
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1309. Decrypt String from Alphabet to Integer Mapping 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1309. Decrypt String from Alphabet to Integer Mapping
무지맘 2023. 4. 11. 00:361. Input
1) String s
2. Output
1) s에 있는 숫자들을 다음 규칙에 맞게 변환한 결과를 반환
- 1 ~ 9는 a ~ i로 변환한다.
- 10# ~ 26#은 j ~ z로 변환한다.
3. Constraint
1) 1 <= s.length <= 1000
2) s는 숫자와 ‘#’로 이루어져 있다.
3) s는 항상 유효한 결과를 갖는 문자열이다.
4. Example
Input: s = "10#11#12" -> Output: "jkab"
설명: "j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2"
5. Code
1) 첫 코드(2023/04/11)
String answer = "";
int i = s.length()-1;
while(i>=0){
if(s.charAt(i)=='#'){
answer = (char)(Integer.valueOf(s.substring(i-2,i))-1+'a') + answer;
i -= 2;
} else
answer = (char)(s.charAt(i)-1-'0'+'a') + answer;
i--;
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Medium] 2390. Removing Stars From a String (0) | 2023.04.11 |
---|---|
[LeetCode/Easy] 1304. Find N Unique Integers Sum up to Zero (0) | 2023.04.11 |
[LeetCode/Easy] 1317. Convert Integer to the Sum of Two No-Zero Integers (0) | 2023.04.10 |
[백준 온라인 저지] 14425. 문자열 집합 (0) | 2023.04.08 |
[백준 온라인 저지] 10815. 숫자 카드 (0) | 2023.04.08 |