본문 바로가기
Algorithm/LeetCode

[Java] 28. Find the Index of the First Occurrence in a String

by tabasco 2023. 6. 8.

문제 설명 :

String에서 indexOf 함수를 알고있는지 물어보는 문제이다.
또는 indexOf 를 구현하는 문제이다.

 

class Solution {
    public int strStr(String haystack, String needle) {
        
        return haystack.indexOf(needle);
    }
}

 

해설 :

Java에서는 String 클래스가 indexOf를 지원하기 때문에 이를 활용해 문제를 해결했다.

'Algorithm > LeetCode' 카테고리의 다른 글

[Java] 58. Length of Last Word  (3) 2023.06.08
[Java] 35. Search Insert Position  (0) 2023.06.08
[Java] 27. Remove Element  (1) 2023.06.07
[Java] 26. Remove Duplicates from Sorted Array  (1) 2023.06.07
[Java] 21. Merge Two Sorted Lists  (0) 2023.06.07