Please help me understand where I'm going wrong


  • 0
    A

    EDIT: Well that was silly, had a typo where i was checking len(ans) not len(arr)...

    My solution was:

    def soln(arr):
      return helper(arr, 0)
    
    def helper(arr, idx):
      ans = [[]]
      if len(ans) == idx:
        ans.append([])
      else:
       ans = power_set(arr, idx+1)
       ans_cpy = ans
       for subset in ans_cpy:
        tmp = subset
        tmp.append(arr[idx])
        ans.append(tmp)
    return ans
    

    I seem to infinite loop in the for loop. Any idea why? What am I doing wrong? Help would be greatly appreciated.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.