Skip to content

Commit e7d61b5

Browse files
committed
正则表达式
1 parent 824c0d1 commit e7d61b5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build ignore
2+
3+
#pragma once
4+
#include <queue>
5+
#include <string>
6+
7+
using namespace std;
8+
#include "TreeNode.hpp"
9+
#include "bfsTravelsal.hpp"
10+
11+
#include <iostream>
12+
#include <iterator>
13+
#include <regex>
14+
#include <sstream>
15+
std::string LeetCodeTreeNodeToString(TreeNode *root) {
16+
stringstream sstream;
17+
auto result = bfsTravelsal(root);
18+
std::regex vowel_re("(,null){1,}\\]$");
19+
20+
std::regex_replace(std::ostreambuf_iterator<char>(sstream), result.begin(),
21+
result.end(), vowel_re, "]");
22+
return sstream.str();
23+
}

insert-into-a-binary-search-tree/test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
using namespace std;
2020
#include "EqualTreeNode.hpp"
2121
#include "HashTreeNode.hpp"
22-
#include "bfsTravelsal.hpp"
22+
// #include "bfsTravelsal.hpp"
2323
#include "debugTreeNode.hpp"
2424
#include "printTreeNode.hpp"
2525
#include "treeparse.hpp"
26+
#include "LeetCodeTreeNodeToString.hpp"
2627

2728
void println(string s) { cout << s << endl; }
2829

@@ -103,7 +104,7 @@ class StringTest : public CppUnit::TestFixture {
103104
CPPUNIT_ASSERT_EQUAL(0, status);
104105

105106
printTreeNode(root);
106-
std::string result = bfsTravelsal(root);
107+
std::string result = LeetCodeTreeNodeToString(root);
107108

108109
println(result);
109110
cleanTreeNode(root);

0 commit comments

Comments
 (0)