반응형
Shuffle the Array - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
배열 안에 짝수개의 숫자들이 있고
그걸 반으로 나눠서 기준에 맞게 다시 정렬하는 문제다.
class Solution {
public:
vector<int> shuffle(vector<int>& nums, int n) {
vector<int>ans;
for(int i=0;i<n;i++){
ans.push_back(nums[i]);
ans.push_back(nums[i+n]);
}
return ans;
}
};
새로운 벡터에다가 순서대로 넣어주었다.
반응형
'IT > 알고리즘' 카테고리의 다른 글
6] Leetcode 771. Jewels and Stones (0) | 2020.06.21 |
---|---|
5] Leetcode 1342. Number of Steps to Reduce a Number to Zero (0) | 2020.06.21 |
4] Leetcode 1108. Defanging an IP Address (0) | 2020.06.21 |
3] Leetcode 1431. Kids With the Greatest Number of Candies (0) | 2020.06.18 |
1] Leetcode 1480. Running Sum of 1d Array (0) | 2020.06.16 |
댓글