A simple Java solution


  • 1
    J
      public int read(char[] buf, int n) {
    	int count = 0;
    	char[] buf4 = new char[4];
        for (int i = 0; i <= n/4; i++) {
        	int len = read4(buf4);
        	if (count + len < n) {
        		System.arraycopy(buf4, 0, buf, count, len);
        		count += len;
        	} else {
        		System.arraycopy(buf4, 0, buf, count, n-count);
        		count = n;
        	}
        }
        return count;
    }

Log in to reply
 

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