Skip to content

Commit 01b66db

Browse files
committed
0513 solved.
1 parent ad37caa commit 01b66db

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_0513)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_0513 main.cpp)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// Source : https://leetcode.com/problems/find-bottom-left-tree-value/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-06-21
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <queue>
8+
9+
using namespace std;
10+
11+
12+
/// BFS
13+
/// Time Complexity: O(n)
14+
/// Space Complexity: O(n)
15+
16+
/// Definition for a binary tree node.
17+
struct TreeNode {
18+
int val;
19+
TreeNode *left;
20+
TreeNode *right;
21+
TreeNode() : val(0), left(nullptr), right(nullptr) {}
22+
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
23+
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
24+
};
25+
26+
class Solution {
27+
public:
28+
int findBottomLeftValue(TreeNode* root) {
29+
30+
int res = -1;
31+
queue<TreeNode*> q;
32+
q.push(root);
33+
while(!q.empty()){
34+
res = q.front()->val;
35+
queue<TreeNode*> tq;
36+
while(!q.empty()){
37+
TreeNode* node = q.front(); q.pop();
38+
if(node->left) tq.push(node->left);
39+
if(node->right) tq.push(node->right);
40+
}
41+
q = tq;
42+
}
43+
return res;
44+
}
45+
};
46+
47+
48+
int main() {
49+
50+
return 0;
51+
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
542542
| | | | | | |
543543
| 511 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
544544
| | | | | | |
545+
| 513 | [Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/) | [] | [C++](0501-1000/0513-Find-Bottom-Left-Tree-Value/cpp-0513/) | | |
546+
| | | | | | |
545547
| 516 | [Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) | [] | [C++](0501-1000/0516-Longest-Palindromic-Subsequence/cpp-0516/) | | |
546548
| 517 | [Super Washing Machines](https://leetcode.com/problems/super-washing-machines/) | [solution](https://leetcode.com/problems/super-washing-machines/solution/) | [C++](0501-1000/0517-Super-Washing-Machines/cpp-0517/) | | |
547549
| 518 | [Coin Change 2](https://leetcode.com/problems/coin-change-2/description/) | [] | [C++](0501-1000/0518-Coin-Change-2/cpp-0518/) | | |

0 commit comments

Comments
 (0)