chore(cs): format

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-03-15 17:22:58 +01:00
parent 09d5c6dc4e
commit 4763cdbdda
Signed by: mfocko
GPG key ID: 7C47D46246790496
4 changed files with 63 additions and 75 deletions

View file

@ -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;

View file

@ -1,10 +1,8 @@
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.val = val;
this.left = left; this.left = left;
this.right = right; this.right = right;
@ -12,40 +10,32 @@
} }
public class Solution public class Solution {
{ private class Level {
private class Level
{
long sum; long sum;
int counter; int counter;
public Level() public Level() {
{
sum = 0; sum = 0;
counter = 0; counter = 0;
} }
public void Add(int x) public void Add(int x) {
{
sum += x; sum += x;
counter++; counter++;
} }
public double Average public double Average {
{
get => sum / (double)counter; get => sum / (double)counter;
} }
} }
private List<Level> AverageOfLevels(List<Level> averages, TreeNode? node, int level) private List<Level> AverageOfLevels(List<Level> averages, TreeNode? node, int level) {
{ if (node == null) {
if (node == null)
{
return averages; return averages;
} }
if (level == averages.Count) if (level == averages.Count) {
{
averages.Add(new Level()); averages.Add(new Level());
} }
averages[level].Add(node.val); averages[level].Add(node.val);
@ -59,12 +49,10 @@ public class Solution
public IList<double> AverageOfLevels(TreeNode? root) public IList<double> AverageOfLevels(TreeNode? root)
=> AverageOfLevels(new List<Level>(), root, 0).Select(level => level.Average).ToList(); => AverageOfLevels(new List<Level>(), root, 0).Select(level => level.Average).ToList();
public static void Main() public static void Main() {
{
var s = new Solution(); 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))))) 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.Write($"{a} ");
} }
Console.WriteLine(); Console.WriteLine();

View file

@ -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];

View file

@ -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));
} }
} }