diff --git a/2023-10-23/.vs/2023-10-23/FileContentIndex/a020f529-fbc6-4896-81c7-f1c8c58a89e4.vsidx b/2023-10-23/.vs/2023-10-23/FileContentIndex/a020f529-fbc6-4896-81c7-f1c8c58a89e4.vsidx new file mode 100644 index 0000000..fdcc012 Binary files /dev/null and b/2023-10-23/.vs/2023-10-23/FileContentIndex/a020f529-fbc6-4896-81c7-f1c8c58a89e4.vsidx differ diff --git a/2023-10-23/.vs/2023-10-23/FileContentIndex/b79fa703-fc4f-42c4-a75c-1150044685f2.vsidx b/2023-10-23/.vs/2023-10-23/FileContentIndex/b79fa703-fc4f-42c4-a75c-1150044685f2.vsidx new file mode 100644 index 0000000..95971ee Binary files /dev/null and b/2023-10-23/.vs/2023-10-23/FileContentIndex/b79fa703-fc4f-42c4-a75c-1150044685f2.vsidx differ diff --git a/2023-10-23/.vs/2023-10-23/v17/.suo b/2023-10-23/.vs/2023-10-23/v17/.suo new file mode 100644 index 0000000..d2b10aa Binary files /dev/null and b/2023-10-23/.vs/2023-10-23/v17/.suo differ diff --git a/2023-10-23/.vs/2023-10-23/v17/Browse.VC.db b/2023-10-23/.vs/2023-10-23/v17/Browse.VC.db new file mode 100644 index 0000000..2aa45ad Binary files /dev/null and b/2023-10-23/.vs/2023-10-23/v17/Browse.VC.db differ diff --git a/2023-10-23/.vs/2023-10-23/v17/ipch/AutoPCH/c28d28c9aafeb402/源.ipch b/2023-10-23/.vs/2023-10-23/v17/ipch/AutoPCH/c28d28c9aafeb402/源.ipch new file mode 100644 index 0000000..0f7f558 Binary files /dev/null and b/2023-10-23/.vs/2023-10-23/v17/ipch/AutoPCH/c28d28c9aafeb402/源.ipch differ diff --git a/2023-10-23/2023-10-23.sln b/2023-10-23/2023-10-23.sln new file mode 100644 index 0000000..3b8a07b --- /dev/null +++ b/2023-10-23/2023-10-23.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34018.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2023-10-23", "2023-10-23.vcxproj", "{DDE1957C-AB2A-4B80-9928-5904DAD85FE3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Debug|x64.ActiveCfg = Debug|x64 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Debug|x64.Build.0 = Debug|x64 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Debug|x86.ActiveCfg = Debug|Win32 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Debug|x86.Build.0 = Debug|Win32 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Release|x64.ActiveCfg = Release|x64 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Release|x64.Build.0 = Release|x64 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Release|x86.ActiveCfg = Release|Win32 + {DDE1957C-AB2A-4B80-9928-5904DAD85FE3}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {07A85C73-522E-4FAD-964D-381906ACE172} + EndGlobalSection +EndGlobal diff --git a/2023-10-23/2023-10-23.vcxproj b/2023-10-23/2023-10-23.vcxproj new file mode 100644 index 0000000..665f59c --- /dev/null +++ b/2023-10-23/2023-10-23.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {dde1957c-ab2a-4b80-9928-5904dad85fe3} + My20231023 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/2023-10-23/2023-10-23.vcxproj.filters b/2023-10-23/2023-10-23.vcxproj.filters new file mode 100644 index 0000000..5324d35 --- /dev/null +++ b/2023-10-23/2023-10-23.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/2023-10-23/2023-10-23.vcxproj.user b/2023-10-23/2023-10-23.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/2023-10-23/2023-10-23.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2023-10-23/x64/Debug/2023-10-23.exe b/2023-10-23/x64/Debug/2023-10-23.exe new file mode 100644 index 0000000..cc59507 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.exe differ diff --git a/2023-10-23/x64/Debug/2023-10-23.exe.recipe b/2023-10-23/x64/Debug/2023-10-23.exe.recipe new file mode 100644 index 0000000..b75fb45 --- /dev/null +++ b/2023-10-23/x64/Debug/2023-10-23.exe.recipe @@ -0,0 +1,11 @@ + + + + + D:\vs代码\2023-10-23\x64\Debug\2023-10-23.exe + + + + + + \ No newline at end of file diff --git a/2023-10-23/x64/Debug/2023-10-23.ilk b/2023-10-23/x64/Debug/2023-10-23.ilk new file mode 100644 index 0000000..83e5207 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.ilk differ diff --git a/2023-10-23/x64/Debug/2023-10-23.log b/2023-10-23/x64/Debug/2023-10-23.log new file mode 100644 index 0000000..8309953 --- /dev/null +++ b/2023-10-23/x64/Debug/2023-10-23.log @@ -0,0 +1,5 @@ + 源.cpp +D:\vs代码\2023-10-23\源.cpp(224,19): warning C4267: “=”: 从“size_t”转换到“int”,可能丢失数据 +D:\vs代码\2023-10-23\源.cpp(226,18): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 +D:\vs代码\2023-10-23\源.cpp(232): warning C4715: “my_Deserialize”: 不是所有的控件路径都返回值 + 2023-10-23.vcxproj -> D:\vs代码\2023-10-23\x64\Debug\2023-10-23.exe diff --git a/2023-10-23/x64/Debug/2023-10-23.pdb b/2023-10-23/x64/Debug/2023-10-23.pdb new file mode 100644 index 0000000..1512efe Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.pdb differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/2023-10-23.lastbuildstate b/2023-10-23/x64/Debug/2023-10-23.tlog/2023-10-23.lastbuildstate new file mode 100644 index 0000000..72ebeb9 --- /dev/null +++ b/2023-10-23/x64/Debug/2023-10-23.tlog/2023-10-23.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.37.32822:TargetPlatformVersion=10.0.22621.0: +Debug|x64|D:\vs代码\2023-10-23\| diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/CL.command.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.command.1.tlog new file mode 100644 index 0000000..67831ab Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.command.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/CL.read.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.read.1.tlog new file mode 100644 index 0000000..bacf116 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.read.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/CL.write.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.write.1.tlog new file mode 100644 index 0000000..2944a01 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/CL.write.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/Cl.items.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/Cl.items.tlog new file mode 100644 index 0000000..cb52d91 --- /dev/null +++ b/2023-10-23/x64/Debug/2023-10-23.tlog/Cl.items.tlog @@ -0,0 +1 @@ +D:\vs代码\2023-10-23\源.cpp;D:\vs代码\2023-10-23\x64\Debug\源.obj diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/link.command.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/link.command.1.tlog new file mode 100644 index 0000000..773e4a3 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/link.command.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/link.read.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/link.read.1.tlog new file mode 100644 index 0000000..ffb3225 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/link.read.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.tlog/link.write.1.tlog b/2023-10-23/x64/Debug/2023-10-23.tlog/link.write.1.tlog new file mode 100644 index 0000000..deefd18 Binary files /dev/null and b/2023-10-23/x64/Debug/2023-10-23.tlog/link.write.1.tlog differ diff --git a/2023-10-23/x64/Debug/2023-10-23.vcxproj.FileListAbsolute.txt b/2023-10-23/x64/Debug/2023-10-23.vcxproj.FileListAbsolute.txt new file mode 100644 index 0000000..c30ac32 --- /dev/null +++ b/2023-10-23/x64/Debug/2023-10-23.vcxproj.FileListAbsolute.txt @@ -0,0 +1 @@ +D:\vs代码\2023-10-23\x64\Debug\2023-10-23.exe diff --git a/2023-10-23/x64/Debug/vc143.idb b/2023-10-23/x64/Debug/vc143.idb new file mode 100644 index 0000000..89d18f3 Binary files /dev/null and b/2023-10-23/x64/Debug/vc143.idb differ diff --git a/2023-10-23/x64/Debug/vc143.pdb b/2023-10-23/x64/Debug/vc143.pdb new file mode 100644 index 0000000..0b01453 Binary files /dev/null and b/2023-10-23/x64/Debug/vc143.pdb differ diff --git a/2023-10-23/x64/Debug/源.obj b/2023-10-23/x64/Debug/源.obj new file mode 100644 index 0000000..9f8f8f1 Binary files /dev/null and b/2023-10-23/x64/Debug/源.obj differ diff --git a/2023-10-23/源.cpp b/2023-10-23/源.cpp new file mode 100644 index 0000000..5db8a99 --- /dev/null +++ b/2023-10-23/源.cpp @@ -0,0 +1,247 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + + + struct TreeNode { + int val; + struct TreeNode *left; + struct TreeNode *right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + }; + + class IsBalanced_Solution_Node { + public: + IsBalanced_Solution_Node(int min=INT_MAX,int max=INT_MIN,int high = 0,bool is_balance=true) + :_min(min),_max(max),_high(high),_is_balance(is_balance) + {} + int _min; + int _max; + int _high; + bool _is_balance; + }; + + IsBalanced_Solution_Node my_IsBalanced_Solution(TreeNode* root) { + //nullptrҪҪ + if (root == nullptr) { + return IsBalanced_Solution_Node(); + } + IsBalanced_Solution_Node left = my_IsBalanced_Solution(root->left); + IsBalanced_Solution_Node right = my_IsBalanced_Solution(root->right); + int min = root->val; + int max = root->val; + int high = 1; + bool is_balance = true; + if (left._is_balance == false || right._is_balance == false + || std::abs(left._high - right._high) > 1) { + is_balance = false; + } + if (left._high != 0) { + min = left._min < min ? left._min : ( min); + } + if (right._high != 0) { + max = right._max > max ? right._max : (max); + } + high = std::max(left._high, right._high) + 1; + return IsBalanced_Solution_Node(min, max, high, is_balance); + } + // жDzƽ + bool IsBalanced_Solution(TreeNode* pRoot) { + // write code here + if (pRoot == nullptr) { + return true; + } + return my_IsBalanced_Solution(pRoot)._is_balance; + } + + + class lowestCommonAncestor_Node { + public: + lowestCommonAncestor_Node(TreeNode*root = nullptr) + :node(root){} + TreeNode* node; + + }; + TreeNode* sum_node = nullptr; + lowestCommonAncestor_Node my_lowestCommonAncestor(TreeNode* root, int p, int q) { + if (root == nullptr) { + return lowestCommonAncestor_Node(); + } + lowestCommonAncestor_Node left = my_lowestCommonAncestor(root->left,p,q); + lowestCommonAncestor_Node right = my_lowestCommonAncestor(root->right, p, q); + //ǰĽӵֿܣ + //ǰĽڵp + //ǰĽڵq + //ǰĽڵʲôǣǹĸڵ + //ǰĽڵʲôҲ + TreeNode* re = nullptr; + if (left.node == nullptr && right.node == nullptr) { + if (root->val == q || root->val == p) { + return lowestCommonAncestor_Node(root); + } + } + if (left.node != nullptr && right.node != nullptr) { + sum_node = root; + return lowestCommonAncestor_Node(); + } + if (left.node != nullptr) { + if (root->val == p && left.node->val == q) { + sum_node = root; + return lowestCommonAncestor_Node(); + } + if (root->val == q && left.node->val == p) { + sum_node = root; + return lowestCommonAncestor_Node(); + } + re = left.node; + } + if (right.node != nullptr) { + if (root->val == p && right.node->val == q) { + sum_node = root; + return lowestCommonAncestor_Node(); + } + if (root->val == q && right.node->val == p) { + sum_node = root; + return lowestCommonAncestor_Node(); + } + re = right.node; + } + return lowestCommonAncestor_Node(re); + } + // + int aalowestCommonAncestor(TreeNode* root, int p, int q) { + // write code here + //һŶڵ㣬ǸĽڵ + //ַ𰸣һֱӵݹҪĴ𰸣 + // һDzò鼯 + //ȲõݹķʽĽڵ㣬ٲò鼯IJ + sum_node = nullptr; + my_lowestCommonAncestor(root, p, q); + return sum_node->val; + } + + class Union { + public: + void put(int father, int child) { + if (get_father(father) == -1) { + father_map[father] = father; + } + if (get_father(child) == -1) { + father_map[child] = child; + } + father_map[child] = get_father(father); + } + int get_father(int child) { + if (father_map.count(child) == 0) { + return -1; + } + queuequ; + int father = child; + qu.push(father); + while (father != father_map[father]) { + father = father_map[father]; + qu.push(father); + } + while (!qu.empty()) { + father_map[qu.front()] = father; + qu.pop(); + } + return father; + } + unordered_mapfather_map; + +}; + + int re = -1; + Union un; +void my_union_lowestCommonAncestor(TreeNode* root, int p, int q) { + if (re != -1) { + return; + } + if (root != nullptr) { + //ÿֻڵݹ֮󣬾ͽIJ + //ݹ֮ͽ͵ǰڵϲ + my_union_lowestCommonAncestor(root->left, q, p); + if (root->left != nullptr) { + un.put(root->val, root->left->val); + } + if (root->val == q && un.get_father(p) != -1) { + re = un.get_father(p); + } + if(root->val == p && un.get_father(q) != -1) { + re = un.get_father(q); + } + + + my_union_lowestCommonAncestor(root->right, q, p); + if (root->right != nullptr) { + un.put(root->val, root->right->val); + } + if (root->val == q && un.get_father(p) != -1) { + re = un.get_father(p); + } + if(root->val == p && un.get_father(q) != -1) { + re = un.get_father(q); + } + + } +} + //ò鼯ķʽв + // + int lowestCommonAncestor(TreeNode* root, int o1, int o2) { + // write code here + my_union_lowestCommonAncestor(root, o1, o2); + return re; + } + + void my_Serialize(TreeNode* root, string& str) { + if (root == nullptr) { + str.append("#"); + } + else { + str.append('{'+ to_string(root->val) + '}'); + my_Serialize(root->left, str); + my_Serialize(root->right, str); + } + } + //л + char* Serialize(TreeNode* root) { + string str; + my_Serialize(root, str); + + return const_cast(str.c_str()); + } + + TreeNode* my_Deserialize( string& str, int& index) { + if (str[index] == '#') { + index++; + return nullptr; + } + index = str.find('{', index); + index = index + 1; + int next_index = str.find('}', index); + + TreeNode* cur = new TreeNode(atoi(str.substr(index, next_index).c_str())); + index = next_index + 1; + cur->left = my_Deserialize(str, index); + cur->right = my_Deserialize(str, index); + } + + //л + TreeNode* Deserialize(char* str) { + int index = 0; + string ss(str); + return my_Deserialize( ss,index); + } + +int main() { + TreeNode* root = new TreeNode(1); + root->left = new TreeNode(2); + root->right = new TreeNode(3); + + return 0; +} \ No newline at end of file