본문 바로가기
leetcode 풀이/String

leetcode 28. Find the index of the First Occurence in a String

by 튼튼한개발자 2023. 1. 21.

https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/

미디움이라고 하지만, 전혀 미디움 난이도가 아닌 문제

class Solution(object):
    def strStr(self, haystack, needle):
        """
        :type haystack: str
        :type needle: str
        :rtype: int
        """
        if needle in haystack :
            return haystack.index(needle)
        
        return -1

댓글