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()); + } +};