“`”
参考回答:
<pre><code class=""language-c"" lang=""c"">def first_not_repeating_char(string):
if not string:
return -1
resultDict = {}
for k, s in enumerate(string):
resultDict [s] = [resultDict [s][0] + 1,k] if resultDict .get(s) else [1,k]
pos = len(string)
ret = None
for x in resultDict :
if resultDict [x][0] ==1 and resultDict [x][1] <pos:
pos = resultDict [x][1]
ret = (x,pos)
return ret
</code></pre>
<pre><code> "“`
Was this helpful?
0 /
0