Skip to content

Commit 88b2e34

Browse files
authored
Create 3838. Weighted Word Mapping.java
1 parent 5d09260 commit 88b2e34

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// 97 ~ 122
2+
3+
class Solution {
4+
public String mapWordWeights(String[] words, int[] weights) {
5+
StringBuilder sb = new StringBuilder();
6+
for (String word : words) {
7+
int sum = 0;
8+
for (char c : word.toCharArray()) {
9+
int num = (int) c - 97;
10+
sum += weights[num];
11+
}
12+
int mod = sum % 26;
13+
sb.append((char)('z' - mod));
14+
}
15+
return sb.toString();
16+
}
17+
}

0 commit comments

Comments
 (0)