Skip to content

Commit 7d242a0

Browse files
add 3838
1 parent dfb6324 commit 7d242a0

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| 3913 | [Sort Vowels by Frequency](https://leetcode.com/problems/sort-vowels-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3913.java) | | Easy |
2222
| 3912 | [Valid Elements in an Array](https://leetcode.com/problems/valid-elements-in-an-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3912.java) | | Easy |
2323
| 3908 | [Valid Digit Number](https://leetcode.com/problems/valid-digit-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3908.java) | | Easy |
24+
| 3838 | [Weighted Word Mapping](https://leetcode.com/problems/weighted-word-mapping/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3838.java) | | Easy |
2425
| 3813 | [Vowel-Consonant Score](https://leetcode.com/problems/vowel-consonant-score/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3813.java) | | Easy |
2526
| 3701 | [Compute Alternating Sum](https://leetcode.com/problems/compute-alternating-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3701.java) | | Easy |
2627
| 3662 | [Filter Characters by Frequency](https://leetcode.com/problems/filter-characters-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3662.java) | | Easy |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3838 {
4+
public static class Solution1 {
5+
public String mapWordWeights(String[] words, int[] weights) {
6+
char[] chars = new char[]{'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'};
7+
chars = new StringBuilder(new String(chars)).reverse().toString().toCharArray();
8+
StringBuilder sb = new StringBuilder();
9+
for (int i = 0; i < words.length; i++) {
10+
String word = words[i];
11+
int sum = 0;
12+
for (char c : word.toCharArray()) {
13+
sum += weights[c - 'a'];
14+
}
15+
sum %= 26;
16+
sb.append(chars[sum]);
17+
}
18+
return sb.toString();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)