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
9 changes: 0 additions & 9 deletions Array/2828. Check if a String Is an Acronym of Words.py

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Each problem follows this structure:

## Solutions

📊 **Statistics**: 83 problems solved (migrated to new structure)
📊 **Statistics**: 84 problems solved (migrated to new structure)

| Difficulty | Count |
|------------|-------|
| Easy | 58 |
| Easy | 59 |
| Medium | 24 |
| Hard | 1 |

Expand Down
3 changes: 2 additions & 1 deletion docs/EASY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Easy Problems

Total: 58 problems solved
Total: 59 problems solved

## Solutions

Expand Down Expand Up @@ -61,6 +61,7 @@ Total: 58 problems solved
| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature/) | [solution.py](../problems/easy/convert_the_temperature_2469/solution.py) | [test_solution.py](../problems/easy/convert_the_temperature_2469/test_solution.py) |
| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/) | [solution.py](../problems/easy/remove_trailing_zeros_from_a_string_2710/solution.py) | [test_solution.py](../problems/easy/remove_trailing_zeros_from_a_string_2710/test_solution.py) |
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target/) | [solution.py](../problems/easy/number_of_employees_who_met_the_target_2798/solution.py) | [test_solution.py](../problems/easy/number_of_employees_who_met_the_target_2798/test_solution.py) |
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/) | [solution.py](../problems/easy/check_if_a_string_is_an_acronym_of_words_2828/solution.py) | [test_solution.py](../problems/easy/check_if_a_string_is_an_acronym_of_words_2828/test_solution.py) |
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [solution.py](../problems/easy/find_words_containing_character_2942/solution.py) | [test_solution.py](../problems/easy/find_words_containing_character_2942/test_solution.py) |
| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string/) | [solution.py](../problems/easy/score_of_a_string_3110/solution.py) | [test_solution.py](../problems/easy/score_of_a_string_3110/test_solution.py) |
| 3289 | [The Two Sneaky Numbers of Digitville](https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville/) | [solution.py](../problems/easy/the_two_sneaky_numbers_of_digitville_3289/solution.py) | [test_solution.py](../problems/easy/the_two_sneaky_numbers_of_digitville_3289/test_solution.py) |
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Tags: Array, String
from typing import List


class Solution:
def is_acronym(self, words: List[str], s: str) -> bool:
"""
Time complexity: O(n)
n represents the number of words in the words list
Loop through words list and build acronym: O(n)
String comparison acronym == s: Python short-circuits at first mismatch,
worst case O(min(n, m)) where m = len(s)
Since O(min(n, m)) ≤ O(n), overall time complexity is O(n)

Space complexity: O(n)
n represents the number of words in the words list
acronym string is formed by taking first character of each word, length is n
No other significant space usage
"""
acronym = ''
for word in words:
acronym += word[0]
return acronym == s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from tests.base_test import BaseTestSolution
from .solution import Solution


class TestSolution(BaseTestSolution):
solution = Solution()

@pytest.mark.parametrize("method_name, words, s, expected, timeout", [
('is_acronym', ["alice", "bob", "charlie"], "abc", True, None),
('is_acronym', ["an", "apple"], "a", False, None),
('is_acronym', ["never", "gonna", "give", "up", "on", "you"], "ngguoy", True, None),
])
def test_is_acronym(self, method_name, words, s, expected, timeout):
self._run_test(self.solution, method_name, (words, s,), expected, timeout)
Loading