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
- 필기
- git
- 책리뷰
- 코드숨
- Jackson
- hackerrank
- post
- 2020년 일정
- 뇌정리
- 2020년 제4회 정보처리기사 필기 문제 분석
- java
- 2020년 정보처리기사 4회
- 서평
- 성적프로그램
- 함수형 코딩
- Real MySQL
- algorithms
- Python
- If
- sqldeveloper
- 미니프로젝트
- 정보처리기사
- 스터디
- LeetCode
- 주간회고
- Til
- jsp
- 회고
- 항해99
- 알고리즘
Archives
- Today
- Total
조컴퓨터
58. Length of Last Word 본문

Input 된 글자의 끝으로 간다.
for문을 돌려서 띄어쓰기가 없는 곳으로 간다.
띄어쓰기가 있을 때까지 count++
class Solution {
public int lengthOfLastWord(String s) {
int count = 0;
for( int i=s.length()-1; i>=0; i-- ) {
if( s.charAt(i)!=' ' ) {
count++;
} else if( count!=0 ) {
break;
}
}
return count;
}
}
'LeetCode > Algorithms' 카테고리의 다른 글
| *67. Add Binary (0) | 2021.11.02 |
|---|---|
| 66. Plus One (0) | 2021.11.02 |
| 53. Maximum Subarray (0) | 2021.10.27 |
| 35. Search Insert Position (0) | 2021.10.20 |
| 28. Implement strStr() (0) | 2021.10.20 |