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) _dict_['value'].append(nums[x]) if counter % 2 == 0: for i in range(len(_dict_['index'])-1): _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
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)
_dict_['value'].append(nums[x])
if counter % 2 == 0:
for i in range(len(_dict_['index'])-1):
_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
Bro I have done this in kinda same logic. Finally I know nothing.
Finally we are getting a break this month!
i have been selected as a Data Engineer, All thanks to your teaching style also, which software you use in data engineer profile