diff --git a/solution/3500-3599/3595.Once Twice/README.md b/solution/3500-3599/3595.Once Twice/README.md new file mode 100644 index 0000000000000..9aafeab8453e5 --- /dev/null +++ b/solution/3500-3599/3595.Once Twice/README.md @@ -0,0 +1,110 @@ +--- +comments: true +difficulty: 中等 +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3595.Once%20Twice/README.md +--- + + + +# [3595. 一次或两次 🔒](https://leetcode.cn/problems/once-twice) + +[English Version](/solution/3500-3599/3595.Once%20Twice/README_EN.md) + +## 题目描述 + + + +

给定一个整数数组 nums。在这个数组中:

+ + + +

返回一个长度为 2 的整数数组,其中第一个元素是只出现 1 次 的那个元素,第二个元素是只出现 2 次 的那个元素。

+ +

你的解决方案必须在 O(n) 时间 与 O(1) 空间中运行。

+ +

 

+ +

示例 1:

+ +
+

输入:nums = [2,2,3,2,5,5,5,7,7]

+ +

输出:[3,7]

+ +

解释:

+ +

元素 3 出现了 1 次,元素 7 出现了 2 次。其余所有元素都出现了 3 次

+
+ +

示例 2:

+ +
+

输入:nums = [4,4,6,4,9,9,9,6,8]

+ +

输出:[8,6]

+ +

解释:

+ +

元素 8 出现了 1 次,元素 6 出现了 2 次。其余所有元素都出现了 3 次

+
+ +

 

+ +

提示:

+ + + + + +## 解法 + + + +### 方法一 + + + +#### Python3 + +```python + +``` + +#### Java + +```java + +``` + +#### C++ + +```cpp + +``` + +#### Go + +```go + +``` + + + + + + diff --git a/solution/3500-3599/3595.Once Twice/README_EN.md b/solution/3500-3599/3595.Once Twice/README_EN.md new file mode 100644 index 0000000000000..1231be24e6089 --- /dev/null +++ b/solution/3500-3599/3595.Once Twice/README_EN.md @@ -0,0 +1,108 @@ +--- +comments: true +difficulty: Medium +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3595.Once%20Twice/README_EN.md +--- + + + +# [3595. Once Twice 🔒](https://leetcode.com/problems/once-twice) + +[中文文档](/solution/3500-3599/3595.Once%20Twice/README.md) + +## Description + + + +

You are given an integer array nums. In this array:

+ + + +

Return an integer array of length 2, where the first element is the one that appears once, and the second is the one that appears twice.

+ +

Your solution must run in O(n) time and O(1) space.

+ +

 

+

Example 1:

+ +
+

Input: nums = [2,2,3,2,5,5,5,7,7]

+ +

Output: [3,7]

+ +

Explanation:

+ +

The element 3 appears once, and the element 7 appears twice. The remaining elements each appear three times.

+
+ +

Example 2:

+ +
+

Input: nums = [4,4,6,4,9,9,9,6,8]

+ +

Output: [8,6]

+ +

Explanation:

+ +

The element 8 appears once, and the element 6 appears twice. The remaining elements each appear three times.

+
+ +

 

+

Constraints:

+ + + + + +## Solutions + + + +### Solution 1 + + + +#### Python3 + +```python + +``` + +#### Java + +```java + +``` + +#### C++ + +```cpp + +``` + +#### Go + +```go + +``` + + + + + + diff --git a/solution/README.md b/solution/README.md index a424a1f14980e..ae9226b1539b9 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3605,6 +3605,7 @@ | 3592 | [硬币面值还原](/solution/3500-3599/3592.Inverse%20Coin%20Change/README.md) | | 中等 | 第 455 场周赛 | | 3593 | [使叶子路径成本相等的最小增量](/solution/3500-3599/3593.Minimum%20Increments%20to%20Equalize%20Leaf%20Paths/README.md) | | 中等 | 第 455 场周赛 | | 3594 | [所有人渡河所需的最短时间](/solution/3500-3599/3594.Minimum%20Time%20to%20Transport%20All%20Individuals/README.md) | | 困难 | 第 455 场周赛 | +| 3595 | [一次或两次](/solution/3500-3599/3595.Once%20Twice/README.md) | | 中等 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index e1114669afb1c..92e75f34952de 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -3603,6 +3603,7 @@ Press Control + F(or Command + F on | 3592 | [Inverse Coin Change](/solution/3500-3599/3592.Inverse%20Coin%20Change/README_EN.md) | | Medium | Weekly Contest 455 | | 3593 | [Minimum Increments to Equalize Leaf Paths](/solution/3500-3599/3593.Minimum%20Increments%20to%20Equalize%20Leaf%20Paths/README_EN.md) | | Medium | Weekly Contest 455 | | 3594 | [Minimum Time to Transport All Individuals](/solution/3500-3599/3594.Minimum%20Time%20to%20Transport%20All%20Individuals/README_EN.md) | | Hard | Weekly Contest 455 | +| 3595 | [Once Twice](/solution/3500-3599/3595.Once%20Twice/README_EN.md) | | Medium | 🔒 | ## Copyright