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 de8b9f4

Browse files
committed
Merge pull request #374 from 0xff-dev/2148
Add solution and test-cases for problem 2148
2 parents 53a9e55 + 1887566 commit de8b9f4

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

‎leetcode/2101-2200/2148.Count-Elements-With-Strictly-Smaller-and-Greater-Elements-/README.md‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
# [2148.Count Elements With Strictly Smaller and Greater Elements ][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
Given an integer array `nums`, return the number of elements that have **both** a strictly smaller and a strictly greater element appear in `nums`.
75

86
**Example 1:**
97

108
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
9+
Input: nums = [11,7,2,15]
10+
Output: 2
11+
Explanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.
12+
Element 11 has element 7 strictly smaller than it and element 15 strictly greater than it.
13+
In total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.
1314
```
1415

15-
## 题意
16-
> ...
17-
18-
## 题解
16+
**Example 2:**
1917

20-
### 思路1
21-
> ...
22-
Count Elements With Strictly Smaller and Greater Elements
23-
```go
2418
```
25-
19+
Input: nums = [-3,3,3,90]
20+
Output: 2
21+
Explanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.
22+
Since there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.
23+
```
2624

2725
## 结语
2826

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(nums []int) int {
4+
max, min := nums[0], nums[0]
5+
check := make(map[int]int)
6+
for _, n := range nums {
7+
if n > max {
8+
max = n
9+
}
10+
if n < min {
11+
min = n
12+
}
13+
check[n]++
14+
}
15+
if len(check) > 2 {
16+
return len(nums) - check[max] - check[min]
17+
}
18+
return 0
519
}

‎leetcode/2101-2200/2148.Count-Elements-With-Strictly-Smaller-and-Greater-Elements-/Solution_test.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs []int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", []int{1, 2}, 0},
17+
{"TestCase2", []int{11, 7, 2, 15}, 2},
18+
{"TestCase3", []int{-3, 3, 3, 90}, 2},
19+
{"TestCase4", []int{1, 2, 3, 4}, 2},
1920
}
2021

2122
// 开始测试
@@ -30,10 +31,10 @@ func TestSolution(t *testing.T) {
3031
}
3132
}
3233

33-
//压力测试
34+
//压力测试
3435
func BenchmarkSolution(b *testing.B) {
3536
}
3637

37-
//使用案列
38+
//使用案列
3839
func ExampleSolution() {
3940
}

0 commit comments

Comments
(0)

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