Skip to content

3513. Number of Unique XOR Triplets I 👍

  • Time: $O(\log n)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  int uniqueXorTriplets(vector<int>& nums) {
    const int n = nums.size();
    if (n < 3)
      return n;
    return 1 << (static_cast<int>(log2(n)) + 1);
  }
};
1
2
3
4
5
6
7
8
9
class Solution {
  public int uniqueXorTriplets(int[] nums) {
    final int n = nums.length;
    if (n < 3)
      return n;
    final int x = (int) (Math.log(n) / Math.log(2));
    return 1 << (x + 1);
  }
}
1
2
3
4
5
6
class Solution:
  def uniqueXorTriplets(self, nums: list[int]) -> int:
    n = len(nums)
    if n < 3:
      return n
    return 1 << (int(math.log2(n)) + 1)