Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions Week_03/id_86/LeetCode_104_086.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgorithmTest
{
class LeetCode_104_086
{
public int MaxDepth(TreeNode root)
{
if (root == null) return 0;
return Math.Max(MaxDepth(root.left), MaxDepth(root.right)) + 1;
}
}
}
42 changes: 42 additions & 0 deletions Week_03/id_86/LeetCode_429_086.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgorithmTest
{
class LeetCode_429_086
{
public IList<IList<int>> LevelOrder(Node root)
{
IList<IList<int>> result = new List<IList<int>>();

if (root != null)
{
var q = new Queue<Node>();
q.Enqueue(root);

while (q.Count != 0)
{
int num = q.Count;
IList<int> r = new List<int>();

for (int i = 0; i < num; i++)
{
Node n = q.Dequeue();
r.Add(n.val);
foreach (Node c in n.children)
{
q.Enqueue(c);
}
}
result.Add(r);
}
}
return result;
}
}
}


40 changes: 40 additions & 0 deletions Week_04/id_86/LeetCode_169_086.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgorithmTest
{
class LeetCode_169_086
{
public int MethodFor169_1(int[] num)
{
int n = num[0];
int count = 1;

for (int i = 1; i < num.Length; i++)
{
if (count == 0)
{
count++;
n = num[i];
}
else if (n == num[i])
{
count++;
}
else count--;

}
return n;
}

//直接调用 Array.Sort
public int MethodFor169_2(int[] num)
{
Array.Sort(num);
return num[num.Length / 2];
}
}
}
21 changes: 21 additions & 0 deletions Week_04/id_86/LeetCode_746_086.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgorithmTest
{
class LeetCode_746_086
{
public int MethodFor746_1(int[] cost)
{
for (int i = 2; i < cost.Length; i++)
{
cost[i] += Math.Min(cost[i - 2], cost[i - 1]);
}

return Math.Min(cost[cost.Length - 1], cost[cost.Length - 2]);
}
}
}