Post

leetcode(리트코드)-1863 Sum of All Subset XOR Totals(python)

leetcode 1863 - Sum of All Subset XOR Totals 문제입니다.

1. 문제

https://leetcode.com/problems/sum-of-all-subset-xor-totals/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.


4. 문제 해석

  • nums의 모든 요소들끼리 XOR를 한 결과를 더해 리턴합니다.
  • 재귀연습하기에 좋습니다. 재귀모르면.. 어케풀지?
  • 어려워서 2주일 뒤에 다시 풀었습니다.

5. code

코드설명

python

1
2
3
4
5
6
7
8
9
class Solution:
    def subsetXORSum(self, nums: List[int]) -> int:
        def sums(term,idx):
            if idx == len(nums) : 
                return term
            return sums(term,idx+1) + sums(term ^ nums[idx],idx+1)
        return sums(0,0)
        
            

6. 결과 및 후기, 개선점

필요시 c++로 짜드리겠습니다.

This post is licensed under CC BY 4.0 by the author.