@@ -0,0 +1,946 @@
+#!/usr/bin/env python%0A# encoding: utf-8%0A%0A%22%22%22%0Aread-n-characters-given-read4.py%0A %0ACreated by Shuailong on 2016-03-17.%0A%0Ahttps://leetcode.com/problems/read-n-characters-given-read4/.%0A%0A%22%22%22%0A%0A# The read4 API is already defined for you.%0A# @param buf, a list of characters%0A# @return an integer%0A# def read4(buf):%0A%0Aclass Solution(object):%0A    def read(self, buf, n):%0A        %22%22%22%0A        :type buf: Destination buffer (List%5Bstr%5D)%0A        :type n: Maximum number of characters to read (int)%0A        :rtype: The number of characters read (int)%0A        %22%22%22%0A        i = 0 # index of current buf position%0A        while n %3E 0: # there are n characters to read%0A            buf4 = %5B''%5D*4%0A            l = read4(buf4)%0A            if not l:%0A                return i%0A            valid = min(l, n)%0A            buf%5Bi:i+valid%5D = buf4%5B:valid%5D%0A            n -= valid%0A            i += valid%0A        return i%0A%0A%0A%0Adef main():%0A    pass%0A    %0Aif __name__ == '__main__':%0A    main()%0A%0A

solve 1 problem