Back to course home
0% completed
Vote For New Content
More eleganct c++ pattern
lejafilip
Jul 29, 2024
Ofc it is just personally and we use std::swap.
class Solution { public: vector<int> sort(vector<int> &nums) { auto i = 0; while(i < nums.size()) { if(nums[i] == i + 1) { i++; continue; } auto jumpValue = nums[i]; std::swap(nums[i], nums[jumpValue - 1]); } return nums; } };
0
0
Comments
Comments
On this page