1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public String lastSubstring(String s) { int n = s.length(); int i = 0, j = 1, k = 0; while (j + k < n) { int d = s.charAt(i + k) - s.charAt(j + k); if (d == 0) { ++k; } else if (d < 0) { i = i + k + 1; k = 0; if (i >= j) j = i + 1; } else { j = j + k + 1; k = 0; } } return s.substring(i); } }
|