134.h 551 B

12345678910111213141516171819202122
  1. int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize) {
  2. int i = 0;
  3. while (i < gasSize) {
  4. int sumOfGas = 0, sumOfCost = 0;
  5. int cnt = 0;
  6. while (cnt < gasSize) {
  7. int j = (i + cnt) % gasSize;
  8. sumOfGas += gas[j];
  9. sumOfCost += cost[j];
  10. if (sumOfCost > sumOfGas) {
  11. break;
  12. }
  13. cnt++;
  14. }
  15. if (cnt == gasSize) {
  16. return i;
  17. } else {
  18. i = i + cnt + 1;
  19. }
  20. }
  21. return -1;
  22. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。