topic:
2341. How much can the array be formed.md
Thought:
I am:
I don’t know if I saw it“Simple”Two words,This question has the initiative to think about the optimal solution。Actually this timeylbBig guy’s hash table method is still fast。
Sort the list,Whether two or two are equal to whether。
Hash tableThought:
CounterAfter counting,a+=v//2
,b+=v%2
For each number x,
if x Number of times v more than the 1,You can choose two from the array x Form a number pair,we willv Divide 2 Take down,
You can get the current number x Number pairs that can be formed,Then we accumulate this number to the variable s middle。
Code:
1 | class Solution: |
1 | class Solution: |