Need help here

  • 0

    Hi, below is my code. I put comment bwn codes

    // Forward declaration of the read4 API.
    int read4(char *buf);
    class Solution {
         * @param buf Destination buffer
         * @param n   Maximum number of characters to read
         * @return    The number of characters read
        int read(char *buf, int n) {
            // tmp: actual number read for single read4 
            // actualRead:  actual number read for us on each read4
            // readLen: total actual number read for us 
            int tmp = 0, actualRead = 0, readLen = 0;
            char buffer[4];
            while (n > 0) {
                tmp = read4(buffer);
                actualRead = min(tmp, n);
                readLen += actualRead;
                //append buffer to buf
                strncat(buf, buffer, actualRead);
                if (actualRead < 4) break;
                n -= actualRead;
            return readLen;

    It has Runtime error for


    Could anyone help me here

Log in to reply

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