Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 자료형
- JS
- JavaScript
- HTML
- greedy
- 알고리즘
- dynamic programming
- hash table
- sorting
- 변수
- github
- vue.js
- SasS
- JavaSceipt
- Algorithm
- 코딩테스트
- 자료구조
- CSS
- 컴포넌트
- Python
- computed
- array
- java
- scss
- math
- 백준
- string
- leetcode
- 파이썬
- 프로그래머스
Archives
- Today
- Total
Posis
[LeetCode][JavaScript] 58. Length of Last Word 본문
[LeetCode][JavaScript] 58. Length of Last Word
문제 출처: https://leetcode.com/problems/length-of-last-word/
Length of Last Word - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
[직접 푼 코드]
var lengthOfLastWord = function(s) {
return s.trim().split(' ').reverse()[0].length;
};
[문제 풀이]
1. 혹시모를 문자열 앞뒤에 공백을 제거 (trim 메서드)
2. 띄어쓰기 기준으로 문자열을 배열로 만듭니다. (split 메서드)
3. 마지막 단어가 배열의 맨 앞으로 오게 만든 후 문자열의 길이를 구합니다. (reverse 메서드)
알고리즘 스터디: https://github.com/ROUTINE-STUDY/Algorithm
GitHub - ROUTINE-STUDY/Algorithm: 초보 알고리즘 스터디 / 누구나 참여 가능
초보 알고리즘 스터디 / 누구나 참여 가능 :runner:. Contribute to ROUTINE-STUDY/Algorithm development by creating an account on GitHub.
github.com
누구나 참여 가능한 알고리즘 스터디입니다.
알고리즘뿐만 아니라 개발을 하면서 겪은 이슈, 이론을 정리하는 Routine-Study를 운영 중입니다.
728x90
'알고리즘 > leetcode' 카테고리의 다른 글
[LeetCode][JavaScript] 389. Find the Difference (0) | 2021.07.29 |
---|---|
[LeetCode][JavaScript] 66. Plus One (0) | 2021.07.28 |
[LeetCode][JavaScript] 860. Lemonade Change (0) | 2021.07.28 |
[LeetCode][JavaScript] 1859. Sorting the Sentence (0) | 2021.07.28 |
[LeetCode][JavaScript] 1025. Divisor Game (0) | 2021.07.28 |