Skip to content

Commit 31563f8

Browse files
committed
Read N Characters Given Read 4 II
1 parent 3eb9680 commit 31563f8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @typedf read4
3+
* @param {character[]} buf Destination buffer
4+
* @return {number} The number of characters read
5+
* read4 = function(buf4) {
6+
* ...
7+
* };
8+
*/
9+
10+
/**
11+
* @param {function} read4()
12+
* @return {function}
13+
*/
14+
const solution = read4 => {
15+
const temp = [];
16+
17+
/**
18+
* @param {character[]} buf Destination buffer.
19+
* @param {number} n Number of characters to read.
20+
* @return {number} The number of actual characters read.
21+
* @summary Read N Characters Given Read4 II - Call multiple times {@link https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/}
22+
* @description
23+
* Space O() -
24+
* Time O() -
25+
*/
26+
return (buf, n) => {
27+
while (n) {
28+
if (!temp.length) read4(temp);
29+
if (!temp.length) return;
30+
buf.push(temp.shift());
31+
n--;
32+
}
33+
};
34+
};

0 commit comments

Comments
 (0)