Leetcode - Sort Array By Parity II (Python)

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • September 2021 Leetcode Challenge
    Leetcode - Sort Array By Parity II #922
    Difficulty: Easy
    *Sorry for the sniffling, not feeling 100%

Komentáře • 4

  • @sachinfulsunge9977
    @sachinfulsunge9977 Před 2 lety

    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

  • @pritam1366
    @pritam1366 Před 2 lety +1

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

  • @janmichaelaustria620
    @janmichaelaustria620 Před 2 lety

    Finally we are getting a break this month!

  • @codeset7810
    @codeset7810 Před 2 lety

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