From 96900391887d344a0642bd6623f63e8aee9ce5ec Mon Sep 17 00:00:00 2001 From: gameloader Date: Thu, 30 May 2024 15:52:24 +0800 Subject: [PATCH] leetcode udpate --- content/posts/leetcode.md | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/content/posts/leetcode.md b/content/posts/leetcode.md index ebb85d1..f5b6e52 100644 --- a/content/posts/leetcode.md +++ b/content/posts/leetcode.md @@ -6603,3 +6603,47 @@ func numSteps(s string) int { ### 总结 本题直接从最后一位开始向前遍历, 遇到0直接将结果加1, 遇到1设定一个标记进位的标记变量为1, 同时将结果加2, 如此重复即可. 注意在每次判断当前位是0还是1之前要将原本的当前位值加上进位的标记变量再判断. + +## day94 2024-05-30 +### 1442. Count Triplets That Can Form Two Arrays of Equal XOR +Given an array of integers arr. + +We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). + +Let's define a and b as follows: + +a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1] +b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k] +Note that ^ denotes the bitwise-xor operation. + +Return the number of triplets (i, j and k) Where a == b. + +![0530uVcNw3JX4b49](https://testingcf.jsdelivr.net/gh/game-loader/picbase@master/uPic/0530uVcNw3JX4b49.png) + +### 题解 + +题目中要求i-j和j-k之间的数组元素全部异或后的值相等, 而i