My C++ solution: same idea but not using n/4


  • 0
    W
    int read(char *buf, int n) {
        int res = 0;
        for (int i = 0; i < n; i += 4) {
            res += read4(buf+ res);
        }
        if (res > n) {
            return n;
        } else {
            return res;
        }
    }

Log in to reply
 

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