File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 46
46
47
47
## Week 5 🚧
48
48
49
- Coming Soon...
49
+ 1 . [ Pancake Sort ] ( https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/553/week-5-august-29th-august-31st/3441/ ) ➡️ [ CPP Solution ] ( Week5/pancakeSort.cpp )
50
50
51
51
## Other Challenges 💪
52
52
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ private:
3
+ int find (vector<int >& A, int target) {
4
+ for (int i = 0 ; i < A.size (); ++i)
5
+ if (A[i] == target) return i;
6
+ return -1 ;
7
+ }
8
+
9
+ void flip (vector<int >& A, int pos) {
10
+ int i = 0 ;
11
+
12
+ while (i < pos) {
13
+ int temp = A[i];
14
+ A[i++] = A[pos];
15
+ A[pos--] = temp;
16
+ }
17
+ }
18
+ public:
19
+ vector<int > pancakeSort (vector<int >& A) {
20
+ vector<int > flips;
21
+
22
+ for (int n = A.size (); n > 0 ; --n) {
23
+ int index = find (A, n);
24
+
25
+ flip (A, index);
26
+ flip (A, n - 1 );
27
+
28
+ flips.push_back (index + 1 );
29
+ flips.push_back (n);
30
+ }
31
+
32
+ return flips;
33
+ }
34
+ };
You can’t perform that action at this time.
0 commit comments