We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50092f2 commit 3bcec72Copy full SHA for 3bcec72
Shifting Letters/Shifting_Letters.cpp
@@ -0,0 +1,27 @@
1
+// 从后向前,反向解决问题
2
+
3
+// Runtime: 52 ms, faster than 92.07% of C++ online submissions for Shifting Letters.
4
+// Memory Usage: 11.7 MB, less than 75.00% of C++ online submissions for Shifting Letters.
5
6
+class Solution
7
+{
8
+public:
9
+ string shiftingLetters(string S, vector<int>& shifts)
10
+ {
11
+ string res = S;
12
13
+ int shift = 0;
14
15
+ for (int index = res.length() - 1; index >= 0; --index)
16
17
+ shift = (shift + shifts[index]) % 26;
18
19
+ int temp = res[index] - 'a';
20
+ temp = (temp + shift) % 26;
21
22
+ res[index] = (temp + 'a');
23
+ }
24
25
+ return res;
26
27
+};
0 commit comments