Find the number of unique words by letter combination
- 5. Class FindUniqueWord {
def alphabets = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’,
‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’,
‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’,
‘x’, ‘y’, ‘z’]
function getWeight(String word) {
int weight = 0;
for (i=0; i<word.length(); i++) {
for (j=0; j<alphabets.length(); j++) {
if (word.chartAt(i) == alphabets[j])
weight += j;
}
}
return weight;
}
function getUniqueWords(String[] words) {
List<int> unique = new ArrayList<int>();
for (i=0; i<words.length; i++) {
int weight = this.getWeight(words[i]);
if (!unique.contains(weight)) {
unique.add(weight);
}
}
return unique.count();
}
}
Class FindUniqueWord {
function getUniqueWords(String[] words) {
List<String> unique = new
ArrayList<String>();
for (i=0; i<words.length; i++) {
char[] c1 = words[i].toCharArray();
Arrays.sort(c1);
if (!unique.contains(new String(c1)) {
unique.add(new String(c1));
}
}
return unique.count();
}
}
Find the number of unique word by letter combination
(`aab`, `aba`, `bba`, `baa`) = 2 unique words
simpler, more efficient,
need less time
- 9. The Point of being lazy is, you stop doing anything but think,
to find an easy way to solve.
More simple means less bug.
- 11. Gather all mighty equipment and weapon
while you can
I hope can win with just one click
- 16. The invisible one is impossible to noticed
Unless we understand our coding in design perspective