[LeetCode] 28. Implement strStr()

원숭2·2022년 1월 17일
0

LeetCode

목록 보기
9/51

문제

풀이

  1. in 연산자로 haystack에 needle이 있는 지 확인
  2. 없으면 -1, 있으면 index method의 값을 return

코드

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        if needle in haystack :
            return haystack.index(needle)
        else :
            return-1

0개의 댓글