Python clean code

  • 0
    # The read4 API is already defined for you.
    # @param buf, a list of characters
    # @return an integer
    # def read4(buf):
    class Solution(object):
        def __init__(self):
            self.buf = []
        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)
            while len(self.buf) < n:
                tmp = ['']*4
                size = read4(tmp)
                if size < 4:
            real_size = min(n, len(self.buf))
            buf[:real_size] = self.buf[:real_size]
            self.buf = self.buf[real_size:]
            return real_size

Log in to reply

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