[Programmers] 종이접기

Time Lapse :12min 2sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <vector>

using namespace std;
vector<int> solution(int n) {
vector<int> answer;
for(int i=1;i<=n;i++){
vector<int> temp;
temp.assign(answer.begin(),answer.end());
temp.push_back(0);
int idx = temp.size()-2;
while(idx>=0){
if(temp[idx]==0)
temp.push_back(1);
else
temp.push_back(0);
idx--;
}
swap(temp,answer);
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/origami/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.