MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / xorQueries

Function xorQueries

xor_queries_of_a_subarray_1310/solution.go:3–22  ·  view source on GitHub ↗
(arr []int, queries [][]int)

Source from the content-addressed store, hash-verified

1package xor_queries_of_a_subarray_1310
2
3func xorQueries(arr []int, queries [][]int) []int {
4 res := make([]int, len(queries))
5 for idx, q := range queries {
6 j := q[0]
7 k := q[1]
8 if j == k {
9 res[idx] = arr[j]
10 continue
11 }
12
13 val := 0
14 for j <= k {
15 val ^= arr[j]
16 j++
17 }
18 res[idx] = val
19 }
20
21 return res
22}

Callers 1

Test_xorQueriesFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_xorQueriesFunction · 0.68