(String s, int[][] shifts)
| 1 | |
| 2 | class Solution { |
| 3 | public String shiftingLetters(String s, int[][] shifts) { |
| 4 | int n = s.length(); |
| 5 | int[] arr = new int[n]; |
| 6 | for (int[] shift : shifts) { |
| 7 | if (shift[2] == 1) { //fw |
| 8 | arr[shift[0]]++; |
| 9 | if (shift[1] + 1 < n) { |
| 10 | arr[shift[1] + 1]--; |
| 11 | } |
| 12 | } else { //bw |
| 13 | arr[shift[0]]--; |
| 14 | if (shift[1] + 1 < n) { |
| 15 | arr[shift[1] + 1]++; |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | StringBuilder result = new StringBuilder(s); |
| 21 | int sum = 0; |
| 22 | for (int i = 0; i < n; i++) { |
| 23 | sum = (sum + arr[i]) % 26; |
| 24 | if (sum < 0) sum += 26; |
| 25 | char shiftedChar = (char) ('a' + |
| 26 | ((s.charAt(i) - 'a' + sum) % 26)); |
| 27 | result.setCharAt(i, shiftedChar); |
| 28 | } |
| 29 | return result.toString(); |
| 30 | } |
| 31 | } |
nothing calls this directly
no outgoing calls
no test coverage detected