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

Commitd03cae6

Browse files
flatten 2d vector
1 parente356669 commitd03cae6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
packagemedium;
2+
3+
importjava.util.Iterator;
4+
importjava.util.LinkedList;
5+
importjava.util.List;
6+
importjava.util.Queue;
7+
8+
publicclassFlatten2DVector {
9+
10+
}
11+
12+
classVector2DimplementsIterator<Integer> {
13+
privateQueue<Integer>cache;
14+
privateList<List<Integer>>vec2d;
15+
16+
publicVector2D(List<List<Integer>>vec2d) {
17+
this.vec2d =vec2d;
18+
this.cache =newLinkedList<Integer>();
19+
if(vec2d !=null &&vec2d.size() >0){
20+
for(List<Integer>list :vec2d){
21+
for(inti :list){
22+
cache.offer(i);
23+
}
24+
}
25+
}
26+
}
27+
28+
@Override
29+
publicIntegernext() {
30+
returncache.poll();
31+
}
32+
33+
@Override
34+
publicbooleanhasNext() {
35+
return !cache.isEmpty();
36+
}
37+
}
38+

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
|259|[3Sum Smaller](https://leetcode.com/problems/3sum-smaller/)|[Solution](../../blob/master/MEDIUM/src/medium/_3Sum_Smaller.java)| O(n^2)|O(1)| Medium|
6464
|257|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)|[Solution](../../blob/master/EASY/src/easy/BinaryTreePaths.java) | O(n*h) | O(h) | DFS/Recursion
6565
|252|[Meeting Rooms](https://leetcode.com/problems/meeting-rooms/)|[Solution](../../blob/master/EASY/src/easy/MeetingRooms.java)| O(nlogn)| O(1)|
66+
|251|[Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector/)|[Solution](../../blob/master/MEDIUM/src/medium/Flatten2DVector.java)| O(1)|O(m*n)| Medium|
6667
|250|[Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees/)|[Solution](../../blob/master/MEDIUM/src/medium/CountUnivalueSubtrees.java)| O(n)|O(h) | Medium| DFS
6768
|249|[Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings/)|[Solution](../../blob/master/EASY/src/easy/GroupShiftedStrings.java)| O(nlogn)| O(n)|
6869
|246|[Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number/)|[Solution](../../blob/master/EASY/src/easy/StrobogrammaticNumber.java)| O(n)| O(1)|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp