public int numDistinct_TLE(String S, String T) {

    // ask what to return when S == T
    if (S.equals(T)) {
      return 1;
    }

    int count = 0;
    // this method, the two for loop are M*N time complexity
    // but the equals function inside the loop need another M time
    // so it's O(M^3) time complexity
    for (int i = 0 ; i < S.length() ; i++) {
      for (int j = i ; j < S.length() ; j++) {
        StringBuffer sb = new StringBuffer(S);
        sb.deleteCharAt(i);
        if (i != j) {
          sb.deleteCharAt(j - 1);
        }
        if (T.equals(sb.toString())) {
          count++;
        }
      }
    }

    return count;
  }