-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboj_1254.java
More file actions
39 lines (32 loc) · 904 Bytes
/
boj_1254.java
File metadata and controls
39 lines (32 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package brute_force;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class boj_1254 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
int len=s.length();
int i=0;
while(true){
if(isPalindrome(s)){
System.out.println(s.length());
break;
}
s=s.substring(0,len)+s.charAt(i)+s.substring(len);
i++;
}
}
private static boolean isPalindrome(String s){
int left=0;
int right=s.length()-1;
while(left<right){
if(s.charAt(left)!=s.charAt(right)){
return false;
}
left++;
right--;
}
return true;
}
}