My short solution(Swift)


  • 0
    Y
    func strStr(_ haystack: String, _ needle: String) -> Int {
            if needle.characters.count == 0 {
                return 0
            }else if let range = haystack.range(of: needle) {
                return haystack.distance(from: haystack.startIndex, to: range.lowerBound)
            }
            return -1
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.