-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1422.分割字符串的最大得分.c
More file actions
52 lines (34 loc) · 885 Bytes
/
1422.分割字符串的最大得分.c
File metadata and controls
52 lines (34 loc) · 885 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
46
47
48
49
50
51
/*
* @lc app=leetcode.cn id=1422 lang=c
*
* [1422] 分割字符串的最大得分
*/
// @lc code=start
int maxScore(char * s){
int resultSum = 0;
int resultMax = 0;
int oneCounter = 0;
int zeroCounter = 0;
for (char *strPointer = s; strPointer < (s + strlen(s)); strPointer++) {
if ((*strPointer) == '0') {
zeroCounter++;
}
else if ((*strPointer) == '1') {
oneCounter++;
}
}
resultSum = oneCounter;
for (char *strPointer = s; strPointer < (s + strlen(s) - 1); strPointer++) {
if ((*strPointer) == '0') {
resultSum++;
}
else if ((*strPointer) == '1') {
resultSum--;
}
if (resultSum > resultMax) {
resultMax = resultSum;
}
}
return resultMax;
}
// @lc code=end