본문 바로가기
IT/알고리즘

2] Leetcode 1470. Shuffle the Array

by 깻잎쌈 2020. 6. 16.
반응형
 

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;
        
    }
};

새로운 벡터에다가 순서대로 넣어주었다.

 

반응형

댓글