LeetCode
LeetCode 28 Implement strStr()
콩순이냉장고
2021. 7. 6. 18:13
문제 URL : 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
문제접근법 : haystack의 문자열안에 needle이 처음으로 존재하는 첫번째 인덱스를 구하는겁니다.
따로설명 안드리겠습니다. 스스로 찾는구현을 해도되고 라이브러리 함수를 사용해도되기때문에 아주 쉬운문제입니다.
소스코드 :
c++
1
2
3
4
5
6
|
class Solution {
public:
int strStr(string haystack, string needle) {
return haystack.find(needle);
}
};
|
cs |
자바
1
2
3
4
5
|
class Solution {
public int strStr(String haystack, String needle) {
return haystack.indexOf(needle);
}
}
|
cs |

궁금한점 혹은 모르는점 논리적인오류등 어떤질문이라도 댓글은 언제나 환영입니다.