Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd37d58

Browse files
feat: add biweekly contest 131 (doocs#2915)
1 parent fb0d7dd commit bd37d58

File tree

16 files changed

+886
-0
lines changed

16 files changed

+886
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3158. 求出出现两次数字的 XOR 值](https://leetcode.cn/problems/find-the-xor-of-numbers-which-appear-twice)
10+
11+
[English Version](/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个数组&nbsp;<code>nums</code>&nbsp;,数组中的数字 <strong>要么</strong> 出现一次,<strong>要么</strong>&nbsp;出现两次。</p>
18+
19+
<p>请你返回数组中所有出现两次数字的按位<em>&nbsp;</em><code>XOR</code>&nbsp;值,如果没有数字出现过两次,返回 0 。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<div class="example-block">
26+
<p><span class="example-io"><b>输入:</b>nums = [1,2,1,3]</span></p>
27+
28+
<p><span class="example-io"><b>输出:</b>1</span></p>
29+
30+
<p><strong>解释:</strong></p>
31+
32+
<p><code>nums</code>&nbsp;中唯一出现过两次的数字是 1 。</p>
33+
</div>
34+
35+
<p><strong class="example">示例 2:</strong></p>
36+
37+
<div class="example-block">
38+
<p><span class="example-io"><b>输入:</b>nums = [1,2,3]</span></p>
39+
40+
<p><span class="example-io"><b>输出:</b>0</span></p>
41+
42+
<p><strong>解释:</strong></p>
43+
44+
<p><code>nums</code>&nbsp;中没有数字出现两次。</p>
45+
</div>
46+
47+
<p><strong class="example">示例 3:</strong></p>
48+
49+
<div class="example-block">
50+
<p><span class="example-io"><b>输入:</b>nums = [1,2,2,1]</span></p>
51+
52+
<p><span class="example-io"><b>输出:</b>3</span></p>
53+
54+
<p><strong>解释:</strong></p>
55+
56+
<p>数字 1 和&nbsp;2 出现过两次。<code>1 XOR 2 == 3</code>&nbsp;。</p>
57+
</div>
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>提示:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
65+
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
66+
<li><code>nums</code>&nbsp;中每个数字要么出现过一次,要么出现过两次。</li>
67+
</ul>
68+
69+
<!-- description:end -->
70+
71+
## 解法
72+
73+
<!-- solution:start -->
74+
75+
### 方法一
76+
77+
<!-- tabs:start -->
78+
79+
#### Python3
80+
81+
```python
82+
83+
```
84+
85+
#### Java
86+
87+
```java
88+
89+
```
90+
91+
#### C++
92+
93+
```cpp
94+
95+
```
96+
97+
#### Go
98+
99+
```go
100+
101+
```
102+
103+
<!-- tabs:end -->
104+
105+
<!-- solution:end -->
106+
107+
<!-- problem:end -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3158. Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice)
10+
11+
[中文文档](/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an array <code>nums</code>, where each number in the array appears <strong>either</strong><em> </em>once<em> </em>or<em> </em>twice.</p>
18+
19+
<p>Return the bitwise<em> </em><code>XOR</code> of all the numbers that appear twice in the array, or 0 if no number appears twice.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<div class="example-block">
25+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,3]</span></p>
26+
27+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
28+
29+
<p><strong>Explanation:</strong></p>
30+
31+
<p>The only number that appears twice in&nbsp;<code>nums</code>&nbsp;is 1.</p>
32+
</div>
33+
34+
<p><strong class="example">Example 2:</strong></p>
35+
36+
<div class="example-block">
37+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p>
38+
39+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
40+
41+
<p><strong>Explanation:</strong></p>
42+
43+
<p>No number appears twice in&nbsp;<code>nums</code>.</p>
44+
</div>
45+
46+
<p><strong class="example">Example 3:</strong></p>
47+
48+
<div class="example-block">
49+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,2,1]</span></p>
50+
51+
<p><strong>Output:</strong> <span class="example-io">3</span></p>
52+
53+
<p><strong>Explanation:</strong></p>
54+
55+
<p>Numbers 1 and 2 appeared twice. <code>1 XOR 2 == 3</code>.</p>
56+
</div>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
63+
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
64+
<li>Each number in <code>nums</code> appears either once or twice.</li>
65+
</ul>
66+
67+
<!-- description:end -->
68+
69+
## Solutions
70+
71+
<!-- solution:start -->
72+
73+
### Solution 1
74+
75+
<!-- tabs:start -->
76+
77+
#### Python3
78+
79+
```python
80+
81+
```
82+
83+
#### Java
84+
85+
```java
86+
87+
```
88+
89+
#### C++
90+
91+
```cpp
92+
93+
```
94+
95+
#### Go
96+
97+
```go
98+
99+
```
100+
101+
<!-- tabs:end -->
102+
103+
<!-- solution:end -->
104+
105+
<!-- problem:end -->
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3159.Find%20Occurrences%20of%20an%20Element%20in%20an%20Array/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3159. 查询数组中元素的出现位置](https://leetcode.cn/problems/find-occurrences-of-an-element-in-an-array)
10+
11+
[English Version](/solution/3100-3199/3159.Find%20Occurrences%20of%20an%20Element%20in%20an%20Array/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,一个整数数组&nbsp;<code>queries</code>&nbsp;和一个整数&nbsp;<code>x</code>&nbsp;。</p>
18+
19+
<p>对于每个查询&nbsp;<code>queries[i]</code>&nbsp;,你需要找到&nbsp;<code>nums</code>&nbsp;中第&nbsp;<code>queries[i]</code>&nbsp;&nbsp;<code>x</code>&nbsp;的位置,并返回它的下标。如果数组中&nbsp;<code>x</code>&nbsp;的出现次数少于&nbsp;<code>queries[i]</code>&nbsp;,该查询的答案为 -1 。</p>
20+
21+
<p>请你返回一个整数数组&nbsp;<code>answer</code>&nbsp;,包含所有查询的答案。</p>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong class="example">示例 1:</strong></p>
26+
27+
<div class="example-block">
28+
<p><span class="example-io"><b>输入:</b>nums = [1,3,1,7], queries = [1,3,2,4], x = 1</span></p>
29+
30+
<p><span class="example-io"><b>输出:</b>[0,-1,2,-1]</span></p>
31+
32+
<p><strong>解释:</strong></p>
33+
34+
<ul>
35+
<li>第 1 个查询,第一个 1 出现在下标 0 处。</li>
36+
<li>第 2 个查询,<code>nums</code>&nbsp;中只有两个 1 ,所以答案为 -1 。</li>
37+
<li>第 3 个查询,第二个 1 出现在下标 2 处。</li>
38+
<li>第 4 个查询,<code>nums</code>&nbsp;中只有两个 1 ,所以答案为 -1 。</li>
39+
</ul>
40+
</div>
41+
42+
<p><strong class="example">示例 2:</strong></p>
43+
44+
<div class="example-block">
45+
<p><span class="example-io"><b>输入:</b>nums = [1,2,3], queries = [10], x = 5</span></p>
46+
47+
<p><span class="example-io"><b>输出:</b>[-1]</span></p>
48+
49+
<p><strong>解释:</strong></p>
50+
51+
<ul>
52+
<li>第 1 个查询,<code>nums</code>&nbsp;中没有 5 ,所以答案为 -1 。</li>
53+
</ul>
54+
</div>
55+
56+
<p>&nbsp;</p>
57+
58+
<p><strong>提示:</strong></p>
59+
60+
<ul>
61+
<li><code>1 &lt;= nums.length, queries.length &lt;= 10<sup>5</sup></code></li>
62+
<li><code>1 &lt;= queries[i] &lt;= 10<sup>5</sup></code></li>
63+
<li><code>1 &lt;= nums[i], x &lt;= 10<sup>4</sup></code></li>
64+
</ul>
65+
66+
<!-- description:end -->
67+
68+
## 解法
69+
70+
<!-- solution:start -->
71+
72+
### 方法一
73+
74+
<!-- tabs:start -->
75+
76+
#### Python3
77+
78+
```python
79+
80+
```
81+
82+
#### Java
83+
84+
```java
85+
86+
```
87+
88+
#### C++
89+
90+
```cpp
91+
92+
```
93+
94+
#### Go
95+
96+
```go
97+
98+
```
99+
100+
<!-- tabs:end -->
101+
102+
<!-- solution:end -->
103+
104+
<!-- problem:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /