일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Binary Tree
- Binary Search
- SQL
- 파이썬
- bit manipulation
- Counting
- Data Structure
- 코딩테스트
- array
- Matrix
- 구현
- Tree
- string
- database
- two pointers
- Number Theory
- Method
- dynamic programming
- Stack
- Class
- Math
- simulation
- greedy
- java
- 코테
- 자바
- geometry
- sorting
- implement
- hash table
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 824. Goat Latin 본문
1. Input
1) 문자열 sentence
2. Output
1) “Goat Latin” 규칙에 맞게 sentence를 바꾼 결과
2) “Goat Latin” 규칙
- 모음으로 시작하는 단어는 뒤에 ma를 붙인다.
- 자음으로 시작하는 단어는 맨 앞글자를 맨 뒤로 보낸 후 그 뒤에 ma를 붙인다. 이때 바꾼 단어가 모음으로 시작하면 맨 뒤에 ma를 붙여야 한다.
- 첫 단어에는 끝에 a를 1개 붙이고, 두 번째 단어에는 a를 2개 붙이는 식으로 계속 a를 붙여나간다.
3. Constraint
1) 1 <= sentence.length <= 150
2) sentence는 영어 대소문자와 공백문자로 이루어져있다.
3) sentence에는 단어를 구분지을때만 공백문자 1개를 쓴다.
4. Example
Input: sentence = "I speak Goat Latin" -> Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa“
설명:
- I는 모음으로 시작 + 첫 번째 단어 -> I + ma + a = Imaa
- speak는 자음으로 시작 -> peak + s = peak -> 두 번째 단어 -> peaks + aa = peaksmaaa
- Goat는 자음으로 시작 -> oat + G = oatG -> 모음으로 시작 -> oatG + ma = oatGma -> 세 번째 단어 -> oatGma + aaa = oatGmaaaa
- Latin은 자음으로 시작 -> atin + L = atinL -> 모음으로 시작 -> atinL + ma -> atinLma -> 네 번째 단어 -> atinLma + aaaa = atinLmaaaaa
5. Code
1) 첫 코드(2022/07/26)
String[] s = sentence.split(" ");
String result = "";
for(int i=0 ; i<s.length ; i++){
String c = s[i].charAt(0) + "";
if(!c.matches("[aeiouAEIOU]"))
s[i] = s[i].substring(1,s[i].length()) + c;
s[i] += "ma";
for(int j=0 ; j<i+1 ; j++)
s[i] += "a";
result += s[i] + " ";
}
return result.substring(0,result.length()-1);
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 860. Lemonade Change (0) | 2022.12.08 |
---|---|
[LeetCode/Easy] 832. Flipping an Image (0) | 2022.12.08 |
[LeetCode/Easy] 821. Shortest Distance to a Character (0) | 2022.12.08 |
[LeetCode/Easy] 806. Number of Lines To Write String (0) | 2022.12.07 |
[LeetCode/Easy] 804. Unique Morse Code Words (0) | 2022.12.07 |