浏览代码

New May problem done

master
Lachlan Jacob 5 年前
父节点
当前提交
180cb837cf
共有 3 个文件被更改,包括 36 次插入0 次删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

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

python3 main.py

正在加载...
取消
保存