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
- Each child in a list should have a unique "key" prop.
- electron-packager
- adb pair
- github pdf
- camera permission
- Git
- custom printing
- augmentedDevice
- github 100mb
- silent printing
- ffi-napi
- nextjs
- Failed to compiled
- npm package
- github lfs
- dvh
- animation
- html
- Can't resolve
- Recoil
- 이미지 데이터 타입
- adb connect
- ELECTRON
- vercel git lfs
- device in use
- react-native
- react-native-dotenv
- camera access
- 티스토리 성능
- rolldown
Archives
- Today
- Total
Bleeding edge
[LeetCode] 2185. Counting Words With a Given Prefix - 자바스크립트 0614 본문
카테고리 없음
[LeetCode] 2185. Counting Words With a Given Prefix - 자바스크립트 0614
codevil 2022. 6. 14. 11:26https://leetcode.com/problems/counting-words-with-a-given-prefix/
Counting Words With a Given Prefix - 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
문제를 너무 어렵게 읽어서 어렵게 시도하다 틀리고 다시풀었습니다 ..-_ㅠ
문제는 아주 간단합니다
words가 prefix를 포함하고 있다면 한개씩 숫자를 더하여 return 하는 문제입니다.
1. count = 0 을 선언하고 words를 기준으로 for 루프합니다.
let count = 0
for (let i = 0; i < words.length; i++) {
}
2. word가 pref를 includes하고 있고, word의 맨앞에 위치하고 있으면 count를 더합니다
for (let i = 0; i < words.length; i++) {
if (words[i].includes(pref) && words[i].indexOf(pref) === 0) {
count++
}
}
최종풀이
var prefixCount = function (words, pref) {
let count = 0
for (let i = 0; i < words.length; i++) {
if (words[i].includes(pref) && words[i].indexOf(pref) === 0) {
count++
}
}
return count
};
pref와 words가 includes가 아닌 몇 글자가 겹치는지(?) 푸는 문제인줄알구 시간이 생각보다 걸리긴 했지만.. 이내 다시 제대로 읽고 제대로 풀었다.. 문제를 잘읽어야겠다..