mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
22
greed/134.h
Normal file
22
greed/134.h
Normal file
@@ -0,0 +1,22 @@
|
||||
int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize) {
|
||||
int i = 0;
|
||||
while (i < gasSize) {
|
||||
int sumOfGas = 0, sumOfCost = 0;
|
||||
int cnt = 0;
|
||||
while (cnt < gasSize) {
|
||||
int j = (i + cnt) % gasSize;
|
||||
sumOfGas += gas[j];
|
||||
sumOfCost += cost[j];
|
||||
if (sumOfCost > sumOfGas) {
|
||||
break;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if (cnt == gasSize) {
|
||||
return i;
|
||||
} else {
|
||||
i = i + cnt + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user