Answers for "find first non repeating character in a string"

0

first unique character in a string python

class Solution(object):
   def firstUniqChar(self, s):
      """
      :type s: str
      :rtype: int
      """
      frequency = {}
      for i in s:
         if i not in frequency:
            frequency[i] = 1
         else:
            frequency[i] +=1
      for i in range(len(s)):
         if frequency[s[i]] == 1:
            return i
      return -1
ob1 = Solution()
print(ob1.firstUniqChar("people"))
print(ob1.firstUniqChar("abaabba"))
Posted by: Guest on October-04-2020
0

First non repeating character position in a string

# First non repeating character position in a string

def first_non_repeating_letter(str)
    strL = str.downcase
    strL.each_char.with_index do |v, i|
        if strL.index(v) == strL.rindex(v)
            return i
        end
    end
    -1
end

print "First non repeating character position = ", 
	first_non_repeating_letter("abcdcba");  # 3
Posted by: Guest on October-07-2021

Code answers related to "find first non repeating character in a string"

Browse Popular Code Answers by Language