Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static int countReversals(String str, int k) {
- int count = 0;
- int n = str.length();
- for (int i = 0; i <= n - k; i++) {
- String substring = str.substring(i, i + k);
- String reversedSubstring = new StringBuilder(substring).reverse().toString();
- if (reversedSubstring.compareTo(substring) < 0) {
- count++;
- }
- }
- return count;
- }
- public static void main(String[] args) {
- String input = "aaaaa";
- int k = 4;
- int result = countReversals(input, k);
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement