Python - wrong answer in oj


  • 0
    R

    My code gives me correct answer in ideone but over here shows wrong output . please help ?

    class Solution:
    # @param A, a list of integer
    # @return an integer
        def singleNumber(self, A):
           b={}
           for i in A:
               b[i]=b.get(i,0)+1
           for num,val in b.items():
              if val==1:
                return num
            
    a=Solution()
    i=raw_input()
    b=map(int,i.split())
    print a.singleNumber(b)
    

    also suggest any changes which can make it better .. thank you !


  • 1
    S

    If you just submit the following code, the results is accepted.

    class Solution:
    # @param A, a list of integer
    # @return an integer
        def singleNumber(self, A):
           b={}
           for i in A:
               b[i]=b.get(i,0)+1
           for num,val in b.items():
              if val==1:
                return num

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.