/* The read4 API is defined in the parent class Reader4.
int read4(char[] buf); */
public class Solution extends Reader4 {
/**
* @param buf Destination buffer
* @param n Maximum number of characters to read
* @return The number of characters read
*/
public int read(char[] buf, int n) {
char[] temp = new char[4];
int total = 0;
boolean flag = true;
while (flag && total < n) {
int count = read4(temp);
if (count == 0) {
flag = false;
}
count = Math.min(count, n - total);
for (int i = 0; i < count; i++) {
buf[total++] = temp[i];
}
}
return total;
}
}
Read N Characters Given Read4
最新推荐文章于 2021-08-05 13:53:38 发布