vins
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class Palindrome {
/**
* @param args
*/
public static void main(String[] args) {
String str = "A man, a plan, a canal: Panama.";
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < str.length(); i++) {
c = str.charAt(i);
if (c == ':' | c == ',' | c == ' ' | c == '.')
continue;
sb.append(c);
}
str = sb.toString().toLowerCase();
int length = str.length();
for (int i = 0; i < length; i++) {
if (str.charAt(i) == str.charAt(length - i - 1))
continue;
else {
System.out.println("Not a Palindrome");
length = -1;
break;
}
}
if (length != -1)
System.out.println("Hope this is a palindrome");
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Somebody tell me what is the complexity of this piece of code. And let me know if any suggestions for improvements in perfomance.
- vins July 02, 2013