Skip to content

Commit ad16109

Browse files
committed
feat: add solutions to lc problem: No.2610
No.2610.Convert an Array Into a 2D Array With Conditions
1 parent f31bc2a commit ad16109

File tree

2 files changed

+11
-1
lines changed
  • solution/2600-2699
    • 2609.Find the Longest Balanced Substring of a Binary String
    • 2610.Convert an Array Into a 2D Array With Conditions

2 files changed

+11
-1
lines changed

solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
遍历字符串 $s$,对于当前字符 $c$:
6767

6868
- 如果当前字符为 `'0'`,我们判断此时 $one$ 是否大于 $0$,是则将 $zero$ 和 $one$ 重置为 $0$,接下来将 $zero$ 加 $1$。
69-
- 如果当前字符为 `'1'`,则将 $one$ 加 $1$,并更新答案为 $2 \times min(one, zero)$。
69+
- 如果当前字符为 `'1'`,则将 $one$ 加 $1$,并更新答案为 $ans = max(ans, 2 \times min(one, zero))$。
7070

7171
遍历结束后,即可得到最长的平衡子串的长度。
7272

solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ nums 中的所有元素都有用到,并且每一行都由不同的整数组成
5151

5252
<!-- 这里可写通用的实现逻辑 -->
5353

54+
**方法一:数组或哈希表**
55+
56+
我们先用数组或哈希表 $cnt$ 统计数组 $nums$ 中每个元素出现的次数。
57+
58+
然后遍历 $cnt$,对于每个元素 $x$,我们将其添加到答案列表中的第 $0$ 行,第 $1$ 行,第 $2$ 行,...,第 $cnt[x]-1$ 行。
59+
60+
最后返回答案列表即可。
61+
62+
时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为数组 $nums$ 的长度。
63+
5464
<!-- tabs:start -->
5565

5666
### **Python3**

0 commit comments

Comments
 (0)