From 5caef3bd087a96daee2dd16ad29dca716f154a53 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 4 Dec 2024 09:43:37 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=8A=88=20#194=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LeetCode/Rotate_Array.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LeetCode/Rotate_Array.cpp 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