Given an N bit binary number, find the 1's complement of the number. The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa).
 
Example 1:
Input:
N = 3
S = 101
Output:
010
Explanation:
We get the output by converting 1's in S
to 0 and 0s to 1
Example 2:
Input:
N = 2
S = 10
Output:
01
Explanation:
We get the output by converting 1's in S
to 0 and 0s to 1
Your Task:  
You don't need to read input or print anything. Your task is to complete the function onesComplement() which takes the binary string S, its size N as input parameters and returns 1's complement of S of size N.
 
Expected Time Complexity: O(N)
Expected Space Complexity: O(N)
 
Constraints:
1<=N<=100

Difficulty: EASY
Tags: Bit manipulation

Data structures
Skill types: Bit manipulation

Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3
class Solution:
    def onesComplement(self,S,N):
        # code here

Solutions:
class Solution:

	def onesComplement(self, S, N):
		i = 0
		res = ''
		for ec in S:
			if ec == '0':
				res = res + '1'
			else:
				res = res + '0'
		l1 = len(res)
		l2 = N
		if l2 != l1:
			diff = l2 - l1
			for i in range(diff):
				res = res + '0'
		return res


class Solution:

	def onesComplement(self, S, N):
		b = ''
		for i in str(S):
			if int(i) == 0:
				b += '1'
			else:
				b += '0'
		return b


class Solution:

	def onesComplement(self, S, N):
		S = str(S)
		li = []
		for i in S:
			if i == '1':
				li.append('0')
			else:
				li.append('1')
		return ''.join(li)


class Solution:

	def onesComplement(self, S, N):
		return S.replace('1', '#').replace('0', '1').replace('#', '0')


class Solution:

	def onesComplement(self, S, N):
		S = str(S)
		return S.replace('0', 'Y').replace('1', '0').replace('Y', '1')


class Solution:

	def onesComplement(self, S, N):
		answer = ''
		for i in range(N):
			if S[i] == '1':
				answer += '0'
			else:
				answer += '1'
		return answer


class Solution:

	def onesComplement(self, S, N):
		resultado = ''
		for i in range(0, N):
			resultado += str(1 - int(S[i]))
		return resultado


class Solution:

	def onesComplement(self, S, N):
		d = ''
		for i in S:
			if i == '0':
				d += '1'
			else:
				d += '0'
		return d


class Solution:

	def onesComplement(self, S, N):
		temp_S = []
		for i in str(S):
			if i == '0':
				temp_S.append('1')
			elif i == '1':
				temp_S.append('0')
		return ''.join(temp_S)


class Solution:

	def onesComplement(self, S, N):
		comp = ''
		d = len(S) - N
		for ch in S:
			if ch == '1':
				comp += '0'
			else:
				comp += '1'
		return comp


class Solution:

	def onesComplement(self, S, N):
		k = ''
		for i in range(N):
			if S[i] == '1':
				k += '0'
			else:
				k += '1'


class Solution:

	def onesComplement(self, S, N):
		a = list(str(S))
		for x in range(0, len(a)):
			if a[x] == '0':
				a[x] = '1'
			else:
				a[x] = '0'
		return ''.join(a)


class Solution:

	def onesComplement(self, S, N):
		S = list(S)
		for i in range(len(S)):
			if S[i] == '1':
				S[i] = '0'
			else:
				S[i] = '1'
		return ''.join(S)


class Solution:

	def onesComplement(self, s, n):
		s = str(s)
		p = ''
		for i in s:
			if i == '0':
				p += '1'
			elif i == '1':
				p += '0'
		return p


class Solution:

	def onesComplement(self, S, N):
		S = S.replace('0', 'a')
		S = S.replace('1', 'b')
		S = S.replace('a', '1')
		S = S.replace('b', '0')
		return S


class Solution:

	def onesComplement(self, S, N):
		return ''.join(('0' if num == '1' else '1' for num in S))


class Solution:

	def onesComplement(self, S, N):
		s = ['1' if c == '0' else '0' for c in S]
		return ''.join(s)


class Solution:

	def onesComplement(self, S, N):
		ans = ''
		for i in S:
			if int(i) == 1:
				ans += str(0)
			elif int(i) == 0:
				ans += str(1)
		return ans


class Solution:

	def onesComplement(self, S, N):
		n = ''
		for i in S:
			if i == '1':
				n = n + '0'
			elif i == '0':
				n += '1'
		return n


class Solution:

	def onesComplement(self, S, N):
		ans = ''
		i = 0
		while i < N:
			if S[i] == '0':
				ans += '1'
			elif S[i] == '1':
				ans += '0'
			i += 1
		return ans


class Solution:

	def onesComplement(self, S, N):
		return ''.join(list(map(lambda x: '0' if x == '1' else '1', list(S))))


class Solution:

	def onesComplement(self, S, N):
		ans = S.translate(str.maketrans('10', '01'))
		return ans


class Solution:

	def onesComplement(self, S, N):
		ss = ''
		for i in range(N):
			if S[i] == str(1):
				ss = ss + str(0)
			else:
				ss = ss + str(1)
		return ss


class Solution:

	def onesComplement(self, S, N):
		k = S.replace('0', '2')
		k1 = k.replace('1', '0')
		k2 = k1.replace('2', '1')
		return k2


class Solution:

	def onesComplement(self, s, n):
		vk = ''
		for i in range(n):
			if s[i] == '1':
				vk += '0'
			else:
				vk += '1'
		return vk


class Solution:

	def onesComplement(self, S, N):
		res = ''
		for c in S:
			if c == '1':
				res += '0'
			else:
				res += '1'
		return res


class Solution:

	def onesComplement(self, S, N):
		l = list(S)
		lst = []
		for i in range(N):
			if l[i] == '0':
				lst.append(1)
			if l[i] == '1':
				lst.append(0)
		c = ''
		for j in lst:
			c = c + str(j)
		return c


class Solution:

	def onesComplement(self, S, N):
		m = ''
		b = list(S)
		for i in b:
			if i == '1':
				m += '0'
			else:
				m += '1'
		return m


from math import *

class Solution:

	def onesComplement(self, S, N):
		d = ''
		for i in S:
			if i == '1':
				d += str(0)
			else:
				d += str(1)
		return d


class Solution:

	def onesComplement(self, S, N):
		k = ''
		for _ in str(S):
			if _ == '1':
				k += '0'
			else:
				k += '1'
		return k


class Solution:

	def onesComplement(self, S, N):
		s = 0
		j = 0
		for i in range(len(S) - 1, -1, -1):
			s += 2 ** i * int(S[j])
			j += 1
		k = s ^ 2 ** N - 1
		k = bin(k)
		k = k[2:]
		return k.zfill(N)


class Solution:

	def onesComplement(self, S, N):
		p = ''
		for i in str(S):
			if i == '0':
				p += str(1)
			else:
				p += str(0)
		return p


class Solution:

	def onesComplement(self, S, N):
		new = ''
		for i in range(0, N):
			if S[i] == '1':
				new = new + '0'
			elif S[i] == '0':
				new = new + '1'
		return new


class Solution:

	def onesComplement(self, S, N):
		return ''.join([str(1 - int(x)) for x in S])


class Solution:

	def onesComplement(self, S, N):
		c = []
		for i in S:
			if i == '1':
				c.append(0)
			else:
				c.append(1)
		d = [str(int) for int in c]
		d = ''.join(d)
		return d


class Solution:

	def onesComplement(self, s, N):
		r = ''
		for i in s:
			if i == '0':
				r += '1'
			else:
				r += '0'
		return r


class Solution:

	def onesComplement(self, S, N):
		s = ''
		for x in S:
			if x == '0':
				s += '1'
			else:
				s += '0'
		return s


class Solution:

	def onesComplement(self, S, N):
		l = list(S)
		for i in range(N):
			if l[i] == '1':
				l[i] = '0'
			elif l[i] == '0':
				l[i] = '1'
		S = ''.join(l)
		return S


class Solution:

	def onesComplement(self, S, N):
		s = S.replace('0', '2')
		s = s.replace('1', '0')
		s = s.replace('2', '1')
		return s


class Solution:

	def onesComplement(self, S, N):
		s = ''
		n = len(S)
		for i in range(n):
			if S[i] == '0':
				s += '1'
			else:
				s += '0'
		return s