Skip to content

Commit b24c78b

Browse files
solves first unique character in string
1 parent 98629ad commit b24c78b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) |
104104
| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) |
105105
| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) |
106-
| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) |
106+
| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) |
107107
| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) |
108108
| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) |
109109
| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) |

Diff for: python/first_unique_character_in_string.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def firstUniqChar(self, s: str) -> int:
3+
frequencies = {}
4+
for index, character in enumerate(s):
5+
frequencies[character] = frequencies.get(character, 0) + 1
6+
for index, character in enumerate(s):
7+
if frequencies[character] == 1:
8+
return index
9+
return -1

0 commit comments

Comments
 (0)