Time Limit Exceeded and my code can run in my own computer and pass this test


  • 0
    T

    input: "hvnjphmatuyqrooblzklatcsgfsswzhfuwpledozyopreftqeddgzfyhlqzjriongfzmjpnjdeak"

    my code :

    def length_of_longest_substring(s)
      @curMax = 0
      tmp_str = Array.new()
      tmp_str = s.split(//)
    
      while !tmp_str.empty? do
        charUsed = {}
        start = 0
        tmp_str.each_with_index do | str, index|
           if charUsed.has_value?(str) && index >= start
              start = index
              charUsed[index] = str
           else
              charUsed[index] = str
              maxTmp = index - start + 1
              @curMax = [@curMax, maxTmp].max		
           end
        end
        tmp_str.shift
      end
    
      return @curMax
    end
    

    This input runs Time Limit Exceeded.

    And i try the same test on my own computer, output is 12,its ok

    Could anyone help me with this problem?

    THANK YOU!


Log in to reply
 

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