Simple C++ solution


  • 0
    J
    class Solution {
    public:
        int read(char *buf, int n) {
            if(buf == NULL) return 0;
    
            int t = 0;        
            for(int i = 0; i<=n/4; i++)
                t += read4(buf + i*4);
    
            if(n>t)
            {
                buf[t] = NULL;
                return t;
            }
            
            return n;
        }
    };

Log in to reply
 

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