Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cpp solution to lc problem: No.0332 #1776

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add cpp solution to lc problem: No.0332
  • Loading branch information
xzhseh committed Oct 10, 2023
commit 2a8491607e8f19be8a14469c8fea0b0b19b004ec
10 changes: 5 additions & 5 deletions solution/0300-0399/0332.Reconstruct Itinerary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class Solution {
```cpp
class Solution {
public:
std::vector<std::string> findItinerary(std::vector<std::vector<std::string>> &tickets) {
std::unordered_map<std::string, std::priority_queue<std::string, std::vector<std::string>, std::greater<std::string>>> g;
std::vector<std::string> ret;
vector<string> findItinerary(vector<vector<string>>& tickets) {
unordered_map<string, priority_queue<string, vector<string>, greater<string>>> g;
vector<string> ret;

// Initialize the graph
for (const auto &t : tickets) {
for (const auto& t : tickets) {
g[t[0]].push(t[1]);
}

Expand All @@ -119,7 +119,7 @@ public:
return ret;
}

void findItineraryInner(std::unordered_map<std::string, std::priority_queue<std::string, std::vector<std::string>, std::greater<std::string>>> &g, std::vector<std::string> &ret, std::string cur) {
void findItineraryInner(unordered_map<string, priority_queue<string, vector<string>, greater<string>>>& g, vector<string>& ret, string cur) {
if (g.count(cur) == 0) {
// This is the end point
ret.push_back(cur);
Expand Down
10 changes: 5 additions & 5 deletions solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ class Solution {
```cpp
class Solution {
public:
std::vector<std::string> findItinerary(std::vector<std::vector<std::string>> &tickets) {
std::unordered_map<std::string, std::priority_queue<std::string, std::vector<std::string>, std::greater<std::string>>> g;
std::vector<std::string> ret;
vector<string> findItinerary(vector<vector<string>>& tickets) {
unordered_map<string, priority_queue<string, vector<string>, greater<string>>> g;
vector<string> ret;

// Initialize the graph
for (const auto &t : tickets) {
for (const auto& t : tickets) {
g[t[0]].push(t[1]);
}

Expand All @@ -109,7 +109,7 @@ public:
return ret;
}

void findItineraryInner(std::unordered_map<std::string, std::priority_queue<std::string, std::vector<std::string>, std::greater<std::string>>> &g, std::vector<std::string> &ret, std::string cur) {
void findItineraryInner(unordered_map<string, priority_queue<string, vector<string>, greater<string>>>& g, vector<string>& ret, string cur) {
if (g.count(cur) == 0) {
// This is the end point
ret.push_back(cur);
Expand Down