|
| 1 | +<p>You are given a string <code>s</code> containing lowercase English letters, and a matrix <code>shift</code>, where <code>shift[i] = [direction<sub>i</sub>, amount<sub>i</sub>]</code>:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>direction<sub>i</sub></code> can be <code>0</code> (for left shift) or <code>1</code> (for right shift).</li> |
| 5 | + <li><code>amount<sub>i</sub></code> is the amount by which string <code>s</code> is to be shifted.</li> |
| 6 | + <li>A left shift by 1 means remove the first character of <code>s</code> and append it to the end.</li> |
| 7 | + <li>Similarly, a right shift by 1 means remove the last character of <code>s</code> and add it to the beginning.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>Return the final string after all operations.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> s = "abc", shift = [[0,1],[1,2]] |
| 17 | +<strong>Output:</strong> "cab" |
| 18 | +<strong>Explanation:</strong> |
| 19 | +[0,1] means shift to left by 1. "abc" -> "bca" |
| 20 | +[1,2] means shift to right by 2. "bca" -> "cab"</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> s = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]] |
| 26 | +<strong>Output:</strong> "efgabcd" |
| 27 | +<strong>Explanation:</strong> |
| 28 | +[1,1] means shift to right by 1. "abcdefg" -> "gabcdef" |
| 29 | +[1,1] means shift to right by 1. "gabcdef" -> "fgabcde" |
| 30 | +[0,2] means shift to left by 2. "fgabcde" -> "abcdefg" |
| 31 | +[1,3] means shift to right by 3. "abcdefg" -> "efgabcd"</pre> |
| 32 | + |
| 33 | +<p> </p> |
| 34 | +<p><strong>Constraints:</strong></p> |
| 35 | + |
| 36 | +<ul> |
| 37 | + <li><code>1 <= s.length <= 100</code></li> |
| 38 | + <li><code>s</code> only contains lower case English letters.</li> |
| 39 | + <li><code>1 <= shift.length <= 100</code></li> |
| 40 | + <li><code>shift[i].length == 2</code></li> |
| 41 | + <li><code>direction<sub>i</sub></code><sub> </sub>is either <code>0</code> or <code>1</code>.</li> |
| 42 | + <li><code>0 <= amount<sub>i</sub> <= 100</code></li> |
| 43 | +</ul> |
0 commit comments