-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayGround.cs
More file actions
63 lines (51 loc) · 1.73 KB
/
PlayGround.cs
File metadata and controls
63 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataStructures.Libraries.Trees;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LeetCode.Recursion
{
[TestClass]
public class PlayGround
{
public double FindSumOfParentOfXValueInTree(BinaryTreeNode binaryTree, int x)
{
List<double> list = new List<double>();
this.SumParentOfXRecursive(binaryTree, null, x, list);
return list.Sum();
}
private void SumParentOfXRecursive(BinaryTreeNode binaryTree, BinaryTreeNode parent, int x, List<double> parentList)
{
if (binaryTree == null) return;
if (binaryTree.Value == x)
{
parentList.Add(parent.Value);
}
SumParentOfXRecursive(binaryTree.Left, binaryTree, x, parentList);
SumParentOfXRecursive(binaryTree.Right, binaryTree, x, parentList);
}
[TestMethod]
public void TestSumParentOfXRecursive()
{
BinaryTreeNode node = new BinaryTreeNode(4);
node.Left = new BinaryTreeNode(2);
node.Left.Left = new BinaryTreeNode(7);
node.Left.Right = new BinaryTreeNode(2);
node.Right = new BinaryTreeNode(5);
node.Right.Left = new BinaryTreeNode(2);
node.Right.Right = new BinaryTreeNode(3);
double answer = this.FindSumOfParentOfXValueInTree(node, 2);
Assert.AreEqual(answer, 11);
}
// find cheeze in the maze
public bool Recurse(int[,] maze)
{
return true;
}
public void TestRecurse()
{
}
}
}