Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #386

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

Merged
pull merged 9 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
11 changes: 11 additions & 0 deletions problems/0112.路径总和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,17 @@ impl Solution {
}
}

```
### C#
```C#
// 0112.路径总和
// 递归
public bool HasPathSum(TreeNode root, int targetSum)
{
if (root == null) return false;
if (root.left == null && root.right == null && targetSum == root.val) return true;
return HasPathSum(root.left, targetSum - root.val) || HasPathSum(root.right, targetSum - root.val);
}
```

<p align="center">
Expand Down
37 changes: 37 additions & 0 deletions problems/0257.二叉树的所有路径.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,43 @@ impl Solution {
}
}
```
### C#
```C#
public IList<string> BinaryTreePaths(TreeNode root)
{
List<int> path = new();
List<string> res = new();
if (root == null) return res;
Traversal(root, path, res);
return res;
}
public void Traversal(TreeNode node, List<int> path, List<string> res)
{
path.Add(node.val);
if (node.left == null && node.right == null)
{
string sPath = "";
for (int i = 0; i < path.Count - 1; i++)
{
sPath += path[i].ToString();
sPath += "->";
}
sPath += path[path.Count - 1].ToString();
res.Add(sPath);
return;
}
if (node.left != null)
{
Traversal(node.left, path, res);
path.RemoveAt(path.Count-1);
}
if (node.right != null)
{
Traversal(node.right, path, res);
path.RemoveAt(path.Count-1);
}
}
```

<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
Expand Down
17 changes: 17 additions & 0 deletions problems/0404.左叶子之和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,23 @@ impl Solution {
}
}
```
### C#
```C#
// 递归
public int SumOfLeftLeaves(TreeNode root)
{
if (root == null) return 0;

int leftValue = SumOfLeftLeaves(root.left);
if (root.left != null && root.left.left == null && root.left.right == null)
{
leftValue += root.left.val;
}
int rightValue = SumOfLeftLeaves(root.right);
return leftValue + rightValue;

}
```

<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
Expand Down
32 changes: 32 additions & 0 deletions problems/0513.找树左下角的值.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,38 @@ impl Solution {
}
}
```
### C#
```C#
//递归
int maxDepth = -1;
int res = 0;
public int FindBottomLeftValue(TreeNode root)
{
Traversal(root, 0);
return res;
}
public void Traversal(TreeNode root, int depth)
{
if (root.left == null && root.right == null)
{
if (depth > maxDepth)
{
maxDepth = depth;
res = root.val;
}
return;
}
if (root.left != null)
{
Traversal(root.left, depth + 1);
}
if (root.right != null)
{
Traversal(root.right, depth + 1);
}
return;
}
```

<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
Expand Down

AltStyle によって変換されたページ (->オリジナル) /