Skip to content

Commit

Permalink
이슈 #451에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 11, 2025
1 parent 7570048 commit b117165
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LeetCode/Gas_Station.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
int totalTank = 0;
int currentTank = 0;
int startStation = 0;

for (int i = 0; i < gas.size(); i++) {
int netGas = gas[i] - cost[i];
totalTank += netGas;
currentTank += netGas;

if (currentTank < 0) {
startStation = i + 1;
currentTank = 0;
}
}

return (totalTank >= 0) ? startStation : -1;
}
};

0 comments on commit b117165

Please sign in to comment.