Skip to content

Commit 2fcac78

Browse files
committed
add code
1 parent 267771f commit 2fcac78

File tree

5 files changed

+828
-22
lines changed

5 files changed

+828
-22
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ dev:
88
cd web && npm run dev
99

1010
build:
11+
make code2db
1112
cd web && npm run build
1213

1314
build-only:
14-
cd web && npm run build-only
15+
make code2db
16+
cd web && npm run build-only
17+
18+
rm:
19+
rm -rf docs/assets && rm -rf docs/index.html && rm -rf docs/logo.png

code/284.顶端迭代器.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @lc app=leetcode.cn id=284 lang=cpp
3+
*
4+
* [284] 顶端迭代器
5+
*/
6+
7+
// @lc code=start
8+
/*
9+
* Below is the interface for Iterator, which is already defined for you.
10+
* **DO NOT** modify the interface for Iterator.
11+
*
12+
* class Iterator {
13+
* struct Data;
14+
* Data* data;
15+
* public:
16+
* Iterator(const vector<int>& nums);
17+
* Iterator(const Iterator& iter);
18+
*
19+
* // Returns the next element in the iteration.
20+
* int next();
21+
*
22+
* // Returns true if the iteration has more elements.
23+
* bool hasNext() const;
24+
* };
25+
*/
26+
27+
class PeekingIterator : public Iterator {
28+
private:
29+
bool isHas = false;
30+
int nextData;
31+
public:
32+
PeekingIterator(const vector<int>& nums) : Iterator(nums) {
33+
// Initialize any member here.
34+
// **DO NOT** save a copy of nums and manipulate it directly.
35+
// You should only use the Iterator interface methods.
36+
isHas = Iterator::hasNext();
37+
if (isHas) {
38+
nextData = Iterator::next();
39+
}
40+
}
41+
42+
// Returns the next element in the iteration without advancing the iterator.
43+
int peek() {
44+
return nextData;
45+
}
46+
47+
// hasNext() and next() should behave the same as in the Iterator interface.
48+
// Override them if needed.
49+
int next() {
50+
isHas = Iterator::hasNext();
51+
int d = nextData;
52+
if (isHas) {
53+
nextData = Iterator::next();
54+
}
55+
return d;
56+
}
57+
58+
bool hasNext() const {
59+
return isHas;
60+
}
61+
};
62+
// @lc code=end
63+

code/287.寻找重复数.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @lc app=leetcode.cn id=287 lang=cpp
3+
*
4+
* [287] 寻找重复数
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public:
10+
int findDuplicate(vector<int>& nums) {
11+
int low = 0;
12+
int fast = 0;
13+
do {
14+
low = nums[low];
15+
fast = nums[nums[fast]];
16+
} while (low != fast);
17+
low = 0;
18+
while (low != fast) {
19+
low = nums[low];
20+
fast = nums[fast];
21+
}
22+
return low;
23+
}
24+
};
25+
// @lc code=end
26+

0 commit comments

Comments
 (0)