Leetcode Note: Go - Find First Palindromic String in the Array

Find First Palindromic String in the Array - LeetCode
https://leetcode.com/problems/find-first-palindromic-string-in-the-array/

  • Go 言語で取り組んだメモ

回答

Funny with Go - Find First Palindromic String in the Array - LeetCode
https://leetcode.com/problems/find-first-palindromic-string-in-the-array/solutions/2463467/funny-with-go/

func firstPalindrome(words []string) string {
    isPalindromic := func(s string) bool {
        if len(s) < 2 {
            return true
        }
        
        l, r := 0, len(s)-1
        
        for l < r {
            if s[l] != s[r] {
                return false
            }
            
            l, r = l+1, r-1
        }
        
        return true
    }  
    
    for _, word := range words {
        if isPalindromic(word) {
            return word
        }
    }
    
    return ""
}