Skip to content

Commit be9ad01

Browse files
committed
3 problems
1 parent c0e298d commit be9ad01

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

README.md

+3
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool increasingTriplet(vector<int>& nums) {
4+
if (nums.size() < 3) return false;
5+
int first = nums[0], second = INT_MAX;
6+
for (int i = 1; i < nums.size(); ++i) {
7+
if (nums[i] > second) return true;
8+
else if (nums[i] < first) first= nums[i];
9+
else if (nums[i] > first && nums[i] < second) second = nums[i];
10+
}
11+
return false;
12+
}
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
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+
void DFS(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

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
bool isSelfCrossing(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+
return true;
8+
if(i>=4 && x[i-1]==x[i-3] && x[i]+x[i-4]>=x[i-2])
9+
return true;
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+
return true;
12+
}
13+
return false;
14+
}
15+
};

0 commit comments

Comments
 (0)