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
- database
- Number Theory
- 파이썬
- Method
- Binary Tree
- Data Structure
- 구현
- greedy
- Class
- hash table
- string
- array
- Stack
- Tree
- SQL
- java
- two pointers
- bit manipulation
- 자바
- 코테
- implement
- sorting
- Math
- Matrix
- Binary Search
- Counting
- dynamic programming
- geometry
- simulation
- 코딩테스트
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Medium] 151. Reverse Words in a String 본문
1. Input
1) String s
2. Output
1) s의 단어들을 역순으로 나열한 문자열 반환
3. Constraint
1) 1 <= s.length <= 104
2) s는 영어 대소문자, 숫자, 공백 문자로 이루어져 있다.
3) s에는 최소 1개의 단어가 있다.
4) 단어는 공백 문자로 구분되어 있는데, 단어 사이에 여러 개의 공백 문자가 들어있을 수 있다. 반환할 때는 단어 사이에 반드시 1개의 공백 문자가 있어야 한다.
4. Example
Input: s = "a good example" -> Output: "example good a"
Input: s = " hello world " -> Output: "world hello"
5. Code
1) 첫 코드(2023/01/20)
String[] words = s.trim().split("[ ]+");
for(int i=words.length-2 ; i>=0 ; i--){
words[words.length-1] += " " + words[i];
}
return words[words.length-1];
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 203. Remove Linked List Elements (0) | 2023.01.23 |
---|---|
[LeetCode/Easy] 202. Happy Number (0) | 2023.01.23 |
[LeetCode/Medium] 137. Single Number II (0) | 2023.01.19 |
[프로그래머스/Lv.2] 스킬트리 (0) | 2023.01.17 |
[LeetCode/Easy] 104. Maximum Depth of Binary Tree (0) | 2023.01.17 |