Java Solution with Only 2 Lines

  • 1

    Below is the recursive solution. I share this solution simply because of its concision. It took 260ms, which is not so brilliant but still acceptable.

    public class Solution {
        public int trailingZeroes(int n) {
            if (n / 5 == 0) return 0;
            return n / 5 + trailingZeroes(n / 5);

  • 1

    so they could be combine to only one line:)

    return n==0 ? n/5 : n/5 + trailingZeroes(n/5);

  • 0

    sorry, I do not understand it, can you tell me in detail? why you code like this. thank you so much.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.