Sum of All Subset XOR Totals

class Solution:
def subsetXORSum(self, nums: List[int]) -> int:
length = len(nums)
result=0
for i in range(2**length):
binary = bin(i)[2:]
if(len(binary)<length):
binary = ((length-len(binary))*"0")+binary
xor_=0
for i in range(len(binary)):
if binary[i]=="1":
xor_^=nums[i]
result+=xor_
return(result)
class Solution:
def subsetXORSum(self, nums: List[int]) -> int:
length = len(nums)
result=0
for i in range(1<<length):
xor_=0
for j in range(length):
if( i & 1<<j !=0 ):
xor_^=nums[j]
result+=xor_
return(result)
class Solution:
def subsetXORSum(self, nums: List[int]) -> int:
total,length=0,len(nums)
for i in nums:
total|=i
return(2**(length-1)*total)

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Getting Started with Augmented Reality: A Beginner’s Guide.

How to test Clojure systems using different seam techniques

Balanced Spawning

ELT Architecture in the Azure Cloud

Installation of Django & Creating a Project

Vulnhub: Vegeta 1.0

Exploring Spark Structured Streaming

image01

Java UUID generation — Performance impact

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

Developer Interview Series by Silen Audio: Erik Rempen Discusses Kainga

Touch Technology : History of becoming

what we see today from pinch to zoom to scroll to haptic

How I landed my Target SWE Internship — A Year in Advance

ARTS Week 26