Short cpp solution


  • 0
    P
    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 = 0,step=0;
            while(i<n && (step=read4(buf+i))) i += step;
            if(i>n) buf[n]='\n';
            return min(i,n);
        }
    };

Log in to reply
 

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