chore(cs): format
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
09d5c6dc4e
commit
4763cdbdda
4 changed files with 63 additions and 75 deletions
|
@ -17,7 +17,7 @@ public class Solution {
|
||||||
|
|
||||||
for (var i = 1; i < n; ++i) {
|
for (var i = 1; i < n; ++i) {
|
||||||
for (var j = 0; j < i; ++j) {
|
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) {
|
if (diff < int.MinValue || diff > int.MaxValue) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1,72 +1,60 @@
|
||||||
public class TreeNode
|
public class TreeNode {
|
||||||
{
|
public int val;
|
||||||
public int val;
|
public TreeNode? left;
|
||||||
public TreeNode? left;
|
public TreeNode? right;
|
||||||
public TreeNode? right;
|
public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null) {
|
||||||
public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null)
|
this.val = val;
|
||||||
{
|
this.left = left;
|
||||||
this.val = val;
|
this.right = right;
|
||||||
this.left = left;
|
}
|
||||||
this.right = right;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
public class Solution {
|
||||||
|
private class Level {
|
||||||
public class Solution
|
long sum;
|
||||||
{
|
int counter;
|
||||||
private class Level
|
|
||||||
{
|
public Level() {
|
||||||
long sum;
|
sum = 0;
|
||||||
int counter;
|
counter = 0;
|
||||||
|
}
|
||||||
public Level()
|
|
||||||
{
|
public void Add(int x) {
|
||||||
sum = 0;
|
sum += x;
|
||||||
counter = 0;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(int x)
|
public double Average {
|
||||||
{
|
get => sum / (double)counter;
|
||||||
sum += x;
|
}
|
||||||
counter++;
|
}
|
||||||
}
|
|
||||||
|
private List<Level> AverageOfLevels(List<Level> averages, TreeNode? node, int level) {
|
||||||
public double Average
|
if (node == null) {
|
||||||
{
|
return averages;
|
||||||
get => sum / (double)counter;
|
}
|
||||||
}
|
|
||||||
}
|
if (level == averages.Count) {
|
||||||
|
averages.Add(new Level());
|
||||||
private List<Level> AverageOfLevels(List<Level> averages, TreeNode? node, int level)
|
}
|
||||||
{
|
averages[level].Add(node.val);
|
||||||
if (node == null)
|
|
||||||
{
|
AverageOfLevels(averages, node.left, level + 1);
|
||||||
return averages;
|
AverageOfLevels(averages, node.right, level + 1);
|
||||||
}
|
|
||||||
|
return averages;
|
||||||
if (level == averages.Count)
|
}
|
||||||
{
|
|
||||||
averages.Add(new Level());
|
public IList<double> AverageOfLevels(TreeNode? root)
|
||||||
}
|
=> AverageOfLevels(new List<Level>(), root, 0).Select(level => level.Average).ToList();
|
||||||
averages[level].Add(node.val);
|
|
||||||
|
public static void Main() {
|
||||||
AverageOfLevels(averages, node.left, level + 1);
|
var s = new Solution();
|
||||||
AverageOfLevels(averages, node.right, level + 1);
|
|
||||||
|
foreach (var a in s.AverageOfLevels(new TreeNode(3, new TreeNode(9), new TreeNode(20, new TreeNode(15), new TreeNode(7))))) {
|
||||||
return averages;
|
Console.Write($"{a} ");
|
||||||
}
|
}
|
||||||
|
Console.WriteLine();
|
||||||
public IList<double> AverageOfLevels(TreeNode? root)
|
}
|
||||||
=> AverageOfLevels(new List<Level>(), 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
public class Solution {
|
public class Solution {
|
||||||
public int Tribonacci(int n) {
|
public int Tribonacci(int n) {
|
||||||
var sequence = new int[]{0, 1, 1};
|
var sequence = new int[] { 0, 1, 1 };
|
||||||
|
|
||||||
if (n < 3) {
|
if (n < 3) {
|
||||||
return sequence[n];
|
return sequence[n];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
public class Solution {
|
public class Solution {
|
||||||
public int PoorPigs(int buckets, int minutesToDie, int minutesToTest) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue