由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Read-n-characters-given-read4 题目看不懂
相关主题
leetcode 的新题好像不太理解题意骑驴找马结束,分享面试题回馈贵版
read4 vs read4II 到底啥区别?我花了一个小时才调通过这个程序
another google interview question:一道微软题
一道google 题,谁给翻译一下意思,多谢。google interview question
FG题目包子求教--read4096what's the output
。。。一个c++问题求解,发50个包子一个Google面试题
请教个LC的新题一道program challenge的题
FB面经问道看到的面试题
相关话题的讨论汇总
话题: characters话题: read话题: read4话题: buf话题: example
进入JobHunting版参与讨论
1 (共1页)
P****e
发帖数: 56
1
https://leetcode.com/problems/read-n-characters-given-read4/description/
The API: int read4(char *buf) reads 4 characters at a time from a file.
The return value is the actual number of characters read. For example, it
returns 3 if there is only 3 characters left in the file.
By using the read4 API, implement the function int read(char *buf, int n)
that reads n characters from the file.
Example 1:
Input: buf = "abc", n = 4
Output: "abc"
Explanation: The actual number of characters read is 3, which is "abc".
Example 2:
Input: buf = "abcde", n = 5
Output: "abcde"
Note:
The read function will only be called once for each test case.
---
根据例子,直接返回输入字符本身不久得了?题目说“能不能解释一下这道题到底要我
们实现什么?
s**********g
发帖数: 14942
2
Example 3:
Input: buf="abcdef", n = 5
Output: "abcde"
l*******g
发帖数: 5
3
read4 一次最多读取4个char,如果不够4个char了就读一部分
比如abcde
read4 读出来是abcd,返回值是4
再次运行读出来e, 返回值是1
所以解法也是累加返回值

【在 P****e 的大作中提到】
: https://leetcode.com/problems/read-n-characters-given-read4/description/
: The API: int read4(char *buf) reads 4 characters at a time from a file.
: The return value is the actual number of characters read. For example, it
: returns 3 if there is only 3 characters left in the file.
: By using the read4 API, implement the function int read(char *buf, int n)
: that reads n characters from the file.
: Example 1:
: Input: buf = "abc", n = 4
: Output: "abc"
: Explanation: The actual number of characters read is 3, which is "abc".

1 (共1页)
进入JobHunting版参与讨论
相关主题
问个array in place operation的题目FG题目包子求教--read4096
急问一个面试题,不知该如何回答?请高人给个思路!谢谢!。。。一个c++问题求解,发50个包子
一个EDA的问题请教个LC的新题
请问A家onsite安排在什么时间比较合适。顺便一面面经。FB面经
leetcode 的新题好像不太理解题意骑驴找马结束,分享面试题回馈贵版
read4 vs read4II 到底啥区别?我花了一个小时才调通过这个程序
another google interview question:一道微软题
一道google 题,谁给翻译一下意思,多谢。google interview question
相关话题的讨论汇总
话题: characters话题: read话题: read4话题: buf话题: example