Skip to content

Commit 517cde1

Browse files
committed
docs: add problem description for 295
1 parent deb87eb commit 517cde1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/hard/readme.md

+35
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,38 @@ Put the code below in main.rs and run `cargo run`
383383
let result = leetcode::hard::sliding_window_maximum::max_sliding_window(nums, k);
384384
println!("result: {:?}", result);
385385
```
386+
387+
# 295. Find Median from Data Stream
388+
389+
## Description
390+
391+
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.
392+
393+
- For example, for arr = [2,3,4], the median is 3.
394+
- For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.
395+
396+
Implement the MedianFinder class:
397+
398+
- MedianFinder() initializes the MedianFinder object.
399+
- void addNum(int num) adds the integer num from the data stream to the data structure.
400+
- double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.
401+
402+
## Examples
403+
404+
Example 1:
405+
406+
```rust
407+
Input
408+
["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]
409+
[[], [1], [2], [], [3], []]
410+
Output
411+
[null, null, null, 1.5, null, 2.0]
412+
413+
Explanation
414+
MedianFinder medianFinder = new MedianFinder();
415+
medianFinder.addNum(1); // arr = [1]
416+
medianFinder.addNum(2); // arr = [1, 2]
417+
medianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)
418+
medianFinder.addNum(3); // arr[1, 2, 3]
419+
medianFinder.findMedian(); // return 2.0
420+
```

0 commit comments

Comments
 (0)