Py学习  »  Python

第一次出现在Python中的重复字符

JingGuo • 5 年前 • 1562 次点击  

给你一根绳子 您的任务是查找S中第一个出现的字母数字字符(从左到右读取),该字符具有连续重复。

包含字符串S的一行输入。

输出格式

例如, 如果我输入下面的字符串

..12345678910111213141516171820212223

结果是

1

我的代码是

def firstRepeatedChar(str):   
   h = {}
   for ch in str: 
      if ch in h: 
         return ch;         
      else: 
         h[ch] = 0

   return -1
n = input()
print(firstRepeatedChar(n)) 

我如何用python解决这个问题?请帮帮我。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56158
 
1562 次点击  
文章 [ 1 ]  |  最新文章 5 年前