You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/1000-1099/1014.Best Sightseeing Pair/README_EN.md
+38-18
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,11 @@ tags:
55
55
56
56
<!-- solution:start -->
57
57
58
-
### Solution 1
58
+
### Solution 1: Enumeration
59
+
60
+
We can enumerate $j$ from left to right while maintaining the maximum value of $values[i] + i$ for elements to the left of $j$, denoted as $mx$. For each $j$, the maximum score is $mx + values[j] - j$. The answer is the maximum of these maximum scores for all positions.
61
+
62
+
The time complexity is $O(n)$, where $n$ is the length of the array $\textit{values}$. The space complexity is $O(1)$.
Copy file name to clipboardexpand all lines: solution/1000-1099/1018.Binary Prefix Divisible By 5/README_EN.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,11 @@ Only the first number is divisible by 5, so answer[0] is true.
60
60
61
61
<!-- solution:start -->
62
62
63
-
### Solution 1
63
+
### Solution 1: Simulation
64
+
65
+
We use a variable $x$ to represent the current binary prefix, then traverse the array $nums$. For each element $v$, we left shift $x$ by one bit, then add $v$, and take the result modulo $5$. If the result equals $0$, it means the current binary prefix is divisible by $5$, and we add $\textit{true}$ to the answer array; otherwise, we add $\textit{false}$ to the answer array.
66
+
67
+
The time complexity is $O(n)$, and ignoring the space consumption of the answer array, the space complexity is $O(1)$.
0 commit comments