avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

2527.Query arrayXorBeautiful value Zhou Sai Third Question

  2024-01-01        
字数统计: 267字   |   阅读时长: 1min

6289.Query array Xor Beautiful value。

This question has been studied for a long time,Discovering a mathematical problem,But I didn’t want to be transparent,Because unfamiliar or valuable。So there is no better solution。

The first is to read the question and learn(nums[i]|nums[j])&nums[k],becauseijkCan be any value in the array,So the tripleforcycle(It will definitely timeout),Then he was a little bit out of his own,Just a little bit,feeli,jThe value of the value is the same,So add an additional layer of judgment(Dictionary)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def xorBeauty(self, nums: List[int]) -> int:
ans = []
record = {}
for i in range(len(nums)):
for j in range(len(nums)):
for k in range(len(nums)):
if k not in record:
if (i,j) not in record.values():
record[k] = (i,j)
flag = (nums[i]|nums[j])&nums[k]
if flag not in ans:
ans.append(flag)
else:
ans.remove(flag)
if len(ans) == 0:
return 0
answer = ans[0]

for i in range(1,len(ans)):
answer ^= ans[i]
return answer

I have been thinking about how to judge the same situation when I go out today,As a result@Lingcha Mountain AifuSolution,One by one,That’s okay。

1
2
3
4
class Solution:
def xorBeauty(self, nums: List[int]) -> int:
return reduce(xor, nums)

Then do,Search online,It turns out that if the two values ​​are the same,for exampleA^B^A = B,Soappend,removeTo implement this function。at lastforcycle求异或值。

Big Big Code is still studyinging

  • Python
  • solved,answer

扫一扫,分享到微信

微信分享二维码
2335. The shortest total time to be filled with a cup One question daily
24.Two or two exchanges linked watches
目录
ahoh, this article has no catalog.

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号