public List<String> (String word){ List<String> result = new ArrayList<>(); helper(result, word, 0, 0, new StringBuilder()); return result; }
privatevoidhelper(List<String> result, String word, int idx, int count, StringBuilder sb){ if (idx == word.length()) { if (count > 0) sb.append(count);
result.add(sb.toString()); return; }
int length = sb.length();
helper(result, word, idx + 1, count + 1, sb);
sb.setLength(length);
if (count > 0) helper(result, word, idx + 1, 0, sb.append(count).append(word.charAt(idx))); else helper(result, word, idx + 1, 0, sb.append(word.charAt(idx))); }
近期评论