Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bdbff73

Browse files
Create 134. Gas Station
1 parent 8a72523 commit bdbff73

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎134. Gas Station‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int canCompleteCircuit(int[] gas, int[] cost) {
3+
int position =0 , sum =0 , total =0;
4+
5+
for(int index=0;index<gas.length;index++){
6+
sum += gas[index] - cost[index];
7+
8+
if(sum<0){
9+
total+=sum;
10+
sum=0;
11+
position = index+1;
12+
}
13+
}
14+
15+
total += sum;
16+
17+
return total>=0?position:-1;
18+
}
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /