C C++ python速解迴文Leetcode 2108 Find First Palindromic String in the Array
這就是迴文「花蓮噴水池水噴蓮花」"racecar",Leetcode蒐集了一堆跟迴文有關的問題,應該是說科技公司面試常出迴文問題。想看C語言解答請進
[codes on Leetcode]https://leetcode.com/problems/find-first-palindromic-string-in-the-array/solutions/4717919/python-1-liner-vs-several-c-c-sols-19ms-beats-99-86/
[Leetcode playList]https://www.youtube.com/watch?v=WjrWkPysfRM&list=PLYRlUBnWnd5IdDHk2BjqXwesydU17z_xk
[Dynamic Programming Playlist]https://www.youtube.com/watch?v=30yq3fmE6E8&list=PLYRlUBnWnd5K_XYUesV9oc6M9ONXII61T
#pragma GCC optimize("O3", "unroll-loops") char* firstPalindrome(char** words, int wordsSize) { for (register int i=0; i<r;wordsSize; i++){ bool isPal=1; char* s=words[i]; for(register int l=0, r=strlen(s)-1; isPal && l<r; l++, r--){ isPal=(s[l]==s[r]); } if (isPal) return s; } return ""; }
沒有留言:
張貼留言