Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 31563f8

Browse files
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
Lines changed: 34 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /