LeetCode gas station implementation
Your code nicely exploits all the constraints from the instructions.

It runs in linear time, which is much better than the naive approach, which would run in quadratic time.

It doesn't need any space other than a few local variables. Perfect.

Without further explanation the code is a bit hard to follow because of the many variables, and it is not entirely clear what sum and diff are exactly. Sure, sum holds a sum, but of what?

The diff variable should move inside the for loop since it is only needed there.

Instead of tank + diff &lt; 0, you could also write tank &lt; diff, but since you later compute tank + diff, having this common subexpression in the code is actually useful. You could also combine the expressions: just execute tank += diff, and if there's a negative amount of gas in the tank after that, reset it to zero. It's impossible in the real world to have negative amounts of gas in the tank, but it would make the code shorter.

For understanding the algorithm I would have preferred a variant that has two for loops. In the first loop, just compute the sum. In the second loop, determine the starting index. That way, there's fewer variables who can confuse me, the human reader. But if you're going for execution speed, you approach is perfect, again.

I would have preferred a short introduction about how you constructed your algorithm. Learning the ideas and then going from ideas to code is often easier than going backwards from the code to the underlying ideas.