2108. Find First Palindromic String in the Array - Easy 前往題目 想法 雙指針,每個單字都檢查一遍 思路秒殺題 雙指針,每個單字都檢查一遍 Codeclass Solution { public String firstPalindrome(String[] words) { // 疊代每個單字 for (String word : words) { // 如果不是palindrome,false if (isPalin(word)) return word; } return ""; } private boolean isPalin(String s) { int left = 0, right = s.length() - 1; while (left < right) { if (s.charAt(left) != s.charAt(right)) return false; ++left; --right; } return true; } } Leetcode > Easy #Leetcode #心得 #String #Array #Two Pointers 2108. Find First Palindromic String in the Array - Easy https://f88083.github.io/2024/07/04/2108-Find-First-Palindromic-String-in-the-Array/ 作者 Simon Lai 發布於 2024年7月4日 許可協議 779. K-th Symbol in Grammar - Medium 上一篇 1662. Check If Two String Arrays are Equivalent - Easy 下一篇 Please enable JavaScript to view the comments