2
public boolean isTransformable(String s, String t) {3
if (!equal(s, t)) return false;4
int[] countS = new int[10];5
int[] countT = new int[10];6
int[][] prev = new int[10][10];7
int[][] after = new int[10][10];9
for (int i = 0; i < s.length(); i++) {10
int s1 = s.charAt(i) - '0';11
int t1 = t.charAt(i) - '0';15
// This step is to calculate how many digit less than s1/t1 occur before time i16
// Store the frequency pair into 2-d array17
for (int j = 0; j < s1; j++) {18
if (countS[j] == 0) continue;19
prev[j][s1] += countS[j];22
for (int j = 0; j < t1; j++) {23
if (countT[j] == 0) continue;24
after[j][t1] += countT[j];28
for (int i = 0; i <= 8; i++) {29
for (int j = i + 1; j <= 9; j++) {30
if (prev[i][j] == 0) continue;31
// Check if any ascending pair's frequency has been reduced after modified.32
if (after[i][j] < prev[i][j]) return false;39
// Judge whether the two strings has the same digits40
public boolean equal(String s, String t) {41
char[] sc = s.toCharArray();42
char[] tc = t.toCharArray();46
for (int i = 0; i < s.length(); i++) {47
if (sc[i] != tc[i]) return false;