Skip to content

Commit c279144

Browse files
authored
Added tasks 2201-2250
1 parent d760a98 commit c279144

File tree

121 files changed

+4267
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4267
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,46 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
18481848

18491849
| # | Title | Difficulty | Tag | Time, ms | Time, %
18501850
|------|----------------|-------------|-------------|----------|---------
1851+
| 2250 |[Count Number of Rectangles Containing Each Point](src/main/kotlin/g2201_2300/s2250_count_number_of_rectangles_containing_each_point/Solution.kt)| Medium | Array, Sorting, Binary_Search, Binary_Indexed_Tree | 967 | 100.00
1852+
| 2249 |[Count Lattice Points Inside a Circle](src/main/kotlin/g2201_2300/s2249_count_lattice_points_inside_a_circle/Solution.kt)| Medium | Array, Hash_Table, Math, Enumeration, Geometry | 204 | 100.00
1853+
| 2248 |[Intersection of Multiple Arrays](src/main/kotlin/g2201_2300/s2248_intersection_of_multiple_arrays/Solution.kt)| Easy | Array, Hash_Table, Counting | 197 | 100.00
1854+
| 2246 |[Longest Path With Different Adjacent Characters](src/main/kotlin/g2201_2300/s2246_longest_path_with_different_adjacent_characters/Solution.kt)| Hard | Array, String, Depth_First_Search, Tree, Graph, Topological_Sort | 828 | 100.00
1855+
| 2245 |[Maximum Trailing Zeros in a Cornered Path](src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path/Solution.kt)| Medium | Array, Matrix, Prefix_Sum | 888 | 100.00
1856+
| 2244 |[Minimum Rounds to Complete All Tasks](src/main/kotlin/g2201_2300/s2244_minimum_rounds_to_complete_all_tasks/Solution.kt)| Medium | Array, Hash_Table, Greedy, Counting | 584 | 73.68
1857+
| 2243 |[Calculate Digit Sum of a String](src/main/kotlin/g2201_2300/s2243_calculate_digit_sum_of_a_string/Solution.kt)| Easy | String, Simulation | 141 | 100.00
1858+
| 2242 |[Maximum Score of a Node Sequence](src/main/kotlin/g2201_2300/s2242_maximum_score_of_a_node_sequence/Solution.kt)| Hard | Array, Sorting, Graph, Enumeration | 844 | 100.00
1859+
| 2241 |[Design an ATM Machine](src/main/kotlin/g2201_2300/s2241_design_an_atm_machine/ATM.kt)| Medium | Array, Greedy, Design | 764 | 100.00
1860+
| 2240 |[Number of Ways to Buy Pens and Pencils](src/main/kotlin/g2201_2300/s2240_number_of_ways_to_buy_pens_and_pencils/Solution.kt)| Medium | Math, Enumeration | 143 | 100.00
1861+
| 2239 |[Find Closest Number to Zero](src/main/kotlin/g2201_2300/s2239_find_closest_number_to_zero/Solution.kt)| Easy | Array | 245 | 66.67
1862+
| 2236 |[Root Equals Sum of Children](src/main/kotlin/g2201_2300/s2236_root_equals_sum_of_children/Solution.kt)| Easy | Tree, Binary_Tree | 141 | 86.73
1863+
| 2235 |[Add Two Integers](src/main/kotlin/g2201_2300/s2235_add_two_integers/Solution.kt)| Easy | Math | 131 | 65.81
1864+
| 2234 |[Maximum Total Beauty of the Gardens](src/main/kotlin/g2201_2300/s2234_maximum_total_beauty_of_the_gardens/Solution.kt)| Hard | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 699 | 100.00
1865+
| 2233 |[Maximum Product After K Increments](src/main/kotlin/g2201_2300/s2233_maximum_product_after_k_increments/Solution.kt)| Medium | Array, Greedy, Heap_Priority_Queue | 766 | 100.00
1866+
| 2232 |[Minimize Result by Adding Parentheses to Expression](src/main/kotlin/g2201_2300/s2232_minimize_result_by_adding_parentheses_to_expression/Solution.kt)| Medium | String, Enumeration | 191 | 100.00
1867+
| 2231 |[Largest Number After Digit Swaps by Parity](src/main/kotlin/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/Solution.kt)| Easy | Sorting, Heap_Priority_Queue | 124 | 100.00
1868+
| 2227 |[Encrypt and Decrypt Strings](src/main/kotlin/g2201_2300/s2227_encrypt_and_decrypt_strings/Encrypter.kt)| Hard | Array, String, Hash_Table, Design, Trie | 483 | 75.00
1869+
| 2226 |[Maximum Candies Allocated to K Children](src/main/kotlin/g2201_2300/s2226_maximum_candies_allocated_to_k_children/Solution.kt)| Medium | Array, Binary_Search | 544 | 66.67
1870+
| 2225 |[Find Players With Zero or One Losses](src/main/kotlin/g2201_2300/s2225_find_players_with_zero_or_one_losses/Solution.kt)| Medium | Array, Hash_Table, Sorting, Counting | 1323 | 65.79
1871+
| 2224 |[Minimum Number of Operations to Convert Time](src/main/kotlin/g2201_2300/s2224_minimum_number_of_operations_to_convert_time/Solution.kt)| Easy | String, Greedy | 155 | 66.67
1872+
| 2223 |[Sum of Scores of Built Strings](src/main/kotlin/g2201_2300/s2223_sum_of_scores_of_built_strings/Solution.kt)| Hard | String, Binary_Search, Hash_Function, String_Matching, Rolling_Hash, Suffix_Array | 264 | 100.00
1873+
| 2222 |[Number of Ways to Select Buildings](src/main/kotlin/g2201_2300/s2222_number_of_ways_to_select_buildings/Solution.kt)| Medium | String, Dynamic_Programming, Prefix_Sum | 261 | 100.00
1874+
| 2221 |[Find Triangular Sum of an Array](src/main/kotlin/g2201_2300/s2221_find_triangular_sum_of_an_array/Solution.kt)| Medium | Array, Math, Simulation, Combinatorics | 257 | 100.00
1875+
| 2220 |[Minimum Bit Flips to Convert Number](src/main/kotlin/g2201_2300/s2220_minimum_bit_flips_to_convert_number/Solution.kt)| Easy | Bit_Manipulation | 131 | 70.59
1876+
| 2218 |[Maximum Value of K Coins From Piles](src/main/kotlin/g2201_2300/s2218_maximum_value_of_k_coins_from_piles/Solution.kt)| Hard | Array, Dynamic_Programming, Prefix_Sum | 313 | 100.00
1877+
| 2217 |[Find Palindrome With Fixed Length](src/main/kotlin/g2201_2300/s2217_find_palindrome_with_fixed_length/Solution.kt)| Medium | Array, Math | 541 | 100.00
1878+
| 2216 |[Minimum Deletions to Make Array Beautiful](src/main/kotlin/g2201_2300/s2216_minimum_deletions_to_make_array_beautiful/Solution.kt)| Medium | Array, Greedy, Stack | 567 | 66.67
1879+
| 2215 |[Find the Difference of Two Arrays](src/main/kotlin/g2201_2300/s2215_find_the_difference_of_two_arrays/Solution.kt)| Easy | Array, Hash_Table | 352 | 98.63
1880+
| 2213 |[Longest Substring of One Repeating Character](src/main/kotlin/g2201_2300/s2213_longest_substring_of_one_repeating_character/Solution.kt)| Hard | Array, String, Ordered_Set, Segment_Tree | 879 | 100.00
1881+
| 2212 |[Maximum Points in an Archery Competition](src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition/Solution.kt)| Medium | Array, Bit_Manipulation, Recursion, Enumeration | 210 | 100.00
1882+
| 2211 |[Count Collisions on a Road](src/main/kotlin/g2201_2300/s2211_count_collisions_on_a_road/Solution.kt)| Medium | String, Stack | 325 | 100.00
1883+
| 2210 |[Count Hills and Valleys in an Array](src/main/kotlin/g2201_2300/s2210_count_hills_and_valleys_in_an_array/Solution.kt)| Easy | Array | 153 | 80.00
1884+
| 2209 |[Minimum White Tiles After Covering With Carpets](src/main/kotlin/g2201_2300/s2209_minimum_white_tiles_after_covering_with_carpets/Solution.kt)| Hard | String, Dynamic_Programming, Prefix_Sum | 373 | 100.00
1885+
| 2208 |[Minimum Operations to Halve Array Sum](src/main/kotlin/g2201_2300/s2208_minimum_operations_to_halve_array_sum/Solution.kt)| Medium | Array, Greedy, Heap_Priority_Queue | 628 | 33.33
1886+
| 2207 |[Maximize Number of Subsequences in a String](src/main/kotlin/g2201_2300/s2207_maximize_number_of_subsequences_in_a_string/Solution.kt)| Medium | String, Greedy, Prefix_Sum | 295 | 100.00
1887+
| 2206 |[Divide Array Into Equal Pairs](src/main/kotlin/g2201_2300/s2206_divide_array_into_equal_pairs/Solution.kt)| Easy | Array, Hash_Table, Bit_Manipulation, Counting | 221 | 71.43
1888+
| 2203 |[Minimum Weighted Subgraph With the Required Paths](src/main/kotlin/g2201_2300/s2203_minimum_weighted_subgraph_with_the_required_paths/Solution.kt)| Hard | Graph, Shortest_Path | 1126 | 100.00
1889+
| 2202 |[Maximize the Topmost Element After K Moves](src/main/kotlin/g2201_2300/s2202_maximize_the_topmost_element_after_k_moves/Solution.kt)| Medium | Array, Greedy | 491 | 50.00
1890+
| 2201 |[Count Artifacts That Can Be Extracted](src/main/kotlin/g2201_2300/s2201_count_artifacts_that_can_be_extracted/Solution.kt)| Medium | Array, Hash_Table, Simulation | 1011 | 100.00
18511891
| 2200 |[Find All K-Distant Indices in an Array](src/main/kotlin/g2101_2200/s2200_find_all_k_distant_indices_in_an_array/Solution.kt)| Easy | Array | 200 | 100.00
18521892
| 2197 |[Replace Non-Coprime Numbers in Array](src/main/kotlin/g2101_2200/s2197_replace_non_coprime_numbers_in_array/Solution.kt)| Hard | Array, Math, Stack, Number_Theory | 917 | 100.00
18531893
| 2196 |[Create Binary Tree From Descriptions](src/main/kotlin/g2101_2200/s2196_create_binary_tree_from_descriptions/Solution.kt)| Medium | Array, Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 933 | 100.00
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package g2201_2300.s2201_count_artifacts_that_can_be_extracted
2+
3+
// #Medium #Array #Hash_Table #Simulation
4+
// #2023_06_27_Time_1011_ms_(100.00%)_Space_108.8_MB_(100.00%)
5+
6+
class Solution {
7+
fun digArtifacts(n: Int, artifacts: Array<IntArray>, dig: Array<IntArray>): Int {
8+
val ar = Array(n) { IntArray(n) }
9+
for (ints in dig) {
10+
ar[ints[0]][ints[1]] = 1
11+
}
12+
var ans = 0
13+
for (artifact in artifacts) {
14+
val x1 = artifact[0]
15+
val y1 = artifact[1]
16+
val x2 = artifact[2]
17+
val y2 = artifact[3]
18+
var flag = 0
19+
var a = x1
20+
var b = y1
21+
while (a <= x2) {
22+
b = y1
23+
while (b <= y2) {
24+
if (ar[a][b] != 1) {
25+
flag = 1
26+
break
27+
}
28+
b++
29+
}
30+
if (flag == 1) {
31+
break
32+
}
33+
a++
34+
}
35+
if (a == x2 + 1 && b == y2 + 1) {
36+
ans++
37+
}
38+
}
39+
return ans
40+
}
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2201\. Count Artifacts That Can Be Extracted
2+
3+
Medium
4+
5+
There is an `n x n` **0-indexed** grid with some artifacts buried in it. You are given the integer `n` and a **0-indexed** 2D integer array `artifacts` describing the positions of the rectangular artifacts where <code>artifacts[i] = [r1<sub>i</sub>, c1<sub>i</sub>, r2<sub>i</sub>, c2<sub>i</sub>]</code> denotes that the <code>i<sup>th</sup></code> artifact is buried in the subgrid where:
6+
7+
* <code>(r1<sub>i</sub>, c1<sub>i</sub>)</code> is the coordinate of the **top-left** cell of the <code>i<sup>th</sup></code> artifact and
8+
* <code>(r2<sub>i</sub>, c2<sub>i</sub>)</code> is the coordinate of the **bottom-right** cell of the <code>i<sup>th</sup></code> artifact.
9+
10+
You will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.
11+
12+
Given a **0-indexed** 2D integer array `dig` where <code>dig[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> indicates that you will excavate the cell <code>(r<sub>i</sub>, c<sub>i</sub>)</code>, return _the number of artifacts that you can extract_.
13+
14+
The test cases are generated such that:
15+
16+
* No two artifacts overlap.
17+
* Each artifact only covers at most `4` cells.
18+
* The entries of `dig` are unique.
19+
20+
**Example 1:**
21+
22+
![](https://assets.leetcode.com/uploads/2019/09/16/untitled-diagram.jpg)
23+
24+
**Input:** n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]]
25+
26+
**Output:** 1
27+
28+
**Explanation:** The different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid. There is 1 artifact that can be extracted, namely the red artifact. The blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it. Thus, we return 1.
29+
30+
**Example 2:**
31+
32+
![](https://assets.leetcode.com/uploads/2019/09/16/untitled-diagram-1.jpg)
33+
34+
**Input:** n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]]
35+
36+
**Output:** 2
37+
38+
**Explanation:** Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2.
39+
40+
**Constraints:**
41+
42+
* `1 <= n <= 1000`
43+
* <code>1 <= artifacts.length, dig.length <= min(n<sup>2</sup>, 10<sup>5</sup>)</code>
44+
* `artifacts[i].length == 4`
45+
* `dig[i].length == 2`
46+
* <code>0 <= r1<sub>i</sub>, c1<sub>i</sub>, r2<sub>i</sub>, c2<sub>i</sub>, r<sub>i</sub>, c<sub>i</sub> <= n - 1</code>
47+
* <code>r1<sub>i</sub> <= r2<sub>i</sub></code>
48+
* <code>c1<sub>i</sub> <= c2<sub>i</sub></code>
49+
* No two artifacts will overlap.
50+
* The number of cells covered by an artifact is **at most** `4`.
51+
* The entries of `dig` are unique.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package g2201_2300.s2202_maximize_the_topmost_element_after_k_moves
2+
3+
// #Medium #Array #Greedy #2023_06_27_Time_491_ms_(50.00%)_Space_58_MB_(100.00%)
4+
5+
class Solution {
6+
fun maximumTop(nums: IntArray, k: Int): Int {
7+
var max = -1
8+
val maxTravers = Math.min(k + 1, nums.size)
9+
if (nums.size == 1) {
10+
return if (k % 2 == 0) {
11+
nums[0]
12+
} else {
13+
max
14+
}
15+
}
16+
for (i in 0 until maxTravers) {
17+
if (nums[i] > max && i != k - 1) {
18+
max = nums[i]
19+
}
20+
}
21+
return max
22+
}
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2202\. Maximize the Topmost Element After K Moves
2+
3+
Medium
4+
5+
You are given a **0-indexed** integer array `nums` representing the contents of a **pile**, where `nums[0]` is the topmost element of the pile.
6+
7+
In one move, you can perform **either** of the following:
8+
9+
* If the pile is not empty, **remove** the topmost element of the pile.
10+
* If there are one or more removed elements, **add** any one of them back onto the pile. This element becomes the new topmost element.
11+
12+
You are also given an integer `k`, which denotes the total number of moves to be made.
13+
14+
Return _the **maximum value** of the topmost element of the pile possible after **exactly**_ `k` _moves_. In case it is not possible to obtain a non-empty pile after `k` moves, return `-1`.
15+
16+
**Example 1:**
17+
18+
**Input:** nums = [5,2,2,4,0,6], k = 4
19+
20+
**Output:** 5
21+
22+
**Explanation:**
23+
24+
One of the ways we can end with 5 at the top of the pile after 4 moves is as follows:
25+
26+
- Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].
27+
28+
- Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].
29+
30+
- Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].
31+
32+
- Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].
33+
34+
Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.
35+
36+
**Example 2:**
37+
38+
**Input:** nums = [2], k = 1
39+
40+
**Output:** -1
41+
42+
**Explanation:**
43+
44+
In the first move, our only option is to pop the topmost element of the pile.
45+
46+
Since it is not possible to obtain a non-empty pile after one move, we return -1.
47+
48+
**Constraints:**
49+
50+
* <code>1 <= nums.length <= 10<sup>5</sup></code>
51+
* <code>0 <= nums[i], k <= 10<sup>9</sup></code>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package g2201_2300.s2203_minimum_weighted_subgraph_with_the_required_paths
2+
3+
// #Hard #Graph #Shortest_Path #2023_06_27_Time_1126_ms_(100.00%)_Space_127.2_MB_(100.00%)
4+
5+
import java.util.PriorityQueue
6+
import java.util.Queue
7+
8+
class Solution {
9+
fun minimumWeight(n: Int, edges: Array<IntArray>, src1: Int, src2: Int, dest: Int): Long {
10+
val graph: Array<MutableList<IntArray>?> = arrayOfNulls(n)
11+
val weight = Array(3) { LongArray(n) }
12+
for (i in 0 until n) {
13+
for (j in 0..2) {
14+
weight[j][i] = Long.MAX_VALUE
15+
}
16+
graph[i] = ArrayList()
17+
}
18+
for (e in edges) {
19+
graph[e[0]]?.add(intArrayOf(e[1], e[2]))
20+
}
21+
val queue: Queue<Node> = PriorityQueue({ node1: Node, node2: Node -> node1.weight.compareTo(node2.weight) })
22+
queue.offer(Node(0, src1, 0))
23+
weight[0][src1] = 0
24+
queue.offer(Node(1, src2, 0))
25+
weight[1][src2] = 0
26+
while (queue.isNotEmpty()) {
27+
val curr = queue.poll()
28+
if (curr.vertex == dest && curr.index == 2) {
29+
return curr.weight
30+
}
31+
for (next in graph[curr.vertex]!!) {
32+
if (curr.index == 2 && weight[curr.index][next[0]] > curr.weight + next[1]) {
33+
weight[curr.index][next[0]] = curr.weight + next[1]
34+
queue.offer(Node(curr.index, next[0], weight[curr.index][next[0]]))
35+
} else if (weight[curr.index][next[0]] > curr.weight + next[1]) {
36+
weight[curr.index][next[0]] = curr.weight + next[1]
37+
queue.offer(Node(curr.index, next[0], weight[curr.index][next[0]]))
38+
if (weight[curr.index xor 1][next[0]] != Long.MAX_VALUE &&
39+
weight[curr.index][next[0]] + weight[curr.index xor 1][next[0]]
40+
< weight[2][next[0]]
41+
) {
42+
weight[2][next[0]] = weight[curr.index][next[0]] + weight[curr.index xor 1][next[0]]
43+
queue.offer(Node(2, next[0], weight[2][next[0]]))
44+
}
45+
}
46+
}
47+
}
48+
return -1
49+
}
50+
51+
private class Node(var index: Int, var vertex: Int, var weight: Long)
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2203\. Minimum Weighted Subgraph With the Required Paths
2+
3+
Hard
4+
5+
You are given an integer `n` denoting the number of nodes of a **weighted directed** graph. The nodes are numbered from `0` to `n - 1`.
6+
7+
You are also given a 2D integer array `edges` where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> denotes that there exists a **directed** edge from <code>from<sub>i</sub></code> to <code>to<sub>i</sub></code> with weight <code>weight<sub>i</sub></code>.
8+
9+
Lastly, you are given three **distinct** integers `src1`, `src2`, and `dest` denoting three distinct nodes of the graph.
10+
11+
Return _the **minimum weight** of a subgraph of the graph such that it is **possible** to reach_ `dest` _from both_ `src1` _and_ `src2` _via a set of edges of this subgraph_. In case such a subgraph does not exist, return `-1`.
12+
13+
A **subgraph** is a graph whose vertices and edges are subsets of the original graph. The **weight** of a subgraph is the sum of weights of its constituent edges.
14+
15+
**Example 1:**
16+
17+
![](https://assets.leetcode.com/uploads/2022/02/17/example1drawio.png)
18+
19+
**Input:** n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5
20+
21+
**Output:** 9
22+
23+
**Explanation:** The above figure represents the input graph. The blue edges represent one of the subgraphs that yield the optimal answer. Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.
24+
25+
**Example 2:**
26+
27+
![](https://assets.leetcode.com/uploads/2022/02/17/example2-1drawio.png)
28+
29+
**Input:** n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2
30+
31+
**Output:** -1
32+
33+
**Explanation:** The above figure represents the input graph. It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints.
34+
35+
**Constraints:**
36+
37+
* <code>3 <= n <= 10<sup>5</sup></code>
38+
* <code>0 <= edges.length <= 10<sup>5</sup></code>
39+
* `edges[i].length == 3`
40+
* <code>0 <= from<sub>i</sub>, to<sub>i</sub>, src1, src2, dest <= n - 1</code>
41+
* <code>from<sub>i</sub> != to<sub>i</sub></code>
42+
* `src1`, `src2`, and `dest` are pairwise distinct.
43+
* <code>1 <= weight[i] <= 10<sup>5</sup></code>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package g2201_2300.s2206_divide_array_into_equal_pairs
2+
3+
// #Easy #Array #Hash_Table #Bit_Manipulation #Counting
4+
// #2023_06_27_Time_221_ms_(71.43%)_Space_37.6_MB_(85.71%)
5+
6+
class Solution {
7+
fun divideArray(nums: IntArray): Boolean {
8+
val freq = IntArray(501)
9+
for (num in nums) {
10+
++freq[num]
11+
}
12+
for (f in freq) {
13+
if (f % 2 != 0) {
14+
return false
15+
}
16+
}
17+
return true
18+
}
19+
}

0 commit comments

Comments
 (0)