public static boolean isPal(String s) {
int i = 0, j = s.length() - 1;
while (i < j) {
if (s.charAt(i) != s.charAt(j)) return false;
i++; j--;
}
return true;
}
// call: isPal("hello")What does isPal("hello") return?
- A
0
- B
exception
- C
true
- Dcheck_circle
false
Explanation
'h' != 'o', so the function returns false.