My solution in python (first time pythoner)


  • 0
    C

    My solution in python with very few lines, 44 ms. First time python, way to go!

       def __init__(self):
            self.q = collections.deque()
         
        def read(self, buf, n):
            """
            :type buf: Destination buffer (List[str])
            :type n: Maximum number of characters to read (int)
            :rtype: The number of characters read (int)
            """
            idx = 0
            
            while True:
                tmpBuf = [""] * 4
                length = read4(tmpBuf)
                for i in range(length):
                    self.q.append(tmpBuf.pop(0))
                while idx < n and self.q:
                        buf[idx] = self.q.popleft()
                        idx += 1
                if length < 4 or idx >= n:
                    return idx

Log in to reply
 

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