void rotate(vector<int>& nums, int k)
{
deque<int> dq;
for (int j = 0; j < nums.size(); j++)
dq.push_back(nums[j]);
nums.clear();
for (int i = 0; i < k; i++)
{
int val = dq.back();
dq.pop_back();
dq.push_front(val);
}
while (!dq.empty())
{
nums.push_back(dq.front());
dq.pop_front();
}
}
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode] Excel Sheet Column Number (0) | 2023.12.11 |
---|---|
[LeetCode] Evaluate Reverse Polish Notation (0) | 2023.12.11 |
[LeetCode] Merge Sorted Array (0) | 2023.12.08 |
[LeetCode] Length of Last Word (0) | 2023.12.06 |
[LeetCode] 17 - Letter Combinations of a Phone Number (0) | 2023.11.22 |