Skip to content

Commit 0795e89

Browse files
committed
Solution to today's problem
1 parent d94478a commit 0795e89

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.spannm.leetcode.lc3.lc3100;
2+
3+
import io.github.spannm.leetcode.LeetcodeProblem;
4+
5+
import java.util.stream.IntStream;
6+
7+
/**
8+
* 3110. Score of a String.
9+
*/
10+
class Problem3110 extends LeetcodeProblem {
11+
12+
int scoreOfString(String _s) {
13+
return IntStream.range(1, _s.length()).map(i -> Math.abs(_s.charAt(i - 1) - _s.charAt(i))).sum();
14+
}
15+
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.github.spannm.leetcode.lc3.lc3100;
2+
3+
import io.github.spannm.leetcode.LeetcodeBaseTest;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.CsvSource;
6+
7+
class Problem3110Test extends LeetcodeBaseTest {
8+
9+
@ParameterizedTest(name = "[{index}] {0} --> {1}")
10+
@CsvSource(delimiter = ';', value = {
11+
"hello; 13",
12+
"zaz; 50"
13+
})
14+
void test(String _s, int _expectedResult) {
15+
assertEquals(_expectedResult, new Problem3110().scoreOfString(_s));
16+
}
17+
18+
}

0 commit comments

Comments
 (0)