Short 14 lines C++


  • 0
    class Solution {
    private:
        int p = 4;
        int i = 4;
        char tmp[4];
    public:
        int read(char *buf, int n) {
            int sum = 0;
            while(sum < n){
                if(p == i){
                    i = read4(tmp);
                    p = 0;
                }
                if(i == 0) break;
                *buf++ = tmp[p++];
                sum++;
            }
            return sum;
        }
    };
    

Log in to reply
 

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