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

Commitbe9ad01

Browse files
committed
3 problems
1 parentc0e298d commitbe9ad01

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
237237
####[327. Count of Range Sum](https://github.com/hitzzc/go-leetcode/tree/master/count_of_range_sum)
238238
####[329. Longest Increasing Path in a Matrix](https://github.com/hitzzc/go-leetcode/tree/master/longest_increasing_path_in_a_matrix)
239239
####[331. Verify Preorder Serialization of a Binary Tree](https://github.com/hitzzc/go-leetcode/tree/master/verify_preorder_serialization_of_a_binary_tree)
240+
####[332. Reconstruct Itinerary](https://github.com/hitzzc/go-leetcode/tree/master/reconstruct_ltinerary)
241+
####[334. Increasing Triplet Subsequence](https://github.com/hitzzc/go-leetcode/tree/master/increasing_triplet_subsequence)
242+
####[335. Self Crossing](https://github.com/hitzzc/go-leetcode/tree/master/self_crossing)
240243

241244

242245

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
classSolution {
2+
public:
3+
boolincreasingTriplet(vector<int>& nums) {
4+
if (nums.size() <3)returnfalse;
5+
int first = nums[0], second = INT_MAX;
6+
for (int i =1; i < nums.size(); ++i) {
7+
if (nums[i] > second)returntrue;
8+
elseif (nums[i] < first) first= nums[i];
9+
elseif (nums[i] > first && nums[i] < second) second = nums[i];
10+
}
11+
returnfalse;
12+
}
13+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
classSolution {
2+
public:
3+
vector<string>findItinerary(vector<pair<string, string>> tickets) {
4+
unordered_map<string, multiset<string>> graph;
5+
for (auto& kv: tickets) {
6+
graph[kv.first].insert(kv.second);
7+
}
8+
vector<string> solution;
9+
DFS(graph, solution,"JFK");
10+
return vector<string>(solution.rbegin(), solution.rend());
11+
}
12+
voidDFS(unordered_map<string, multiset<string>>& graph, vector<string>& solution, string start) {
13+
while (!graph[start].empty()) {
14+
string city = *graph[start].begin();
15+
graph[start].erase(city);
16+
(DFS(graph, solution, city));
17+
}
18+
solution.push_back(start);
19+
return;
20+
}
21+
};

‎self_crossing/self_crossing.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
classSolution {
2+
public:
3+
boolisSelfCrossing(vector<int>& x) {
4+
int m = x.size();
5+
for(int i=0; i<m; ++i){
6+
if(i>=3 && x[i]>=x[i-2] && x[i-3]>=x[i-1])
7+
returntrue;
8+
if(i>=4 && x[i-1]==x[i-3] && x[i]+x[i-4]>=x[i-2])
9+
returntrue;
10+
if(i>=5 && x[i-3]>x[i-1] && x[i-2]>x[i-4] && x[i]+x[i-4]>=x[i-2] && x[i-1]+x[i-5]>=x[i-3])
11+
returntrue;
12+
}
13+
returnfalse;
14+
}
15+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp