Leetcode - Sort Array By Parity II (Python)

preview_player
Показать описание
September 2021 Leetcode Challenge
Leetcode - Sort Array By Parity II #922
Difficulty: Easy

*Sorry for the sniffling, not feeling 100%
Рекомендации по теме
Комментарии
Автор

Bro I have done this in kinda same logic. Finally I know nothing.

pritam
Автор

Finally we are getting a break this month!

janmichaelaustria
Автор

i have been selected as a Data Engineer, All thanks to your teaching style also, which software you use in data engineer profile

codeset
Автор

Can anyone tell me whats wrong with my logic :
class Solution:
def sortArrayByParityII(self, nums: List[int]) -> List[int]:
counter = 0
_dict_ = {'index':[], 'value':[]}
for x in range(len(nums)):
if x%2 != 0 and nums[x] % 2 == 0 or x%2 == 0 and nums[x] % 2 != 0:
counter += 1
_dict_['index'].append(x)

if counter % 2 == 0:
for i in
_dict_['index'][i], _dict_['index'][i+1] = _dict_['index'][i+1], _dict_['index'][i]
for x, y in zip(_dict_['index'], _dict_['value']):
nums[x] = y
return nums

sachinfulsunge
visit shbcf.ru