We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int ii = 0; ii < n; ii++){
String s = sc.next();
int count = 0;
// use two pointers;
int i = 0, j = s.length() - 1;
while(i < j){
count += Math.abs(s.charAt(i) - s.charAt(j));
i++; j--;
}
System.out.println(count);
}
}
The Love-Letter Mystery
You are viewing a single comment's thread. Return to all comments →
public class Solution {
}