Skip to content

Commit d15270b

Browse files
authored
Create 387_First_Unique_Character_in_a_String.md
1 parent 79cd2d5 commit d15270b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 387. First Unique Character in a String
2+
3+
4+
Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1.
5+
6+
Examples:
7+
8+
s = "leetcode"
9+
return 0.
10+
11+
s = "loveleetcode"
12+
return 2.
13+
14+
15+
16+
```python
17+
def firstUniqChar(self, s: str) -> int:
18+
dic = Counter(s)
19+
for k, v in dic.items():
20+
if v == 1:
21+
return s.index(k)
22+
return -1
23+
```
24+
25+
26+
```
27+
Runtime: 52 ms, faster than 98.59% of Python3 online submissions for First Unique Character in a String.
28+
Memory Usage: 14.2 MB, less than 100.00% of Python3 online submissions for First Unique Character in a String.
29+
```

0 commit comments

Comments
 (0)