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 07290a1

Browse files
feat: add solutions to lc problems: No.10031+ (doocs#2189)
1 parent 9d01a95 commit 07290a1

File tree

24 files changed

+723
-21
lines changed

24 files changed

+723
-21
lines changed

‎solution/0300-0399/0383.Ransom Note/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func canConstruct(ransomNote string, magazine string) bool {
136136

137137
```ts
138138
function canConstruct(ransomNote: string, magazine: string): boolean {
139-
const cnt=new Array(26).fill(0);
139+
const cnt:number[] = Array(26).fill(0);
140140
for (const c of magazine) {
141141
++cnt[c.charCodeAt(0) - 97];
142142
}

‎solution/0300-0399/0383.Ransom Note/README_EN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func canConstruct(ransomNote string, magazine string) bool {
113113

114114
```ts
115115
function canConstruct(ransomNote: string, magazine: string): boolean {
116-
const cnt=new Array(26).fill(0);
116+
const cnt:number[] = Array(26).fill(0);
117117
for (const c of magazine) {
118118
++cnt[c.charCodeAt(0) - 97];
119119
}

‎solution/0300-0399/0383.Ransom Note/Solution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function canConstruct(ransomNote: string, magazine: string): boolean {
2-
const cnt=new Array(26).fill(0);
2+
const cnt: number[]= Array(26).fill(0);
33
for (const c of magazine) {
44
++cnt[c.charCodeAt(0) - 97];
55
}

‎solution/10000-10099/10031.Smallest Missing Integer Greater Than Sequential Prefix Sum/README.md‎

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,105 @@
5050
<!-- 这里可写当前语言的特殊实现逻辑 -->
5151

5252
```python
53-
53+
class Solution:
54+
def missingInteger(self, nums: List[int]) -> int:
55+
s, n = nums[0], len(nums)
56+
j = 1
57+
while j < len(nums) and nums[j] == nums[j - 1] + 1:
58+
s += nums[j]
59+
j += 1
60+
vis = set(nums)
61+
for x in count(s):
62+
if x not in vis:
63+
return x
5464
```
5565

5666
### **Java**
5767

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

6070
```java
61-
71+
class Solution {
72+
public int missingInteger(int[] nums) {
73+
int s = nums[0], j = 1;
74+
while (j < nums.length && nums[j] == nums[j - 1] + 1) {
75+
s += nums[j++];
76+
}
77+
boolean[] vis = new boolean[51];
78+
for (int x : nums) {
79+
vis[x] = true;
80+
}
81+
for (int x = s;; ++x) {
82+
if (x >= vis.length || !vis[x]) {
83+
return x;
84+
}
85+
}
86+
}
87+
}
6288
```
6389

6490
### **C++**
6591

6692
```cpp
67-
93+
class Solution {
94+
public:
95+
int missingInteger(vector<int>& nums) {
96+
int s = nums[0], j = 1;
97+
while (j < nums.size() && nums[j] == nums[j - 1] + 1) {
98+
s += nums[j++];
99+
}
100+
bool vis[51]{};
101+
for (int x : nums) {
102+
vis[x] = true;
103+
}
104+
for (int x = s;; ++x) {
105+
if (x >= 51 || !vis[x]) {
106+
return x;
107+
}
108+
}
109+
}
110+
};
68111
```
69112
70113
### **Go**
71114
72115
```go
116+
func missingInteger(nums []int) int {
117+
s, j := nums[0], 1
118+
for j < len(nums) && nums[j] == nums[j-1]+1 {
119+
s, j = s+nums[j], j+1
120+
}
121+
vis := [51]bool{}
122+
for _, x := range nums {
123+
vis[x] = true
124+
}
125+
for x := s; ; x++ {
126+
if x >= len(vis) || !vis[x] {
127+
return x
128+
}
129+
}
130+
}
131+
```
73132

133+
### **TypeScript**
134+
135+
```ts
136+
function missingInteger(nums: number[]): number {
137+
let [s, j] = [nums[0], 1];
138+
const n = nums.length;
139+
while (j < n && nums[j] === nums[j - 1] + 1) {
140+
s += nums[j++];
141+
}
142+
const vis: boolean[] = Array(51).fill(false);
143+
for (const x of nums) {
144+
vis[x] = true;
145+
}
146+
for (let x = s; ; ++x) {
147+
if (x >= vis.length || !vis[x]) {
148+
return x;
149+
}
150+
}
151+
}
74152
```
75153

76154
### **...**

‎solution/10000-10099/10031.Smallest Missing Integer Greater Than Sequential Prefix Sum/README_EN.md‎

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,103 @@
4242
### **Python3**
4343

4444
```python
45-
45+
class Solution:
46+
def missingInteger(self, nums: List[int]) -> int:
47+
s, n = nums[0], len(nums)
48+
j = 1
49+
while j < len(nums) and nums[j] == nums[j - 1] + 1:
50+
s += nums[j]
51+
j += 1
52+
vis = set(nums)
53+
for x in count(s):
54+
if x not in vis:
55+
return x
4656
```
4757

4858
### **Java**
4959

5060
```java
51-
61+
class Solution {
62+
public int missingInteger(int[] nums) {
63+
int s = nums[0], j = 1;
64+
while (j < nums.length && nums[j] == nums[j - 1] + 1) {
65+
s += nums[j++];
66+
}
67+
boolean[] vis = new boolean[51];
68+
for (int x : nums) {
69+
vis[x] = true;
70+
}
71+
for (int x = s;; ++x) {
72+
if (x >= vis.length || !vis[x]) {
73+
return x;
74+
}
75+
}
76+
}
77+
}
5278
```
5379

5480
### **C++**
5581

5682
```cpp
57-
83+
class Solution {
84+
public:
85+
int missingInteger(vector<int>& nums) {
86+
int s = nums[0], j = 1;
87+
while (j < nums.size() && nums[j] == nums[j - 1] + 1) {
88+
s += nums[j++];
89+
}
90+
bool vis[51]{};
91+
for (int x : nums) {
92+
vis[x] = true;
93+
}
94+
for (int x = s;; ++x) {
95+
if (x >= 51 || !vis[x]) {
96+
return x;
97+
}
98+
}
99+
}
100+
};
58101
```
59102
60103
### **Go**
61104
62105
```go
106+
func missingInteger(nums []int) int {
107+
s, j := nums[0], 1
108+
for j < len(nums) && nums[j] == nums[j-1]+1 {
109+
s, j = s+nums[j], j+1
110+
}
111+
vis := [51]bool{}
112+
for _, x := range nums {
113+
vis[x] = true
114+
}
115+
for x := s; ; x++ {
116+
if x >= len(vis) || !vis[x] {
117+
return x
118+
}
119+
}
120+
}
121+
```
63122

123+
### **TypeScript**
124+
125+
```ts
126+
function missingInteger(nums: number[]): number {
127+
let [s, j] = [nums[0], 1];
128+
const n = nums.length;
129+
while (j < n && nums[j] === nums[j - 1] + 1) {
130+
s += nums[j++];
131+
}
132+
const vis: boolean[] = Array(51).fill(false);
133+
for (const x of nums) {
134+
vis[x] = true;
135+
}
136+
for (let x = s; ; ++x) {
137+
if (x >= vis.length || !vis[x]) {
138+
return x;
139+
}
140+
}
141+
}
64142
```
65143

66144
### **...**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int missingInteger(vector<int>& nums) {
4+
int s = nums[0], j = 1;
5+
while (j < nums.size() && nums[j] == nums[j - 1] + 1) {
6+
s += nums[j++];
7+
}
8+
bool vis[51]{};
9+
for (int x : nums) {
10+
vis[x] = true;
11+
}
12+
for (int x = s;; ++x) {
13+
if (x >= 51 || !vis[x]) {
14+
return x;
15+
}
16+
}
17+
}
18+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func missingInteger(nums []int) int {
2+
s, j := nums[0], 1
3+
for j < len(nums) && nums[j] == nums[j-1]+1 {
4+
s, j = s+nums[j], j+1
5+
}
6+
vis := [51]bool{}
7+
for _, x := range nums {
8+
vis[x] = true
9+
}
10+
for x := s; ; x++ {
11+
if x >= len(vis) || !vis[x] {
12+
return x
13+
}
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int missingInteger(int[] nums) {
3+
int s = nums[0], j = 1;
4+
while (j < nums.length && nums[j] == nums[j - 1] + 1) {
5+
s += nums[j++];
6+
}
7+
boolean[] vis = new boolean[51];
8+
for (int x : nums) {
9+
vis[x] = true;
10+
}
11+
for (int x = s;; ++x) {
12+
if (x >= vis.length || !vis[x]) {
13+
return x;
14+
}
15+
}
16+
}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def missingInteger(self, nums: List[int]) -> int:
3+
s, n = nums[0], len(nums)
4+
j = 1
5+
while j < len(nums) and nums[j] == nums[j - 1] + 1:
6+
s += nums[j]
7+
j += 1
8+
vis = set(nums)
9+
for x in count(s):
10+
if x not in vis:
11+
return x
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function missingInteger(nums: number[]): number {
2+
let [s, j] = [nums[0], 1];
3+
const n = nums.length;
4+
while (j < n && nums[j] === nums[j - 1] + 1) {
5+
s += nums[j++];
6+
}
7+
const vis: boolean[] = Array(51).fill(false);
8+
for (const x of nums) {
9+
vis[x] = true;
10+
}
11+
for (let x = s; ; ++x) {
12+
if (x >= vis.length || !vis[x]) {
13+
return x;
14+
}
15+
}
16+
}

0 commit comments

Comments
(0)

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