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
- greedy
- Stack
- Tree
- array
- hash table
- two pointers
- 코테
- 코딩테스트
- dynamic programming
- Method
- bit manipulation
- sorting
- 자바
- Matrix
- java
- simulation
- Binary Search
- SQL
- geometry
- 파이썬
- string
- implement
- Binary Tree
- database
- Counting
- Data Structure
- Number Theory
- Class
- 구현
- Math
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 58. Length of Last Word 본문
1. Input
1) String 변수 s
2) s는 word와 space로 구성
3) word는 space로 구분됨
2. Output
1) s의 마지막 word의 길이
3. Constraint
1) 1 <= s.length <= 104
2) s는 영문자와 빈 공간으로만 구성되어 있음
3) s에는 최소 1개의 word가 있음
4. Example
Input: s = " fly me to the moon "
Output: 4
설명:
- 빈 공간을 제외하면 words = "fly", "me", "to", "the", "moon"
- 마지막 단어인 "moon"의 길이는 4
5. Code
1) 첫 코드(2022/05/31)
String[] str = s.split(" ");
return str[str.length-1].length();
- s를 " "로 나눔
- 배열의 가장 마지막 단어(str[str.length-1])의 길이를 반환해줌
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 88. Merge Sorted Array (0) | 2022.08.24 |
---|---|
[LeetCode/Easy] 69. Sqrt(x) (0) | 2022.08.23 |
[LeetCode/Medium] 537. Complex Number Multiplication (0) | 2022.08.23 |
[LeetCode/Medium] 1314. Matrix Block Sum (0) | 2022.08.23 |
[LeetCode/Medium] 2221. Find Triangular Sum of an Array (0) | 2022.08.19 |