-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5d8a43
commit 3c604b1
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Solution { | ||
public void reverseString(char[] s) { | ||
int n = s.length; | ||
for (int i = 0; i < n / 2; i++) { | ||
char temp = s[i]; | ||
s[i] = s[n - i - 1]; | ||
s[n - i - 1] = temp; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Solution { | ||
public int scoreOfString(String s) { | ||
int score = 0; | ||
int n = s.length(); | ||
for (int i = 0; i < n - 1; i++) { | ||
int diff = Math.abs(s.charAt(i + 1) - s.charAt(i)); | ||
score += diff; | ||
} | ||
return score; | ||
} | ||
} |