-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFallingDisks.cpp
More file actions
38 lines (32 loc) · 835 Bytes
/
FallingDisks.cpp
File metadata and controls
38 lines (32 loc) · 835 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
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// write your code in C++14 (g++ 6.2.0)
//drop disks in order
A.push_back(0);//bottom_of_well
int disks = 0;
for(int i =0;i < B.size();i++)
{
//cout << i << endl;
if(A[0] >= B[i])
{
for(int j = 0;j < A.size()+1;j++)
{
if(A[j+1] < B[i])
{
//cout << i << "stuck at " << j+1 << endl;
A[j] = 0;
disks++;
break;
}
}
}
else
{
return disks;
}
}
return disks;
}