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 81230ba

Browse files
committed
Add solution 134.
1 parent 6379b6f commit 81230ba

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $gas
5+
* @param Integer[] $cost
6+
* @return Integer
7+
*/
8+
function canCompleteCircuit($gas, $cost) {
9+
$sum = 0;
10+
$min = 2147483647;
11+
$minIndex = 0;
12+
for($i=0; $i<count($gas); $i++){
13+
$sum += $gas[$i]-$cost[$i];
14+
if($sum<$min){
15+
$min = $sum;
16+
$minIndex = $i;
17+
}
18+
}
19+
if($sum<0) return -1;
20+
return $minIndex==count($gas)-1 ? 0 : $minIndex + 1;
21+
}
22+
}

0 commit comments

Comments
(0)

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