Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions solution/3100-3199/3136.Valid Word/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,71 @@ function isValid(word: string): boolean {
}
```

#### Rust

```rust
impl Solution {
pub fn is_valid(word: String) -> bool {
if word.len() < 3 {
return false;
}

let mut has_vowel = false;
let mut has_consonant = false;
let vowels = ['a', 'e', 'i', 'o', 'u'];

for c in word.chars() {
if !c.is_alphanumeric() {
return false;
}
if c.is_alphabetic() {
let lower_c = c.to_ascii_lowercase();
if vowels.contains(&lower_c) {
has_vowel = true;
} else {
has_consonant = true;
}
}
}

has_vowel && has_consonant
}
}
```

#### C#

```cs
public class Solution {
public bool IsValid(string word) {
if (word.Length < 3) {
return false;
}

bool hasVowel = false, hasConsonant = false;
bool[] vs = new bool[26];
foreach (char c in "aeiou") {
vs[c - 'a'] = true;
}

foreach (char c in word) {
if (char.IsLetter(c)) {
char lower = char.ToLower(c);
if (vs[lower - 'a']) {
hasVowel = true;
} else {
hasConsonant = true;
}
} else if (!char.IsDigit(c)) {
return false;
}
}

return hasVowel && hasConsonant;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
65 changes: 65 additions & 0 deletions solution/3100-3199/3136.Valid Word/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,71 @@ function isValid(word: string): boolean {
}
```

#### Rust

```rust
impl Solution {
pub fn is_valid(word: String) -> bool {
if word.len() < 3 {
return false;
}

let mut has_vowel = false;
let mut has_consonant = false;
let vowels = ['a', 'e', 'i', 'o', 'u'];

for c in word.chars() {
if !c.is_alphanumeric() {
return false;
}
if c.is_alphabetic() {
let lower_c = c.to_ascii_lowercase();
if vowels.contains(&lower_c) {
has_vowel = true;
} else {
has_consonant = true;
}
}
}

has_vowel && has_consonant
}
}
```

#### C#

```cs
public class Solution {
public bool IsValid(string word) {
if (word.Length < 3) {
return false;
}

bool hasVowel = false, hasConsonant = false;
bool[] vs = new bool[26];
foreach (char c in "aeiou") {
vs[c - 'a'] = true;
}

foreach (char c in word) {
if (char.IsLetter(c)) {
char lower = char.ToLower(c);
if (vs[lower - 'a']) {
hasVowel = true;
} else {
hasConsonant = true;
}
} else if (!char.IsDigit(c)) {
return false;
}
}

return hasVowel && hasConsonant;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
28 changes: 28 additions & 0 deletions solution/3100-3199/3136.Valid Word/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Solution {
public bool IsValid(string word) {
if (word.Length < 3) {
return false;
}

bool hasVowel = false, hasConsonant = false;
bool[] vs = new bool[26];
foreach (char c in "aeiou") {
vs[c - 'a'] = true;
}

foreach (char c in word) {
if (char.IsLetter(c)) {
char lower = char.ToLower(c);
if (vs[lower - 'a']) {
hasVowel = true;
} else {
hasConsonant = true;
}
} else if (!char.IsDigit(c)) {
return false;
}
}

return hasVowel && hasConsonant;
}
}
27 changes: 27 additions & 0 deletions solution/3100-3199/3136.Valid Word/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
impl Solution {
pub fn is_valid(word: String) -> bool {
if word.len() < 3 {
return false;
}

let mut has_vowel = false;
let mut has_consonant = false;
let vowels = ['a', 'e', 'i', 'o', 'u'];

for c in word.chars() {
if !c.is_alphanumeric() {
return false;
}
if c.is_alphabetic() {
let lower_c = c.to_ascii_lowercase();
if vowels.contains(&lower_c) {
has_vowel = true;
} else {
has_consonant = true;
}
}
}

has_vowel && has_consonant
}
}