Skip to content

Commit 0d38234

Browse files
committed
feat: add solutions to lc problem: No.1832
No.1832.Check if the Sentence Is Pangram
1 parent 7cf1908 commit 0d38234

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed

solution/1800-1899/1832.Check if the Sentence Is Pangram/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,81 @@ func checkIfPangram(sentence string) bool {
162162
}
163163
```
164164

165+
### **TypeScript**
166+
167+
```ts
168+
function checkIfPangram(sentence: string): boolean {
169+
const vis = new Array(26).fill(false);
170+
for (const c of sentence) {
171+
vis[c.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
172+
}
173+
return vis.every(v => v);
174+
}
175+
```
176+
177+
```ts
178+
function checkIfPangram(sentence: string): boolean {
179+
let mark = 0;
180+
for (const c of sentence) {
181+
mark |= 1 << (c.charCodeAt(0) - 'a'.charCodeAt(0));
182+
}
183+
return mark === (1 << 26) - 1;
184+
}
185+
```
186+
187+
### **Rust**
188+
189+
```rust
190+
impl Solution {
191+
pub fn check_if_pangram(sentence: String) -> bool {
192+
let mut vis = [false; 26];
193+
for c in sentence.as_bytes() {
194+
vis[(*c - b'a') as usize] = true;
195+
}
196+
vis.iter().all(|v| *v)
197+
}
198+
}
199+
```
200+
201+
```rust
202+
impl Solution {
203+
pub fn check_if_pangram(sentence: String) -> bool {
204+
let mut mark = 0;
205+
for c in sentence.as_bytes() {
206+
mark |= 1 << *c - b'a';
207+
}
208+
mark == (1 << 26) - 1
209+
}
210+
}
211+
```
212+
213+
### **C**
214+
215+
```c
216+
bool checkIfPangram(char *sentence) {
217+
int vis[26] = {0};
218+
for (int i = 0; sentence[i]; i++) {
219+
vis[sentence[i] - 'a'] = 1;
220+
}
221+
for (int i = 0; i < 26; i++) {
222+
if (!vis[i]) {
223+
return 0;
224+
}
225+
}
226+
return 1;
227+
}
228+
```
229+
230+
```c
231+
bool checkIfPangram(char *sentence) {
232+
int mark = 0;
233+
for (int i = 0; sentence[i]; i++) {
234+
mark |= 1 << (sentence[i] - 'a');
235+
}
236+
return mark == (1 << 26) - 1;
237+
}
238+
```
239+
165240
### **...**
166241

167242
```

solution/1800-1899/1832.Check if the Sentence Is Pangram/README_EN.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,81 @@ func checkIfPangram(sentence string) bool {
136136
}
137137
```
138138

139+
### **TypeScript**
140+
141+
```ts
142+
function checkIfPangram(sentence: string): boolean {
143+
const vis = new Array(26).fill(false);
144+
for (const c of sentence) {
145+
vis[c.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
146+
}
147+
return vis.every(v => v);
148+
}
149+
```
150+
151+
```ts
152+
function checkIfPangram(sentence: string): boolean {
153+
let mark = 0;
154+
for (const c of sentence) {
155+
mark |= 1 << (c.charCodeAt(0) - 'a'.charCodeAt(0));
156+
}
157+
return mark === (1 << 26) - 1;
158+
}
159+
```
160+
161+
### **Rust**
162+
163+
```rust
164+
impl Solution {
165+
pub fn check_if_pangram(sentence: String) -> bool {
166+
let mut vis = [false; 26];
167+
for c in sentence.as_bytes() {
168+
vis[(*c - b'a') as usize] = true;
169+
}
170+
vis.iter().all(|v| *v)
171+
}
172+
}
173+
```
174+
175+
```rust
176+
impl Solution {
177+
pub fn check_if_pangram(sentence: String) -> bool {
178+
let mut mark = 0;
179+
for c in sentence.as_bytes() {
180+
mark |= 1 << *c - b'a';
181+
}
182+
mark == (1 << 26) - 1
183+
}
184+
}
185+
```
186+
187+
### **C**
188+
189+
```c
190+
bool checkIfPangram(char *sentence) {
191+
int vis[26] = {0};
192+
for (int i = 0; sentence[i]; i++) {
193+
vis[sentence[i] - 'a'] = 1;
194+
}
195+
for (int i = 0; i < 26; i++) {
196+
if (!vis[i]) {
197+
return 0;
198+
}
199+
}
200+
return 1;
201+
}
202+
```
203+
204+
```c
205+
bool checkIfPangram(char *sentence) {
206+
int mark = 0;
207+
for (int i = 0; sentence[i]; i++) {
208+
mark |= 1 << (sentence[i] - 'a');
209+
}
210+
return mark == (1 << 26) - 1;
211+
}
212+
```
213+
139214
### **...**
140215

141216
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bool checkIfPangram(char *sentence) {
2+
int mark = 0;
3+
for (int i = 0; sentence[i]; i++) {
4+
mark |= 1 << (sentence[i] - 'a');
5+
}
6+
return mark == (1 << 26) - 1;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl Solution {
2+
pub fn check_if_pangram(sentence: String) -> bool {
3+
let mut mark = 0;
4+
for c in sentence.as_bytes() {
5+
mark |= 1 << *c - b'a';
6+
}
7+
mark == (1 << 26) - 1
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function checkIfPangram(sentence: string): boolean {
2+
let mark = 0;
3+
for (const c of sentence) {
4+
mark |= 1 << (c.charCodeAt(0) - 'a'.charCodeAt(0));
5+
}
6+
return mark === (1 << 26) - 1;
7+
}

0 commit comments

Comments
 (0)