FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_131/LeetCode_441_131.cpp at master · algorithm001/algorithm · GitHub
algorithm001
/
algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
148
Star
118
Code
Issues
548
Pull requests
46
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_01
/
id_131
/
LeetCode_441_131.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (39 loc) · 972 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_131
/
LeetCode_441_131.cpp
Copy path
File metadata and controls
41 lines (39 loc) · 972 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
class
Solution
{
public:
int
findSuitData
(vector<
int
>& unorderV,
int
index)
{
if
(unorderV.
empty
())
{
unorderV.
push_back
(index);
return
-
1
;
}
int
lastIndex = unorderV[unorderV.
size
() -
1
];
if
(index %
2
!= lastIndex %
2
)
{
unorderV.
pop_back
();
return
lastIndex;
}
else
{
unorderV.
push_back
(index);
}
return
-
1
;
}
vector<
int
>
sortArrayByParityII
(vector<
int
>& A) {
vector<
int
> unorderV;
for
(
int
begin =
0
; begin < A.
size
(); ++begin)
{
if
(begin %
2
!= A[begin] %
2
)
{
int
i =
findSuitData
(unorderV, begin);
if
(i >=
0
)
{
int
tmpData = A[begin];
A[begin] = A[i];
A[i] = tmpData;
}
}
}
return
A;
}
};
Back
|
FazBrowse Home
|
New Git URL