-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution3.java
42 lines (35 loc) · 989 Bytes
/
Solution3.java
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
40
41
42
import java.util.Scanner;
public class Solution3 {
public static void main(String[] args) {
int j = 1, num1 = 4;
while (++j <= 10) {
num1++;
}
System.out.println(num1);
}
public static String getShortestPallindrom(String str) {
String ans = "";
for (int i = 0; i < str.length(); i++) {
String temp = str.substring(0, i + 1);
if (isPallindrom(temp) && isPallindrom(str + temp)) {
ans = temp;
break;
}
}
return ans;
}
public static boolean isPallindrom(String str) {
// int i = 0;
// int j = str.length() - 1;
// while (i < j) {
// if (str.charAt(i) != str.charAt(j)) {
// return false;
// }
// i++;
// j--;
// }
// return true;
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString().equals(str);
}
}