Created
December 2, 2017 19:58
-
-
Save mizushou/adb64df02aa8602017d94e0fde175d2c to your computer and use it in GitHub Desktop.
山本山
This file contains 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
public class ThePalindrome { | |
public int find(String s) { | |
// 答えの文字数を決定する. 条件は指定しない(無限ループ. returnでの強制終了) | |
for(int i=s.length(); ;i++){ | |
boolean flag = true; | |
for(int j=0; j<s.length(); j++){ | |
if ((i - j - 1) < s.length() && s.charAt(j) != s.charAt(i - j - 1)){ | |
flag = false; | |
break; | |
} | |
}; | |
if(flag) return i; | |
} | |
} | |
public static void main(String[] args) { | |
ThePalindrome p = new ThePalindrome(); | |
System.out.println(p.find("abdfhdyrbdbsdfghjkllkjhgfds")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment