File tree Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ class Solution {
95
95
return 0 ;
96
96
}
97
97
int i = 0 ;
98
- for (int j = 0 ; j < nums . length ; ++ j) {
98
+ for (int j = 0 ; j < len ; ++ j) {
99
99
// 如果等于目标值,则删除
100
100
if (nums[j] == val) {
101
101
continue ;
@@ -110,7 +110,7 @@ class Solution {
110
110
111
111
Python3 Code:
112
112
113
- ``` py
113
+ ``` python
114
114
class Solution :
115
115
def removeElement (self , nums : List[int ], val : int ) -> int :
116
116
i = 0
@@ -121,3 +121,21 @@ class Solution:
121
121
return i
122
122
```
123
123
124
+ C++ Code:
125
+
126
+ ``` cpp
127
+ class Solution {
128
+ public:
129
+ int removeElement(vector<int >& nums, int val) {
130
+ int n = nums.size();
131
+ if(!n) return 0;
132
+ int i = 0;
133
+ for(int j = 0; j < n; ++j){
134
+ if(nums[ j] == val) continue;
135
+ nums[ i++] = nums[ j] ;
136
+ }
137
+ return i;
138
+ }
139
+ };
140
+ ```
141
+
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ class Solution {
119
119
120
120
Python3 Code:
121
121
122
- ``` py
122
+ ``` python
123
123
class Solution :
124
124
def firstMissingPositive (self , nums : List[int ]) -> int :
125
125
n = len (nums)
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ class Solution {
57
57
58
58
** 题目代码**
59
59
60
+ Java Code:
61
+
60
62
``` java
61
63
class Solution {
62
64
public int findRepeatNumber (int [] nums ) {
@@ -80,3 +82,22 @@ class Solution {
80
82
}
81
83
```
82
84
85
+ C++ Code:
86
+
87
+ ``` cpp
88
+ class Solution {
89
+ public:
90
+ int findRepeatNumber(vector<int >& nums) {
91
+ if(nums.empty()) return 0;
92
+ int n = nums.size();
93
+ for(int i = 0; i < n; ++i){
94
+ while(nums[ i] != i){
95
+ if(nums[ i] == nums[ nums[ i]] ) return nums[ i] ;
96
+ swap(nums[ i] , nums[ nums[ i]] );
97
+ }
98
+ }
99
+ return -1;
100
+ }
101
+ };
102
+ ```
103
+
Original file line number Diff line number Diff line change 38
38
39
39
#### 题目代码
40
40
41
+ Java Code:
42
+
41
43
``` java
42
44
class Solution {
43
45
public int minSubArrayLen (int s , int [] nums ) {
@@ -60,3 +62,23 @@ class Solution {
60
62
}
61
63
```
62
64
65
+ C++ Code:
66
+
67
+ ``` cpp
68
+ class Solution {
69
+ public:
70
+ int minSubArrayLen(int t, vector<int >& nums) {
71
+ int n = nums.size();
72
+ int i = 0, sum = 0, winlen = INT_MAX;
73
+ for(int j = 0; j < n; ++j){
74
+ sum += nums[ j] ;
75
+ while(sum >= t){
76
+ winlen = min(winlen, j - i + 1);
77
+ sum -= nums[ i++] ;
78
+ }
79
+ }
80
+ return winlen == INT_MAX? 0: winlen;
81
+ }
82
+ };
83
+ ```
84
+
You can’t perform that action at this time.
0 commit comments