Created
August 4, 2016 17:58
-
-
Save tburnam/c26f43006c07fcb7897e0137be30d28c to your computer and use it in GitHub Desktop.
AirBnB Practice Questions
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AirBnBPractice | |
{ | |
public static class Palindrome | |
{ | |
public static string FindLongestPalindrome(string originalString) | |
{ | |
string currentPalindrome = ""; | |
string longestPalindrome = ""; | |
int back = 0; | |
int front = 0; | |
int originalStringLength = originalString.Length - 1; | |
for (int index = 1; index < originalStringLength; index++) | |
{ | |
front = index - 1; | |
back = index + 1; | |
while (front >= 0 && back < originalString.Length) | |
{ | |
if (originalString[front] != originalString[back]) | |
{ | |
break; | |
} | |
currentPalindrome = originalString.Substring(front, back - front + 1); | |
if (currentPalindrome.Length > longestPalindrome.Length) | |
longestPalindrome = currentPalindrome; | |
front--; | |
back++; | |
} | |
} | |
return longestPalindrome; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment