Solution 1: accepted 30ms
Recursive DFS. Check all possible paths from each node.
Time: O(n^2)
Space: O(n)
|
|
Recursive DFS. Check all possible paths from each node.
Time: O(n^2)
Space: O(n)
|
|
DP.
Time: O(n)
Space: O(1)
|
|
|
|
Time: O(n^2)
Brute force with double loops
|
|
|
|
Cost of coins: 1+2+3+…+k = k(1+k)/2
Calculate the maximum of k where k(1+k) <= 2n
(0 <= k < n)
|
|
Alternative from this post
We have many math solutions.
Increment and simply mapping the index.
|
|
This solution will use more space but has better performance.
|
|
Integer.toString(i, radix)
, 2 <= radix <= 36. For example, Integer.toString(11112222, 0)
will give 6m68u.
DP. The same as the cutting rope issue.
Time: O(n^2)
Space: O(n)
|
|
Could use math method.
Iteration.
Time: O(n)
Space: O(1)
|
|
Calculate the average at last - be flexible man.
|
|
DP.
|
|
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.
We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n).
Example 1:
Input: [4,2,3]
Output: True
Explanation: You could modify the first 4 to 1 to get a non-decreasing array.
Example 2:
Input: [4,2,1]
Output: False
Explanation: You can’t get a non-decreasing array by modify at most one element.
Note: The n belongs to [1, 10,000].
|
|
|
|
|
|
|
|