Created
May 18, 2022 08:51
-
-
Save parajuliamit/1f655db66432bf9c9212d0f74fdd5368 to your computer and use it in GitHub Desktop.
Longest Palindrome Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main(){ | |
| String val = "31208345654312309845312345654321"; | |
| String longest = val.substring(0,3); | |
| for(int i = 0 ; i< val.length; i++){ | |
| for(int j = 3; j <= val.length-i; j++){ | |
| String testString = val.substring(i,j+i); | |
| if(reverseString(testString) == testString){ | |
| if(testString.length >= longest.length){ | |
| longest = testString; | |
| }} | |
| } | |
| } | |
| print(longest); | |
| } | |
| String reverseString(String text){ | |
| String reversedOutput =''; | |
| for(int i =text.length-1; i>=0; i--){ | |
| reversedOutput = reversedOutput + text[i]; | |
| } | |
| return reversedOutput; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment