0. 문제
https://leetcode.com/problems/implement-strstr/
Implement strStr() - 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
두개의 문자열이 주어진다. 두 번째 문자열에 해당하는 첫 번째 문자열에 인덱스를 반환한다.
#1
Input: haystack = "hello", needle = "ll"
Output: 2
#2
Input: haystack = "aaaaa", needle = "bba"
Output: -1
1.언어
자바스크립트(JavaScript)
2. 문제 풀이
var strStr = function(haystack, needle) {
return haystack.indexOf(needle)
};
Runtime: 66 ms, faster than 88.94% of JavaScript online submissions for Implement strStr().
Memory Usage: 41.9 MB, less than 72.09% of JavaScript online submissions for Implement strStr().
indexf 함수 사용
'LeetCode > 코딩 테스트 스터디 2주차' 카테고리의 다른 글
[LeetCode] 7. Reverse Integer 풀이 (JS) (0) | 2022.07.17 |
---|---|
[LeetCode] 35. Search Insert Position 풀이 (JS) (0) | 2022.07.17 |
[LeetCode] 6. Zigzag Conversion 풀이 (JS) (0) | 2022.07.17 |
[LeetCode] 27. Remove Element 풀이 (JS) (0) | 2022.07.17 |
[LeetCode] 26. Remove Duplicates from Sorted Array 풀이 (JS) (0) | 2022.07.17 |