알고리즘 기초 다지기 프로젝트 (feat. 코드없는 프로그래밍) [2021년 05월 27일]
Leetcode - Implement strStr()
문제: LeetCode - 28. Implement strStr()
- KMP 알고리즘은 무엇인고..?
- 분명 강의의 의도는 이게 아닌데
indexOf로만 풀이..
코드
const strStr = (haystack, needle) => haystack.indexOf(needle);
Leetcode - Rotate String
문제: LeetCode - 796. Rotate String
- 이 문제에서도 강의는 다른 의도였던 것 같은데..
코드
const moveLeft = (str) => str.slice(1, str.length) + str[0];
const rotateString = (s, goal) => {
if (s.length <= 1) return s === goal;
let startStr = moveLeft(s);
while (startStr !== s) {
if (startStr === goal) return true;
startStr = moveLeft(startStr);
}
return false;
};
rotateString('abcde', 'cdeab');
참고 자료
강의
알고리즘 기초 다지기 프로젝트 (feat. 코드없는 프로그래밍) [2021년 05월 27일]
Leetcode - Implement strStr()
문제: LeetCode - 28. Implement strStr()
indexOf로만 풀이..코드
indexOf활용하여 풀이Leetcode - Rotate String
문제: LeetCode - 796. Rotate String
코드
참고 자료
강의