@StefanPochmann Would it be really O(n) considering dictionary lookup (with could be O(n) in worst case itself)?
N
niksite
@niksite
11
Reputation
8
Posts
199
Profile views
0
Followers
0
Following
Posts made by niksite

RE: 12 lines Python

Python, two pointers, simple.
i = 1 for j in range(len(nums)): if nums[i1] != nums[j]: nums[i], nums[j] = nums[j], nums[i] i += 1 return len(nums[:i])

Simple and clear python solution.
For /subsets problem solution looks like the following:
nums.sort() res = [[]] for num in nums: res += [r + [num] for r in res] return res
Now we could have dups so it makes sense to just replace lists with sets:
nums.sort() res = {()} for num in nums: res = {r + (num,) for r in res} return list(res)
That's all.

RE: Python binary search solution  O(logn)  48ms
@eran there is no integer overflow in python

1line Python solution
class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ return sorted(set(itertools.permutations(nums)))

RE: Number of 1 Bits
In Python it could be pretty straightforward (still not so efficient) oneliner: bin(n).count('1')