About time complexity


  • 0
    W

    I am very poor in English and thank those who are willing to read my question.
    I don't pay attention to the meaning of question before having written code.
    I am puzzled about time complexity.

    class Solution(object):
        def searchRange(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            start=-1
            end=-1
            length=len(nums)
            flag=False
            for i in range(length):
                if not flag and nums[i]==target:
                    start=i
                    flag=True
                if flag and nums[i]==target:
                    end=i
                else:
                    if flag:
                        break
            return [start,end]
    

    I think its time complexity is O (n). But I passed the test case, and in three submissions, there were twice defeated 70% of the people.


Log in to reply
 

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