Posts

Find the first recurring character in a string

 Problem: Given a string, return the first recurring character in it, or None if there is no recurring character. For example, given the string "abdefgccad", return "c". Given the string "abcdefgh", return None.  Solution1: def str_opr ( s ): for i , x in enumerate ( s ): if x in s [: i ]: return x return None print ( str_opr ( 'abdefgccad' )) Solution2: def str_opr ( s ): lis = set () for x in s : if x in lis : return x lis . add ( x ) return None print ( str_opr ( 'abdefgccad' ))