diff --git a/LeetCode/Rotate_Array.cpp b/LeetCode/Rotate_Array.cpp new file mode 100644 index 0000000..db8fd86 --- /dev/null +++ b/LeetCode/Rotate_Array.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +class Solution { +public: + void rotate(vector& nums, int k) { + int n = nums.size(); + vector result(n); + k = k % n; + + for (int i = 0; i < n; i++) { + result[(k + i) % n] = nums[i]; + } + + nums = result; + } +}; \ No newline at end of file