3 line c++ impl


  • 0
    T
    // Forward declaration of the read4 API.
    int read4(char *buf);
    
    class Solution {
    public:
        /**
         * @param buf Destination buffer
         * @param n   Maximum number of characters to read
         * @return    The number of characters read
         */
        int read(char *buf, int n) {
            int i = 1, rst = 0;
            for ( ; i; i = read4(buf), buf += i, rst += i);
            return min(n, rst + i);
        }
    };
    ``

Log in to reply
 

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