-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Sherali Obidov
committed
Jul 28, 2018
1 parent
9bb9a21
commit 03a5897
Showing
2 changed files
with
47 additions
and
1 deletion.
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
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,22 @@ | ||
package problems.medium; | ||
|
||
/** | ||
* Why Did you create this class? what does it do? | ||
*/ | ||
public class ShiftingLetters { | ||
public String shiftingLetters(String s, int[] a) { | ||
if (a == null || a.length == 0) | ||
return s; | ||
a[a.length - 1] %= 26; | ||
for (int i = a.length - 2; i >= 0; i--) { | ||
a[i] = (a[i] + a[i + 1]) % 26; | ||
} | ||
char[] c = s.toCharArray(); | ||
for (int i = 0; i < a.length; i++) { | ||
c[i] = (char) (a[i] + c[i]); | ||
if (c[i] > 'z') | ||
c[i] = (char) (c[i] % 'z' + 'a' - 1); | ||
} | ||
return new String(c); | ||
} | ||
} |