Skip to content

Commit daf4783

Browse files
committed
update: 添加问题“961.在长度2N的数组中找出重复N次的元素”的代码和题解(1commit) (#1298)
961: AC.cpp (#1297) 方法一.1:排序+相邻 cpp - AC,100.00%,89.42% py - AC,30.97%,96.34% go - AC,36.00%,64.00% java- AC,17.13%,5.06% rust- AC,100.00%,28.57% 方法一.1:排序+中间 cpp - AC,27.01%,90.69% py - AC,24.09%,96.99% go - AC,8.00%,56.00% java- AC,17.13%,5.06% rust- AC,100.00%,28.57% 方法二:哈希表 cpp - AC,100.00%,89.23% py - AC,100.00%,96.34% go - AC,100.00%,84.00% java- AC,78.65%,56.74% rust- AC,100.00%,100.00% 方法三:相隔或相邻 cpp - AC,100.00%,99.63% py - AC,100.00%,99.14% go - AC,100.00%,44.00% java- AC,100.00%,41.01% rust-AC,100.00%,42.86% 方法四:变种摩尔投票法 cpp - AC,100.00%,99.63% py - AC,38.92%,72.90% go - AC,100.00%,48.00% java- AC,44.94%,12.08% rust- AC,100.00%,100.00% 方法五:随机数 cpp - AC,100.00%,92.15% py - AC,50.54%,99.78% go - AC,100.00%,56.00% java- AC,78.65%,40.45% rust- AC,100.00%,28.57% Signed-off-by: LetMeFly666 <[email protected]>
1 parent 10a452e commit daf4783

File tree

47 files changed

+1623
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1623
-98
lines changed

.commitTitleExtra

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(1commit)

.commitmsg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
961: AC.cpp (#1297)
2+
3+
方法一.1:排序+相邻
4+
cpp - AC,100.00%,89.42%
5+
py - AC,30.97%,96.34%
6+
go - AC,36.00%,64.00%
7+
java- AC,17.13%,5.06%
8+
rust- AC,100.00%,28.57%
9+
10+
方法一.1:排序+中间
11+
cpp - AC,27.01%,90.69%
12+
py - AC,24.09%,96.99%
13+
go - AC,8.00%,56.00%
14+
java- AC,17.13%,5.06%
15+
rust- AC,100.00%,28.57%
16+
17+
方法二:哈希表
18+
cpp - AC,100.00%,89.23%
19+
py - AC,100.00%,96.34%
20+
go - AC,100.00%,84.00%
21+
java- AC,78.65%,56.74%
22+
rust- AC,100.00%,100.00%
23+
24+
方法三:相隔或相邻
25+
cpp - AC,100.00%,99.63%
26+
py - AC,100.00%,99.14%
27+
go - AC,100.00%,44.00%
28+
java- AC,100.00%,41.01%
29+
rust-AC,100.00%,42.86%
30+
31+
方法四:变种摩尔投票法
32+
cpp - AC,100.00%,99.63%
33+
py - AC,38.92%,72.90%
34+
go - AC,100.00%,48.00%
35+
java- AC,44.94%,12.08%
36+
rust- AC,100.00%,100.00%
37+
38+
方法五:随机数
39+
cpp - AC,100.00%,92.15%
40+
py - AC,50.54%,99.78%
41+
go - AC,100.00%,56.00%
42+
java- AC,78.65%,40.45%
43+
rust- AC,100.00%,28.57%

.github/workflows/1problem1day-label.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ jobs:
175175
176176
- name: Generate GitHub App token
177177
id: app-token
178+
if: steps.update-status.outputs.skip != 'true'
178179
uses: actions/create-github-app-token@v1
179180
with:
180181
app-id: ${{ vars.DAILY_BOT_APP_ID }}
181182
private-key: ${{ secrets.DAILY_BOT_APP_PRIVATE_KEY }}
182183

183184
- name: Comment on issue
185+
if: steps.update-status.outputs.skip != 'true'
184186
uses: actions/github-script@v7
185187
with:
186188
github-token: ${{ steps.app-token.outputs.token }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 12:47:42
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 13:05:32
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int repeatedNTimes(vector<int>& nums) {
14+
sort(nums.begin(), nums.end());
15+
for (int i = 1; i < nums.size(); i++) {
16+
if (nums[i] == nums[i - 1]) {
17+
return nums[i];
18+
}
19+
}
20+
return -1; // FAKE RETURN
21+
}
22+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 12:47:42
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 17:23:19
6+
*/
7+
package main
8+
9+
import "sort"
10+
11+
func repeatedNTimes(nums []int) int {
12+
sort.Ints(nums)
13+
for i := 1; i < len(nums); i++ {
14+
if nums[i] == nums[i - 1] {
15+
return nums[i]
16+
}
17+
}
18+
return -1 // FAKE RETURN
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 12:47:42
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 17:41:05
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public int repeatedNTimes(int[] nums) {
11+
Arrays.sort(nums);
12+
for (int i = 1; i < nums.length; i++) {
13+
if (nums[i] == nums[i-1]) {
14+
return nums[i];
15+
}
16+
}
17+
return -1;
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-01-02 12:47:42
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-01-02 14:48:48
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def repeatedNTimes(self, nums: List[int]) -> int:
11+
nums.sort()
12+
for i in range(1, len(nums)):
13+
if nums[i] == nums[i - 1]:
14+
return nums[i]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 12:47:42
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 17:58:03
6+
*/
7+
impl Solution {
8+
pub fn repeated_n_times(mut nums: Vec<i32>) -> i32 {
9+
nums.sort();
10+
for i in 1..nums.len() {
11+
if nums[i] == nums[i - 1] {
12+
return nums[i];
13+
}
14+
}
15+
-1 // FAKE RETURN
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 17:24:39
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 17:24:44
6+
*/
7+
package main
8+
9+
import "sort"
10+
11+
func repeatedNTimes(nums []int) int {
12+
sort.Ints(nums)
13+
mid := len(nums) / 2
14+
if nums[mid] == nums[mid + 1] {
15+
return nums[mid]
16+
}
17+
return nums[mid - 1]
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-02 17:43:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-02 17:43:23
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public int repeatedNTimes(int[] nums) {
11+
Arrays.sort(nums);
12+
int mid = nums.length / 2;
13+
return nums[mid] == nums[mid + 1] ? nums[mid] : nums[mid - 1];
14+
}
15+
}

0 commit comments

Comments
 (0)