给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。

案例:

s = "leetcode"
返回 0.

s = "loveleetcode",
返回 2.


class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        s_len=len(s)
        for i in "abcdefghijklmnopqrstuvwxyz":
            start_f = s.find(i)
            if start_f != -1 and start_f == s.rfind(i):
                s_len = min(start_f,s_len)
        return s_len if s_len != len(s) else -1

 

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2021-10-12
  • 2021-08-08
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2021-06-26
  • 2021-06-30
  • 2021-11-17
  • 2022-12-23
  • 2021-09-01
  • 2022-03-06
相关资源
相似解决方案