Skip to content

Commit a93d151

Browse files
committed
feat: add solutions to lc problem: No.2089
* Add solutions to lc problem: No.2089.Find Target Indices After Sorting Array * Update workflows
1 parent 5ef0461 commit a93d151

File tree

8 files changed

+135
-13
lines changed

8 files changed

+135
-13
lines changed

.github/workflows/compress.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
name: Compress
22

33
on:
4-
push:
5-
branches: [main]
6-
paths:
7-
- "**.jpg"
8-
- "**.jpeg"
9-
- "**.png"
10-
- "**.webp"
4+
schedule:
5+
- cron: "0 0 * * 3"
116
workflow_dispatch:
127

138
jobs:

.github/workflows/contributors.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Contributors
22

33
on:
4-
push:
5-
branches: [main]
4+
schedule:
5+
- cron: "0 18 * * *"
66
workflow_dispatch:
77

88
jobs:

solution/2000-2099/2089.Find Target Indices After Sorting Array/README.md

+47-2
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,29 @@
6565
<!-- 这里可写当前语言的特殊实现逻辑 -->
6666

6767
```python
68-
68+
class Solution:
69+
def targetIndices(self, nums: List[int], target: int) -> List[int]:
70+
nums.sort()
71+
return [i for i, num in enumerate(nums) if num == target]
6972
```
7073

7174
### **Java**
7275

7376
<!-- 这里可写当前语言的特殊实现逻辑 -->
7477

7578
```java
76-
79+
class Solution {
80+
public List<Integer> targetIndices(int[] nums, int target) {
81+
Arrays.sort(nums);
82+
List<Integer> ans = new ArrayList<>();
83+
for (int i = 0; i < nums.length; ++i) {
84+
if (nums[i] == target) {
85+
ans.add(i);
86+
}
87+
}
88+
return ans;
89+
}
90+
}
7791
```
7892

7993
### **TypeScript**
@@ -92,6 +106,37 @@ function targetIndices(nums: number[], target: number): number[] {
92106
};
93107
```
94108

109+
### **C++**
110+
111+
```cpp
112+
class Solution {
113+
public:
114+
vector<int> targetIndices(vector<int>& nums, int target) {
115+
sort(nums.begin(), nums.end());
116+
vector<int> ans;
117+
for (int i = 0; i < nums.size(); ++i)
118+
if (nums[i] == target)
119+
ans.push_back(i);
120+
return ans;
121+
}
122+
};
123+
```
124+
125+
### **Go**
126+
127+
```go
128+
func targetIndices(nums []int, target int) []int {
129+
sort.Ints(nums)
130+
var ans []int
131+
for i, num := range nums {
132+
if num == target {
133+
ans = append(ans, i)
134+
}
135+
}
136+
return ans
137+
}
138+
```
139+
95140
### **...**
96141

97142
```

solution/2000-2099/2089.Find Target Indices After Sorting Array/README_EN.md

+47-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,27 @@ The index where nums[i] == 5 is 4.
6161
### **Python3**
6262

6363
```python
64-
64+
class Solution:
65+
def targetIndices(self, nums: List[int], target: int) -> List[int]:
66+
nums.sort()
67+
return [i for i, num in enumerate(nums) if num == target]
6568
```
6669

6770
### **Java**
6871

6972
```java
70-
73+
class Solution {
74+
public List<Integer> targetIndices(int[] nums, int target) {
75+
Arrays.sort(nums);
76+
List<Integer> ans = new ArrayList<>();
77+
for (int i = 0; i < nums.length; ++i) {
78+
if (nums[i] == target) {
79+
ans.add(i);
80+
}
81+
}
82+
return ans;
83+
}
84+
}
7185
```
7286

7387
### **TypeScript**
@@ -86,6 +100,37 @@ function targetIndices(nums: number[], target: number): number[] {
86100
};
87101
```
88102

103+
### **C++**
104+
105+
```cpp
106+
class Solution {
107+
public:
108+
vector<int> targetIndices(vector<int>& nums, int target) {
109+
sort(nums.begin(), nums.end());
110+
vector<int> ans;
111+
for (int i = 0; i < nums.size(); ++i)
112+
if (nums[i] == target)
113+
ans.push_back(i);
114+
return ans;
115+
}
116+
};
117+
```
118+
119+
### **Go**
120+
121+
```go
122+
func targetIndices(nums []int, target int) []int {
123+
sort.Ints(nums)
124+
var ans []int
125+
for i, num := range nums {
126+
if num == target {
127+
ans = append(ans, i)
128+
}
129+
}
130+
return ans
131+
}
132+
```
133+
89134
### **...**
90135

91136
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public:
3+
vector<int> targetIndices(vector<int>& nums, int target) {
4+
sort(nums.begin(), nums.end());
5+
vector<int> ans;
6+
for (int i = 0; i < nums.size(); ++i)
7+
if (nums[i] == target)
8+
ans.push_back(i);
9+
return ans;
10+
}
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func targetIndices(nums []int, target int) []int {
2+
sort.Ints(nums)
3+
var ans []int
4+
for i, num := range nums {
5+
if num == target {
6+
ans = append(ans, i)
7+
}
8+
}
9+
return ans
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public List<Integer> targetIndices(int[] nums, int target) {
3+
Arrays.sort(nums);
4+
List<Integer> ans = new ArrayList<>();
5+
for (int i = 0; i < nums.length; ++i) {
6+
if (nums[i] == target) {
7+
ans.add(i);
8+
}
9+
}
10+
return ans;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def targetIndices(self, nums: List[int], target: int) -> List[int]:
3+
nums.sort()
4+
return [i for i, num in enumerate(nums) if num == target]

0 commit comments

Comments
 (0)