Selaa lähdekoodia

New May problem done

master
Lachlan Jacob 5 vuotta sitten
vanhempi
commit
180cb837cf
3 muutettua tiedostoa jossa 36 lisäystä ja 0 poistoa
  1. 22
    0
      problems/387/main.py
  2. 11
    0
      problems/387/problem.txt
  3. 3
    0
      problems/387/run.sh

+ 22
- 0
problems/387/main.py Näytä tiedosto

@@ -0,0 +1,22 @@
class Solution:
def firstUniqChar(self, s):
seen = dict()
for x in range(len(s)):
if s[x] in seen:
seen[s[x]][0] += 1
else:
seen[s[x]] = [1, x]
result = None
for key, val in seen.items():
if val[0] == 1 and (result is None or val[1] < result):
result = val[1]
if result is None:
return -1
return result
s = Solution()
print("Expected: 0")
print("Got:", s.firstUniqChar("leetcode"))

+ 11
- 0
problems/387/problem.txt Näytä tiedosto

@@ -0,0 +1,11 @@
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

Examples:

s = "leetcode"
return 0.

s = "loveleetcode",
return 2.

Note: You may assume the string contain only lowercase letters.

+ 3
- 0
problems/387/run.sh Näytä tiedosto

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

Loading…
Peruuta
Tallenna