From a0ed56e754897eba6df6bb1976e8c3cbefc40d03 Mon Sep 17 00:00:00 2001 From: priya <107272239+priya-thv@users.noreply.github.com> Date: Sun, 25 Jun 2023 15:00:09 +0530 Subject: [PATCH] Create rotate array.cpp --- rotate array.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 rotate array.cpp diff --git a/rotate array.cpp b/rotate array.cpp new file mode 100644 index 0000000..74a308f --- /dev/null +++ b/rotate array.cpp @@ -0,0 +1,11 @@ +class Solution { +public: + void rotate(vector& nums, int k) { + + int n=nums.size(); + k%=n; + reverse(nums.begin(),nums.end()); + reverse(nums.begin(),nums.begin()+k); + reverse(nums.begin()+k,nums.end()); + } +};