Skip to content

Commit 8fb9ef7

Browse files
committed
commit changes to gh-page
1 parent f240fe2 commit 8fb9ef7

File tree

3 files changed

+38
-1
lines changed
  • _includes/_root/read-n-characters-given-read4-ii-call-multiple-times
  • read-n-characters-given-read4-ii-call-multiple-times

3 files changed

+38
-1
lines changed

_includes/_root/read-n-characters-given-read4-ii-call-multiple-times/README.md

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* The read4 API is defined in the parent class Reader4.
2+
int read4(char[] buf); */
3+
4+
public class Solution extends Reader4 {
5+
6+
LinkedList<Character> queue = new LinkedList<Character>();
7+
8+
/**
9+
* @param buf Destination buffer
10+
* @param n Maximum number of characters to read
11+
* @return The number of characters read
12+
*/
13+
public int read(char[] buf, int n) {
14+
15+
char[] _buf = new char[4];
16+
17+
int total = 0;
18+
19+
while(true){
20+
int l = read4(_buf);
21+
22+
for(int i = 0; i < l; i++){
23+
queue.add(_buf[i]);
24+
}
25+
26+
l = Math.min(n - total, queue.size());
27+
28+
for(int i = 0; i < l; i++){
29+
buf[total++] = queue.poll();
30+
}
31+
32+
if(l == 0) break;
33+
}
34+
35+
return total;
36+
}
37+
}

read-n-characters-given-read4-ii-call-multiple-times/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: solution
33
title: Read N Characters Given Read4 II - Call multiple times
4-
date: 2014-11-24 17:30:24+08:00
4+
date: 2014-11-24 17:31:29 +0800
55
---
66
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
77
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

0 commit comments

Comments
 (0)