Dumb python code question


  • 0
    V

    Hello everyone! I'm a newbie and trying to do some coding exercise. I wrote the following python code and tested it locally without any issue. Could some help me to understand why it doesn't work in the OJ? Thanks for looking at my dumb code!

       class Solution:
            def findPeakElement(self,num):
                if len(num)==1:
                    print 0
                elif num[0]>num[1]:
                    print 0
                elif num[-1]>num[-2]:
                    print len(num)-1
                else:
                    for i in xrange(1,len(num)-1):
                        if num[i]>num[i-1] and num[i]>num[i+1]:
                            print i
                            break
                        else:
                            continue
    

    It says my answer is wrong:

    Input:	[-2147483648]
    Output:	null
    Expected:	0

  • 1
    S

    Instead of 'printing the result', you are supposed to return the found peak element so that OJ could decide whether your answer is correct or not.


  • 0
    V

    Thanks! I figured this is a mistake I often commit..


Log in to reply
 

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