leetcode 387. First Unique Character in a Stringpython

    xiaoxiao2021-03-25  63

    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.

    class Solution(object): def firstUniqChar(self, s): """ :type s: str :rtype: int """ return min([s.find(c) for c in string.ascii_lowercase if s.count(c)==1] or [-1])
    转载请注明原文地址: https://ju.6miu.com/read-36951.html

    最新回复(0)