|
1 | 1 | --- |
2 | 2 | title: 3072. Allocate elements into two arrays II.md |
3 | | -date: '2024.01.01 0:00' |
| 3 | +date: "2024.01.01 0:00" |
4 | 4 | tags: |
5 | 5 | - - Python |
6 | 6 | - - answer |
|
9 | 9 | - Array |
10 | 10 | - simulation |
11 | 11 | abbrlink: 48a38683 |
| 12 | +docId: r12u8o7j73oxhbvgphi939fb |
12 | 13 | --- |
13 | 14 |
|
14 | 15 | # topic: |
15 | 16 |
|
16 | 17 | [3072. Allocate elements into two arrays II.md](https://leetcode.cn/problems/distribute-elements-into-two-arrays-ii/description/?envType=daily-question&envId=2024-06-05) |
17 | 18 | """ |
| 19 | + |
18 | 20 | <p>Give you a bidding <strong>1</strong> start、Length <code>n</code> 的整数Array <code>nums</code> 。</p> |
19 | 21 |
|
20 | 22 | <p>Now define function <code>greaterCount</code> ,Make <code>greaterCount(arr, val)</code> 返回Array <code>arr</code> middle<strong> Strict</strong> <code>val</code> Number of elements。</p> |
@@ -81,20 +83,20 @@ therefore,连接形成的Array result yes [3,3,3,3] 。 |
81 | 83 | """ |
82 | 84 |
|
83 | 85 | # Thought: |
| 86 | + |
84 | 87 | 1. initialization: |
85 | | -首先Will nums Array反转,以便我们可以从最后一个元素start处理。这一步exist最初与学长@Angro beatICPCI learned,`pop()` Compare `pop(0)` It is much faster。 |
86 | | -Will反转后的第一个元素分配给 arr1 and temp1,The second element is allocated to arr2 and temp2。 |
| 88 | + 首先Will nums Array反转,以便我们可以从最后一个元素start处理。这一步exist最初与学长@Angro beatICPCI learned,`pop()` Compare `pop(0)` It is much faster。 |
| 89 | + Will反转后的第一个元素分配给 arr1 and temp1,The second element is allocated to arr2 and temp2。 |
87 | 90 |
|
88 | 91 | 2. Iteration processing each element: |
89 | | -use while Traversal nums Array的剩余元素。 |
90 | | -For each element,use bisect.bisect_right exist arr1 and arr2 middle找到Compare当前元素小的元素的数量。 |
91 | | -Re -uselen(arr1)andlen(arr2)Minus this quantity,得到Compare当前元素大的元素的数量。 |
92 | | -然后进行Compare较To。 为了use二分查找,therefore我们要保证 arr1 and arr2 yes有序的, Pythonmiddleuse `insort()` To。 |
93 | | -but同时我们要维持一个答案Array,thereforeappendTo。 |
| 92 | + use while Traversal nums Array的剩余元素。 |
| 93 | + For each element,use bisect.bisect_right exist arr1 and arr2 middle找到Compare当前元素小的元素的数量。 |
| 94 | + Re -uselen(arr1)andlen(arr2)Minus this quantity,得到Compare当前元素大的元素的数量。 |
| 95 | + 然后进行Compare较To。 为了use二分查找,therefore我们要保证 arr1 and arr2 yes有序的, Pythonmiddleuse `insort()` To。 |
| 96 | + but同时我们要维持一个答案Array,thereforeappendTo。 |
94 | 97 |
|
95 | 98 | 3. Merge answer |
96 | 99 |
|
97 | | - |
98 | 100 | # Code: |
99 | 101 |
|
100 | 102 | ```python |
@@ -132,4 +134,4 @@ class Solution: |
132 | 134 | temp1.append(temp) |
133 | 135 |
|
134 | 136 | return temp1 + temp2 |
135 | | -``` |
| 137 | +``` |
0 commit comments