思路
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1e5 + 10; int tr[maxn * 32][2], cnt; int n; int val[maxn]; void add(int x){ int cur = 0; for(int i = 30; i >= 0; i--){ int f = (x >> i) & 1; if(!tr[cur][f]) tr[cur][f] = ++cnt; cur = tr[cur][f]; } } int query(int x){ int cur = 0, ans = 0; for(int i = 30; i >= 0; i--){ int f = (x >> i) & 1; f ^= 1; if(!tr[cur][f]) f ^= 1; else ans += 1 << i; cur = tr[cur][f]; } return ans; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", &val[i]); add(val[i]); } int ans = 0; for(int i = 1; i <= n; i++){ ans = max(ans, query(val[i])); } printf("%d\n", ans); return 0; }