-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChips_Factory.cpp
More file actions
45 lines (37 loc) · 776 Bytes
/
Chips_Factory.cpp
File metadata and controls
45 lines (37 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Chips Factory
/*
A chips factory is packing chips in packets. The packets of chips are represented as an array A.
Find the packet of chips which are empty (Ai = 0) and move them to the end of the array. Return the resultant array.
Problem Constraints
1 <= |A| <= 105
0 <= Ai <= 109
Input Format
Given an integer array A.
Output Format
Return an integer array.
Example Input
Input 1:
A = [0, 1, 2, 3]
Input 2:
A = [1, 0, 0, 0]
Example Output
Output 1:
[1, 2, 3, 0]
Output 2:
[1, 0, 0, 0]
*/
//Solution in CPP
vector<int> Solution::solve(vector<int> &A) {
vector<int> v;
for(auto &i:A){
if(i!=0){
v.push_back(i);
// A.erase(i);
}
}
for(auto &i:A){
if(i==0)
v.push_back(i);
}
return v;
}