代码拉取完成,页面将自动刷新
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode() : val(0), left(nullptr), right(nullptr) {}
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};
int findBottomLeftValue(TreeNode* root) {
queue<TreeNode*>q;
int number = 0;
if (root)
{
q.push(root);
number = 1;
}
vector<vector<int>> vv;
while (!q.empty())
{
vector<int>v;
for (int i = 0; i < number; ++i)
{
TreeNode* front = q.front();
v.push_back(front->val);
if (front->left)
q.push(front->left);
if (front->right)
q.push(front->right);
q.pop();
}
vv.push_back(v);
number = q.size();
}
int row = vv.size();
return vv[row][0];
}
int main()
{
TreeNode* n1 = new TreeNode(1);
TreeNode* n2 = new TreeNode(2);
TreeNode* n3 = new TreeNode(3);
TreeNode* n4 = new TreeNode(4);
TreeNode* n5 = new TreeNode(5);
TreeNode* n6 = new TreeNode(6);
TreeNode* n7 = new TreeNode(7);
n1->left = n2;
n1->right = n3;
n2->left = n4;
n3->left = n5;
n3->right = n6;
n5->left = n6;
findBottomLeftValue(n1);
return 0;
}
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
// * TreeNode() : val(0), left(nullptr), right(nullptr) {}
// * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
// * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
// * };
// */
//class Solution {
//
//public:
// vector<int> largestValues(TreeNode* root) {
// queue<TreeNode*> q;
// size_t levelSize = 0;
// if (root)
// {
// q.push(root);
// levelSize = 1;
// }
// vector<vector<int>> vv;
// while (!q.empty())
// {
// vector<int>v;
// for (int i = 0; i < levelSize; ++i)
// {
// TreeNode* front = q.front();
// v.push_back(front->val);
// if (front->left)
// q.push(front->left);
// if (front->right)
// q.push(front->right);
// q.pop();
// }
// vv.push_back(v);
// //当前层出完了,下一层也都进入,更改levelSize
// levelSize = q.size();
// }
// vector<int> ret;
// for (size_t i = 0; i < vv.size(); i++)
// {
// int max = vv[i][0];
// for (size_t j = 0; j < vv[i].size(); j++)
// {
// if (max < vv[i][j])
//// {
//// max = vv[i][j];
//// }
//// }
//// ret.push_back(max);
//// }
//// return ret;
//
//
//
//
// }
//};
////#include <iostream>
////#include <string>
////using namespace std;
////
////
////string replaceSpaces(string s, int length) {
//// string str(s, length);
//// string ret;
//// int sz = str.size();
//// for (auto& e : str)
//// {
//// if (e == ' ')
//// {
//// ret += "%20";
//// }
//// else
//// {
//// ret += e;
//// }
//// }
//// int diff = length - sz;
//// while (diff--)
// {
// ret += "%20";
// }
// return ret;
//}
//#include<vector>
//
//int main() {
//
// vector<int> a = { 1,2,3,4,5 };
//
// auto e=a.erase(a.begin());
//
//
// int n=0;
// //cin >> n;
// //while (n--)
// //{
// // getline(cin, str,'\n');
// // if (str.size() <= 10)
// // {
// // cout << str << endl;
// // }
// // else
// // {
// // size_t len = str.size();
// // len -= 2;
// // cout << str[0] << len << str[str.size() - 1] << endl;
// // }
// //}
// return 0;
//}
//// 64 位输出请用 printf("%lld")
////#include <stdio.h>
////#include<string.h>
////#include<stdio.h>
////char* f(char* str, char ch)
////{
//// char* it1 = str;
//// char* it2 = str;
//// while (*it2 != '\0')
//// {
//// while (*it2 == ch)
//// {
//// it2++;
//// }
//// *it1++ = *it2++;
//// }
//// return str;
////}
////int main() {
//// char a[10];
//// strcpy(a, "abcdcccd");
//// printf("%s", f(a, 'c'));
//// return 0;
////}
//////int main()
//////{
////// char p1[15] = "abcd", p2[] = "ABCD", str[50] = "xyz";
////// strcpy(str + 2, strcat(p1 + 2, p2 + 1));
////// printf("%s", str);
////// return 0;
//////}
////
//////int main()
//////{
//////
////// char a[] = "abcd";
////// char* p = a;
////// char ch = (*p)++;
////// printf("%c\n", ch);
////// printf("%s", a);
//////
////// //const char* str[3] = { "stra", "strb", "strc" };
////// //const char* p = str[0];
////// //int i = 0;
////// //while (i < 3)
////// //{
////// // printf("%s ", p++);
////// // i++;
////// //}
////// return 0;
//////}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。