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 c9bff6e

Browse files
committed
Update0134.加油站,添加C#
1 parent 85f8efe commit c9bff6e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎problems/0134.加油站.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,29 @@ object Solution {
630630
}
631631
}
632632
```
633+
### C#
634+
```csharp
635+
// 贪心算法,方法二
636+
public class Solution
637+
{
638+
public int CanCompleteCircuit(int[] gas, int[] cost)
639+
{
640+
int curSum = 0, totalSum = 0, start = 0;
641+
for (int i = 0; i < gas.Length; i++)
642+
{
643+
curSum += gas[i] - cost[i];
644+
totalSum += gas[i] - cost[i];
645+
if (curSum < 0)
646+
{
647+
start = i + 1;
648+
curSum = 0;
649+
}
650+
}
651+
if (totalSum < 0) return -1;
652+
return start;
653+
}
654+
}
655+
```
633656

634657
<p align="center">
635658
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

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