Movatterモバイル変換


[0]ホーム

URL:


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

Commit543d427

Browse files
authored
Update Read N characters Given Read4.java
1 parent5be1437 commit543d427

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* The read4 API is defined in the parent class Reader4.
3-
* int read4(char[]buf);
3+
* int read4(char[]buf4);
44
*/
55

66
publicclassSolutionextendsReader4 {
@@ -10,17 +10,19 @@ public class Solution extends Reader4 {
1010
* @return The number of actual characters read
1111
*/
1212
publicintread(char[]buf,intn) {
13-
booleanendOfFile =false;
14-
inttotalLength =0;
15-
char[]temp =newchar[4];
16-
while (!endOfFile &&totalLength <n) {
17-
intcount =read4(temp);
18-
endOfFile =count <4;
19-
count =Math.min(count,n -totalLength);
20-
for (inti =0;i <count;i++) {
21-
buf[totalLength++] =temp[i];
13+
intcopied =0;
14+
intreadLength =4;
15+
char[]buf4 =newchar[4];
16+
while (copied <n &&readLength ==4) {
17+
readLength =read4(buf4);
18+
for (inti =0;i <readLength;i++) {
19+
if (copied ==n) {
20+
returncopied;
21+
}
22+
buf[copied] =buf4[i];
23+
copied++;
2224
}
2325
}
24-
returntotalLength;
26+
returncopied;
2527
}
2628
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp