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 77e704b

Browse files
D. J.:
- Added the leetcode problem and description of 3136
1 parent e86340a commit 77e704b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
- [2466 Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings/description/)
273273
- [2523 Closest Prime Numbers in Range](https://leetcode.com/problems/closest-prime-numbers-in-range/description/)
274274
- [2799 Count Complete Subarrays in an Array](https://leetcode.com/problems/count-complete-subarrays-in-an-array/description/)
275+
- [3136 Valid Word](https://leetcode.com/problems/valid-word/description/)
275276
- [3392 Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/description/)
276277

277278
## Development 🔧
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution:
2+
"""Base class for all LeetCode Problems."""
3+
4+
def isValid(self, word: str) -> bool:
5+
"""
6+
A word is considered valid if:
7+
- It contains a minimum of 3 characters.
8+
- It contains only digits (0-9), and English letters (uppercase and lowercase).
9+
- It includes at least one vowel.
10+
- It includes at least one consonant.
11+
You are given a string word.
12+
13+
Return true if word is valid, otherwise, return false.
14+
15+
Notes:
16+
- 'a', 'e', 'i', 'o', 'u', and their uppercases are vowels.
17+
- A consonant is an English letter that is not a vowel.
18+
"""
19+
num_characters, num_vowels, num_consonants = 0, 0, 0
20+
for c in word.lower():
21+
is_digit = c >= "0" and c <= "9"
22+
is_letter = c >= "a" and c <= "z"
23+
is_vowel = c in ["a", "e", "i", "o", "u"]
24+
is_consonant = not is_vowel and is_letter
25+
if not (is_digit or is_letter):
26+
return False
27+
num_characters += 1
28+
if is_vowel:
29+
num_vowels += 1
30+
if is_consonant:
31+
num_consonants += 1
32+
return num_characters >= 3 and num_vowels >= 1 and num_consonants >= 1

‎tests/test_3136_valid_word.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from awesome_python_leetcode._3136_valid_word import Solution
4+
5+
6+
@pytest.mark.parametrize(
7+
argnames=["word", "expected"],
8+
argvalues=[
9+
("234Adas", True),
10+
("b3", False),
11+
("a3$e", False),
12+
],
13+
)
14+
def test_func(word: str, expected: bool):
15+
"""Tests the solution of a LeetCode problem."""
16+
is_valid = Solution().isValid(word)
17+
assert is_valid is expected

0 commit comments

Comments
(0)

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