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
- Til
- Jackson
- 서평
- jsp
- 정보처리기사
- 2020년 정보처리기사 4회
- rownum
- Python
- hackerrank
- algorithms
- 회고
- 필기
- sqldeveloper
- 함수형 코딩
- 성적프로그램
- 2020년 일정
- Real MySQL
- 미니프로젝트
- java
- LeetCode
- If
- 스터디
- 2020년 제4회 정보처리기사 필기 문제 분석
- 주간회고
- post
- 코드숨
- 책리뷰
- 알고리즘
- 뇌정리
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 |