Time and Space Calc

whitehousechef·2025년 6월 18일

comb

look at https://velog.io/@whitehousechef/Leetcode-3405.-Count-the-Number-of-Arrays-with-K-Matching-Adjacent-Elements example and my explanation

comb formula is nCk and n!/k!x(n-k)!. The time is the minimum of k and n-k.

perm

math.perm(n, k): O(k)

pow()

look at https://velog.io/@whitehousechef/Leetcode-3405.-Count-the-Number-of-Arrays-with-K-Matching-Adjacent-Elements example and my explanation

time is the exponent (power) so if it is like sth to power of n, then the time is n.

space

normally the data structure needed to store the required answer isnt counted as the main space complexity

https://velog.io/@whitehousechef/Leetcode-2411.-Smallest-Subarrays-With-Maximum-Bitwise-OR

string += can be o(k^2)

Strings are immutable so when we append like that we are essentially making a new string by copying old content

s = new StringBuilder(s).append("world").toString();

this can be k^2 so use stringbuilder

0개의 댓글