package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
3179. Find the N-th Value After K Seconds
Solution idea
Prefix Sum
- 以
[1, 1, ..., 1]
作为种子,算prefixSum算k次。
Time complexity = $O(k\cdot n)$
Pascal's Triangle
- Pascal's Triangle is a graphical representation of the binomial coefficients.
- The binomial coefficient $\binom{n}{k}$, in Pascal's Triangle, is the element at row $n$ and position $k$ (starting from 0).
- The value at position (n−1) after k seconds can be represented in Pascal's Triangle as: $\binom{n+k-1}{k}$ (why?)
Time complexity = $O(\binom{n+k-1}{k})$