[leetcode/JS] 28. Implement strStr() /Javascript
문제 링크
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
투포인터를 사용 해 풀었습니다
기억하면 좋을 것 / 소감
indexOf()를 쓰는게 속도 빠르니까 그렇게 하자
indexOf() 짚고 넘어가기
indexOf() 메서드는 배열에서 지정된 요소를 찾을 수 있는 첫 번째 인덱스를 반환하고 존재하지 않으면 -1을 반환합니다.
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
String.prototype.indexOf() - JavaScript | MDN
indexOf() 메서드는 호출한 String 객체에서 주어진 값과 일치하는 첫 번째 인덱스를 반환합니다. 일치하는 값이 없으면 -1을 반환합니다.
developer.mozilla.org
입력 받은 배열이 empty 인 것을 확인하는 방법
if (strValue === "") {
//...
}
empty 확인을 할 때는 === 을 쓰도록 하자
How can I check for an empty/undefined/null string in JavaScript?
I saw this question, but I didn't see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
stackoverflow.com
Javascript Truth Value
That is, all values are truthy except false, 0, -0, 0n, "", null, undefined, and NaN.
false, 0, -0, "", null , undefined 은 false로 간주된다.
https://developer.mozilla.org/en-US/docs/Glossary/Truthy
Truthy - MDN Web Docs Glossary: Definitions of Web-related terms | MDN
In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy. That is, all values are truthy except false, 0, -0, 0n, "", null, undefined, and NaN.
developer.mozilla.org
해결 코드
Submission Detail
다른 풀이
slice 해서 푸는게 더 빠르게 풀리네요