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/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README_EN.md
+32-5
Original file line number
Diff line number
Diff line change
@@ -68,13 +68,13 @@ It can be shown that we cannot have less than 3 rows in a valid array.</pre>
68
68
69
69
### Solution 1: Array or Hash Table
70
70
71
-
We use an array or hash table $cnt$ to count the number of occurrences of each element in the array $nums$.
71
+
We first use an array or hash table $\textit{cnt}$ to count the frequency of each element in the array $\textit{nums}$.
72
72
73
-
Then we traverse the $cnt$ array, add $x$to the $0$th row, the $1$st row, the $2$nd row, ..., the ($cnt[x]-1$)th row of the answer list.
73
+
Then we iterate through $\textit{cnt}$. For each element $x$, we add it to the 0th row, 1st row, 2nd row, ..., and $(cnt[x]-1)$th row of the answer list.
74
74
75
-
Finally, return the answer list.
75
+
Finally, we return the answer list.
76
76
77
-
The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is the length of the array $nums$.
77
+
The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is the length of the array $\textit{nums}$.
<pdata-end="384"data-start="34">You are given a <code>replacements</code> mapping and a <code>text</code> string that may contain <strong>placeholders</strong> formatted as <codedata-end="139"data-start="132">%var%</code>, where each <code>var</code> corresponds to a key in the <code>replacements</code> mapping. Each replacement value may itself contain <strong>one or more</strong> such <strong>placeholders</strong>. Each <strong>placeholder</strong> is replaced by the value associated with its corresponding replacement key.</p>
<pdata-end="353"data-start="34">Return the fully substituted <code>text</code> string which <strong>does not</strong> contain any <strong>placeholders</strong>.</p>
<li data-end="138" data-start="71">The mapping associates <code data-end="101" data-start="96">"A"</code> with <code data-end="114" data-start="107">"abc"</code> and <code data-end="124" data-start="119">"B"</code> with <code data-end="137" data-start="130">"def"</code>.</li>
41
-
<li data-end="203" data-start="139">Replace <code data-end="154" data-start="149">%A%</code> with <code data-end="167" data-start="160">"abc"</code> and <code data-end="177" data-start="172">%B%</code> with <code data-end="190" data-start="183">"def"</code> in the text.</li>
42
-
<li data-end="238" data-start="204">The final text becomes <code data-end="237" data-start="226">"abc_def"</code>.</li>
<li data-end="346" data-start="255">The mapping associates <code data-end="285" data-start="280">"A"</code> with <code data-end="298" data-start="291">"bce"</code>, <code data-end="305" data-start="300">"B"</code> with <code data-end="318" data-start="311">"ace"</code>, and <code data-end="329" data-start="324">"C"</code> with <code data-end="345" data-start="335">"abc%B%"</code>.</li>
57
-
<li data-end="411" data-start="347">Replace <code data-end="362" data-start="357">%A%</code> with <code data-end="375" data-start="368">"bce"</code> and <code data-end="385" data-start="380">%B%</code> with <code data-end="398" data-start="391">"ace"</code> in the text.</li>
58
-
<li data-end="496" data-start="412">Then, for <code data-end="429" data-start="424">%C%</code>, substitute <code data-end="447" data-start="442">%B%</code> in <code data-end="461" data-start="451">"abc%B%"</code> with <code data-end="474" data-start="467">"ace"</code> to obtain <code data-end="495" data-start="485">"abcace"</code>.</li>
59
-
<li data-end="541" data-is-last-node="" data-start="497">The final text becomes <code data-end="540" data-start="522">"bce_ace_abcace"</code>.</li>
<li data-end="1683" data-start="1433">Each element of <code data-end="1465" data-start="1451">replacements</code> is a two-element list <code data-end="1502" data-start="1488">[key, value]</code>, where:
<li data-end="1558" data-start="1513"><code data-end="1520" data-start="1515">key</code> is a single uppercase English letter.</li>
71
-
<li data-end="1683" data-start="1561"><code data-end="1570" data-start="1563">value</code> is a non-empty string of at most 8 characters that may contain zero or more placeholders formatted as <code data-end="1682" data-start="1673">%<key>%</code>.</li>
<li data-end="726" data-start="688">All replacement keys are unique.</li>
75
-
<li data-end="1875" data-start="1723">The <code>text</code> string is formed by concatenating all key placeholders (formatted as <code data-end="1808" data-start="1799">%<key>%</code>) randomly from the replacements mapping, separated by underscores.</li>
<li data-end="2052" data-start="1943">Every placeholder in the <code>text</code> or in any replacement value corresponds to a key in the <code>replacements</code> mapping.</li>
78
-
<li data-end="2265" data-start="2205">There are no cyclic dependencies between replacement keys.</li>
0 commit comments