GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/Bit_Manipulation/1734.Decode-XORed-Permutation at master · wisdompeak/LeetCode

Expand file tree

/

1734.Decode-XORed-Permutation

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

1734.Decode-XORed-Permutation

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1734.Decode-XORed-Permutation.cpp
1734.Decode-XORed-Permutation.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

1734.Decode-XORed-Permutation

我们知道,XOR的最常用的一个性质就是x^x=0,我们需要尽量使用这个性质。但是我们发现如果把encode里面的元素全部XOR起来,大多数元素都会被消除,得到的只是头尾值nums[0]^nums[n-1].

这时候我们注意到题目中说n是个奇数,这个条件很奇怪。仔细分析了一下,发现我们如果间隔着取encode里面的元素再XOR起来,就得到nohead = nums[1]^numx[2]^...^nums[n-1],只缺少了nums[0]而已.这时候我们果断想到全局的XOR Sum其实是已知的(因为题目说的是1到n的permutation)。将nohead与XORSum再亦或一下,就得到了nums[0]。于是nums[1]就可以从encode[0]^nums[0]得到,其余的nums[i]也就迎刃而解。

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.