Why am i getting TLE, any ideas?


  • 0
    P
    from collections import deque
    class Solution(object):
        def wordsTyping(self, sentence, rows, cols):
            """
            :type sentence: List[str]
            :type rows: int
            :type cols: int
            :rtype: int
            """
            d = deque(sentence)
            count = 0
            for each in range(rows):
                avail = cols            
                while (	len(d[0])  <= avail ):
                	avail = avail - len(d[0]) -1
                	d.rotate(-1)
                	count+=1
            return count/len(d)
    
      Last executed input:
    

    ["try","to","be","better"]
    10000
    9001
    Says TLE for this test case.
    How can this be improved?


Log in to reply
 

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