My LeetCode grinding. Trying to do a problem a day.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

problem.txt 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction, amount]:
  2. direction can be 0 (for left shift) or 1 (for right shift).
  3. amount is the amount by which string s is to be shifted.
  4. A left shift by 1 means remove the first character of s and append it to the end.
  5. Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
  6. Return the final string after all operations.
  7. Example 1:
  8. Input: s = "abc", shift = [[0,1],[1,2]]
  9. Output: "cab"
  10. Explanation:
  11. [0,1] means shift to left by 1. "abc" -> "bca"
  12. [1,2] means shift to right by 2. "bca" -> "cab"
  13. Example 2:
  14. Input: s = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]
  15. Output: "efgabcd"
  16. Explanation:
  17. [1,1] means shift to right by 1. "abcdefg" -> "gabcdef"
  18. [1,1] means shift to right by 1. "gabcdef" -> "fgabcde"
  19. [0,2] means shift to left by 2. "fgabcde" -> "abcdefg"
  20. [1,3] means shift to right by 3. "abcdefg" -> "efgabcd"
  21. Constraints:
  22. 1 <= s.length <= 100
  23. s only contains lower case English letters.
  24. 1 <= shift.length <= 100
  25. shift[i].length == 2
  26. 0 <= shift[i][0] <= 1
  27. 0 <= shift[i][1] <= 100