Created
          February 15, 2018 02:16 
        
      - 
      
- 
        Save basmoura/3f5344e30fa7eb80ebfa846a93024334 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | def isPalindrome(low, high) | |
| while (low < high) do | |
| if (low != high) | |
| return false; | |
| end | |
| low += 1 | |
| high -= 1 | |
| end | |
| return true; | |
| end | |
| def IsAlmostPalindrome(str) | |
| low = 0 | |
| high = str.size - 1 | |
| while (low < high) do | |
| if (str[low] == str[high]) | |
| low += 1 | |
| high -= 1 | |
| else | |
| if (isPalindrome(str[0].to_i + low + 1, str[0].to_i + high)) | |
| return low | |
| end | |
| if (isPalindrome(str[0].to_i + low, str[0].to_i + high - 1)) | |
| return high; | |
| end | |
| return -1 | |
| end | |
| end | |
| return -2 | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment