From 4763cdbdda7be22d5f5d866e93b82340e7099c95 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 15 Mar 2024 17:22:58 +0100 Subject: [PATCH] chore(cs): format Signed-off-by: Matej Focko --- cs/arithmetic-slices-ii-subsequence.cs | 2 +- cs/average-of-levels-in-binary-tree.cs | 132 +++++++++++-------------- cs/n-th-tribonacci-number.cs | 2 +- cs/poor-pigs.cs | 2 +- 4 files changed, 63 insertions(+), 75 deletions(-) diff --git a/cs/arithmetic-slices-ii-subsequence.cs b/cs/arithmetic-slices-ii-subsequence.cs index 8ede65e..2545cdb 100644 --- a/cs/arithmetic-slices-ii-subsequence.cs +++ b/cs/arithmetic-slices-ii-subsequence.cs @@ -17,7 +17,7 @@ public class Solution { for (var i = 1; i < n; ++i) { for (var j = 0; j < i; ++j) { - var diff = (long) nums[i] - nums[j]; + var diff = (long)nums[i] - nums[j]; if (diff < int.MinValue || diff > int.MaxValue) { continue; diff --git a/cs/average-of-levels-in-binary-tree.cs b/cs/average-of-levels-in-binary-tree.cs index f2ba5aa..c2f6379 100644 --- a/cs/average-of-levels-in-binary-tree.cs +++ b/cs/average-of-levels-in-binary-tree.cs @@ -1,72 +1,60 @@ -public class TreeNode -{ - public int val; - public TreeNode? left; - public TreeNode? right; - public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null) - { - this.val = val; - this.left = left; - this.right = right; - } -} - - -public class Solution -{ - private class Level - { - long sum; - int counter; - - public Level() - { - sum = 0; - counter = 0; - } - - public void Add(int x) - { - sum += x; - counter++; - } - - public double Average - { - get => sum / (double)counter; - } - } - - private List AverageOfLevels(List averages, TreeNode? node, int level) - { - if (node == null) - { - return averages; - } - - if (level == averages.Count) - { - averages.Add(new Level()); - } - averages[level].Add(node.val); - - AverageOfLevels(averages, node.left, level + 1); - AverageOfLevels(averages, node.right, level + 1); - - return averages; - } - - public IList AverageOfLevels(TreeNode? root) - => AverageOfLevels(new List(), root, 0).Select(level => level.Average).ToList(); - - public static void Main() - { - var s = new Solution(); - - foreach (var a in s.AverageOfLevels(new TreeNode(3, new TreeNode(9), new TreeNode(20, new TreeNode(15), new TreeNode(7))))) - { - Console.Write($"{a} "); - } - Console.WriteLine(); - } -} +public class TreeNode { + public int val; + public TreeNode? left; + public TreeNode? right; + public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null) { + this.val = val; + this.left = left; + this.right = right; + } +} + + +public class Solution { + private class Level { + long sum; + int counter; + + public Level() { + sum = 0; + counter = 0; + } + + public void Add(int x) { + sum += x; + counter++; + } + + public double Average { + get => sum / (double)counter; + } + } + + private List AverageOfLevels(List averages, TreeNode? node, int level) { + if (node == null) { + return averages; + } + + if (level == averages.Count) { + averages.Add(new Level()); + } + averages[level].Add(node.val); + + AverageOfLevels(averages, node.left, level + 1); + AverageOfLevels(averages, node.right, level + 1); + + return averages; + } + + public IList AverageOfLevels(TreeNode? root) + => AverageOfLevels(new List(), root, 0).Select(level => level.Average).ToList(); + + public static void Main() { + var s = new Solution(); + + foreach (var a in s.AverageOfLevels(new TreeNode(3, new TreeNode(9), new TreeNode(20, new TreeNode(15), new TreeNode(7))))) { + Console.Write($"{a} "); + } + Console.WriteLine(); + } +} diff --git a/cs/n-th-tribonacci-number.cs b/cs/n-th-tribonacci-number.cs index 98abbb6..2ddc17b 100644 --- a/cs/n-th-tribonacci-number.cs +++ b/cs/n-th-tribonacci-number.cs @@ -1,6 +1,6 @@ public class Solution { public int Tribonacci(int n) { - var sequence = new int[]{0, 1, 1}; + var sequence = new int[] { 0, 1, 1 }; if (n < 3) { return sequence[n]; diff --git a/cs/poor-pigs.cs b/cs/poor-pigs.cs index d5e8f20..129ecbc 100644 --- a/cs/poor-pigs.cs +++ b/cs/poor-pigs.cs @@ -1,5 +1,5 @@ public class Solution { public int PoorPigs(int buckets, int minutesToDie, int minutesToTest) { - return (int) Math.Ceiling(Math.Log(buckets) / Math.Log(1 + minutesToTest / minutesToDie)); + return (int)Math.Ceiling(Math.Log(buckets) / Math.Log(1 + minutesToTest / minutesToDie)); } }