C++_Accepted_0ms


  • 0
    // 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 res = 0;
        while(res < n){
            int r4 = read4(buf);
            if(r4 == 4){res += r4;}
            else{
                res += r4;
                break;
            }
            buf += r4;
        }
        return min(res,n);
    }
    };

Log in to reply
 

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