-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1089.复写零.c
More file actions
90 lines (61 loc) · 1.56 KB
/
1089.复写零.c
File metadata and controls
90 lines (61 loc) · 1.56 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* @lc app=leetcode.cn id=1089 lang=c
*
* [1089] 复写零
*/
// @lc code=start
void duplicateZeros(int* arr, int arrSize){
int currentSize = 0;
int arrIndex = 0;
bool flag = false;
for (arrIndex = 0; arrIndex < arrSize; arrIndex++) {
currentSize++;
if (currentSize >= arrSize) {
flag = false;
break;
}
if (arr[arrIndex] == 0) {
currentSize++;
}
if (currentSize >= arrSize) {
flag = true;
break;
}
}
for (currentSize = (arrSize - 1); (arrIndex >= 0); arrIndex--) {
if (arr[arrIndex] == 0) {
if ((!flag) && (currentSize == (arrSize - 1))) {
if (currentSize >= 0) {
arr[currentSize--] = 0;
}
else {
break;
}
}
else {
if (currentSize >= 0) {
arr[currentSize--] = 0;
}
else {
break;
}
if (currentSize >= 0) {
arr[currentSize--] = 0;
}
else {
break;
}
}
}
else {
if (currentSize >= 0) {
arr[currentSize--] = arr[arrIndex];
}
else {
break;
}
}
}
return;
}
// @lc code=end