Skip to content

Commit 00704fb

Browse files
authored
Create score-of-a-string.cpp
1 parent d2e7b1d commit 00704fb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

C++/score-of-a-string.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// string
5+
class Solution {
6+
public:
7+
int scoreOfString(string s) {
8+
int result = 0;
9+
for (int i = 0; i + 1 < size(s); ++i) {
10+
result += abs(s[i + 1] - s[i]);
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)