From e711e64e07be9376c44b2dd5a17b199aff2acdd0 Mon Sep 17 00:00:00 2001 From: Electrominch <64524860+Electrominch@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:48:48 +0300 Subject: [PATCH] Clear --- 118. Pascal's Triangle/Program.cs | 2 +- 118. Pascal's Triangle/Solution.cs | 10 +++++----- 142. Linked List Cycle II/Solution.cs | 6 +++--- .../Program.cs | 2 +- .../Solution.cs | 4 ++-- 189. Rotate Array/Program.cs | 2 +- 189. Rotate Array/Solution.cs | 4 ++-- 240. Search a 2D Matrix II/Program.cs | 2 +- 283. Move Zeroes/Solution.cs | 2 +- 36. Valid Sudoku/Solution.cs | 14 +++++++------- 409. Longest Palindrome/Solution.cs | 10 +++++----- 566. Reshape the Matrix/Program.cs | 4 ++-- 566. Reshape the Matrix/Solution.cs | 2 +- 74. Search a 2D Matrix/Program.cs | 2 +- 876. Middle of the Linked List/Program.cs | 4 ++-- 876. Middle of the Linked List/Solution.cs | 2 +- 977. Squares of a Sorted Array/Program.cs | 2 +- 977. Squares of a Sorted Array/Solution.cs | 16 ++++++++-------- 18 files changed, 45 insertions(+), 45 deletions(-) diff --git a/118. Pascal's Triangle/Program.cs b/118. Pascal's Triangle/Program.cs index b825b8b..f7ca310 100644 --- a/118. Pascal's Triangle/Program.cs +++ b/118. Pascal's Triangle/Program.cs @@ -5,7 +5,7 @@ static void Main(string[] args) { var res = new Solution().Generate(300); - foreach(var r in res) + foreach (var r in res) Console.WriteLine(String.Join(" ", r)); } } diff --git a/118. Pascal's Triangle/Solution.cs b/118. Pascal's Triangle/Solution.cs index 1dd9941..42c8ebb 100644 --- a/118. Pascal's Triangle/Solution.cs +++ b/118. Pascal's Triangle/Solution.cs @@ -5,19 +5,19 @@ public class Solution public IList> Generate(int numRows) { List> triangle = new List>() { new List { 1 } }; - if(numRows > 1) - triangle.Add(new List() { 1,1 }); + if (numRows > 1) + triangle.Add(new List() { 1, 1 }); numRows -= 2; while (numRows-- > 0) { IList prev = triangle[^1]; int nextCount = prev.Count; List row = new List() { 1 }; - for(int i = 1; i < nextCount; i++) + for (int i = 1; i < nextCount; i++) { - row.Add(prev[i-1] + prev[i]); + row.Add(prev[i - 1] + prev[i]); } - row.Add(1); + row.Add(1); triangle.Add(row); } diff --git a/142. Linked List Cycle II/Solution.cs b/142. Linked List Cycle II/Solution.cs index f973b8d..6c792cb 100644 --- a/142. Linked List Cycle II/Solution.cs +++ b/142. Linked List Cycle II/Solution.cs @@ -4,16 +4,16 @@ public class Solution { public ListNode? DetectCycle(ListNode head) { - if(head == null) + if (head == null) return null; ListNode? cur = head; int bit = 1 << 28; int curAbs = 0; - while (cur!=null && (curAbs & bit) == 0) + while (cur != null && (curAbs & bit) == 0) { cur.val ^= bit; cur = cur.next; - if(cur != null) + if (cur != null) curAbs = cur.val < 0 ? (cur.val * -1) : cur.val; } cur = head; diff --git a/167. Two Sum II - Input Array Is Sorted/Program.cs b/167. Two Sum II - Input Array Is Sorted/Program.cs index 48cf9cd..8024f33 100644 --- a/167. Two Sum II - Input Array Is Sorted/Program.cs +++ b/167. Two Sum II - Input Array Is Sorted/Program.cs @@ -4,7 +4,7 @@ { static void Main(string[] args) { - var arr = new int[] { -2,-3,4 }; + var arr = new int[] { -2, -3, 4 }; var res = new Solution().TwoSum(arr, -5); Console.WriteLine(String.Join(" ", res)); } diff --git a/167. Two Sum II - Input Array Is Sorted/Solution.cs b/167. Two Sum II - Input Array Is Sorted/Solution.cs index 13259e1..ac01a0c 100644 --- a/167. Two Sum II - Input Array Is Sorted/Solution.cs +++ b/167. Two Sum II - Input Array Is Sorted/Solution.cs @@ -4,7 +4,7 @@ public class Solution { public int[]? TwoSum(int[] numbers, int target) { - for(int i = 0; i < numbers.Length; i++) + for (int i = 0; i < numbers.Length; i++) { int cur = numbers[i]; int nextTar = target - cur; @@ -14,7 +14,7 @@ public class Solution int val = numbers[index]; if (cur + val == target) { - if(i>index) + if (i > index) { i = i + index; index = i - index; diff --git a/189. Rotate Array/Program.cs b/189. Rotate Array/Program.cs index e8a6065..23e38f3 100644 --- a/189. Rotate Array/Program.cs +++ b/189. Rotate Array/Program.cs @@ -4,7 +4,7 @@ { static void Main(string[] args) { - var arr = new int[] { 1, 2, 3, 4, 5, 6}; + var arr = new int[] { 1, 2, 3, 4, 5, 6 }; new Solution().Rotate(arr, 3); Console.WriteLine(String.Join(" ", arr)); } diff --git a/189. Rotate Array/Solution.cs b/189. Rotate Array/Solution.cs index 2aebe2d..8c6ad8d 100644 --- a/189. Rotate Array/Solution.cs +++ b/189. Rotate Array/Solution.cs @@ -7,7 +7,7 @@ public class Solution k %= nums.Length; if (k == 0) return; - int oneCycleLen = nums.Length/ GCD(nums.Length, k); + int oneCycleLen = nums.Length / GCD(nums.Length, k); for (int i = 0; i < nums.Length / oneCycleLen; i++) MoveTo(nums, nums[i], i + k, k, oneCycleLen); } @@ -30,5 +30,5 @@ public class Solution return b == 0 ? a : GCD(b, a % b); } - + } diff --git a/240. Search a 2D Matrix II/Program.cs b/240. Search a 2D Matrix II/Program.cs index 01973cb..2eb5b48 100644 --- a/240. Search a 2D Matrix II/Program.cs +++ b/240. Search a 2D Matrix II/Program.cs @@ -4,7 +4,7 @@ { static void Main(string[] args) { - int[][] matrix = new int[][] { new int[] { 1, 1,1,1 } }; + int[][] matrix = new int[][] { new int[] { 1, 1, 1, 1 } }; Console.WriteLine(new Solution().SearchMatrix(matrix, 2)); } } diff --git a/283. Move Zeroes/Solution.cs b/283. Move Zeroes/Solution.cs index 83a89bf..f1fd4f7 100644 --- a/283. Move Zeroes/Solution.cs +++ b/283. Move Zeroes/Solution.cs @@ -4,7 +4,7 @@ public class Solution { public void MoveZeroes(int[] nums) { - for(int i = 0; i < nums.Length-1; i++) + for (int i = 0; i < nums.Length - 1; i++) { if (nums[i] != 0) continue; diff --git a/36. Valid Sudoku/Solution.cs b/36. Valid Sudoku/Solution.cs index e8e0a5d..3f5cde5 100644 --- a/36. Valid Sudoku/Solution.cs +++ b/36. Valid Sudoku/Solution.cs @@ -14,7 +14,7 @@ public class Solution HashSet rowSet = new HashSet(); foreach (char c in row) { - if(c != '.') + if (c != '.') { int prevCount = rowSet.Count; rowSet.Add(c); @@ -28,10 +28,10 @@ public class Solution private bool CheckColumns(char[][] board) { - for(int columnIndex = 0; columnIndex < board[0].Length; columnIndex++) + for (int columnIndex = 0; columnIndex < board[0].Length; columnIndex++) { HashSet column = new HashSet(); - for(int rowIndex = 0; rowIndex < board[columnIndex].Length; rowIndex++) + for (int rowIndex = 0; rowIndex < board[columnIndex].Length; rowIndex++) { char ch = board[rowIndex][columnIndex]; if (ch != '.') @@ -48,7 +48,7 @@ public class Solution private bool CheckSubBoxes(char[][] board) { - for(int i = 0; i < 27; i+=3) + for (int i = 0; i < 27; i += 3) { int y = i / 9 * 3; int x = i % 9; @@ -61,12 +61,12 @@ public class Solution private bool CheckSubBox(char[][] board, int startY, int startX) { HashSet set = new HashSet(); - for (int y = startY; y < startY+3; y++) + for (int y = startY; y < startY + 3; y++) { - for(int x = startX; x < startX+3; x++) + for (int x = startX; x < startX + 3; x++) { char ch = board[y][x]; - if(ch!='.') + if (ch != '.') { int prev = set.Count; set.Add(ch); diff --git a/409. Longest Palindrome/Solution.cs b/409. Longest Palindrome/Solution.cs index 39fe09c..465b016 100644 --- a/409. Longest Palindrome/Solution.cs +++ b/409. Longest Palindrome/Solution.cs @@ -5,21 +5,21 @@ public class Solution public int LongestPalindrome(string s) { Dictionary dict = new Dictionary(); - foreach(var ch in s) + foreach (var ch in s) { - if(dict.ContainsKey(ch)) + if (dict.ContainsKey(ch)) dict[ch]++; else dict.Add(ch, 1); } int sum = 0; bool hasOdd = false; - foreach(var v in dict.Values) + foreach (var v in dict.Values) { sum += v / 2; - if(v % 2 == 1) + if (v % 2 == 1) hasOdd = true; } - return sum*2 + (hasOdd ? 1 : 0); + return sum * 2 + (hasOdd ? 1 : 0); } } diff --git a/566. Reshape the Matrix/Program.cs b/566. Reshape the Matrix/Program.cs index 23c81f6..5a588ef 100644 --- a/566. Reshape the Matrix/Program.cs +++ b/566. Reshape the Matrix/Program.cs @@ -4,8 +4,8 @@ { static void Main(string[] args) { - var res = new Solution().MatrixReshape(new int[][] { new int[] { 1,2 }, new int[] { 4, 5 } }, 2, 4); - foreach(var row in res) + var res = new Solution().MatrixReshape(new int[][] { new int[] { 1, 2 }, new int[] { 4, 5 } }, 2, 4); + foreach (var row in res) Console.WriteLine(String.Join(" ", row)); } } diff --git a/566. Reshape the Matrix/Solution.cs b/566. Reshape the Matrix/Solution.cs index fa6359d..a9d22cf 100644 --- a/566. Reshape the Matrix/Solution.cs +++ b/566. Reshape the Matrix/Solution.cs @@ -13,7 +13,7 @@ public class Solution int size = r * c; if (size != height * width) return mat; - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) { int ySource = i / width; int xSource = i % width; diff --git a/74. Search a 2D Matrix/Program.cs b/74. Search a 2D Matrix/Program.cs index 3b81f46..86b3eed 100644 --- a/74. Search a 2D Matrix/Program.cs +++ b/74. Search a 2D Matrix/Program.cs @@ -4,7 +4,7 @@ { static void Main(string[] args) { - int[][] matrix = new int[][] { new int[] { 1 }}; + int[][] matrix = new int[][] { new int[] { 1 } }; Console.WriteLine(new Solution().SearchMatrix(matrix, 1)); } } diff --git a/876. Middle of the Linked List/Program.cs b/876. Middle of the Linked List/Program.cs index 072856e..bbca776 100644 --- a/876. Middle of the Linked List/Program.cs +++ b/876. Middle of the Linked List/Program.cs @@ -4,8 +4,8 @@ { static void Main(string[] args) { - var l1 = ListNode.Create(new int[] { 1,2,3,4,5}); - var l2 = ListNode.Create(new int[] { 1,2,3,4,5,6}); + var l1 = ListNode.Create(new int[] { 1, 2, 3, 4, 5 }); + var l2 = ListNode.Create(new int[] { 1, 2, 3, 4, 5, 6 }); Console.WriteLine(new Solution().MiddleNode(l1).val); Console.WriteLine(new Solution().MiddleNode(l2).val); } diff --git a/876. Middle of the Linked List/Solution.cs b/876. Middle of the Linked List/Solution.cs index 5ec21b1..8c47c74 100644 --- a/876. Middle of the Linked List/Solution.cs +++ b/876. Middle of the Linked List/Solution.cs @@ -5,7 +5,7 @@ public class Solution public ListNode MiddleNode(ListNode? head) { ListNode result = head!; - while(head?.next != null) + while (head?.next != null) { head = head?.next?.next; result = result!.next!; diff --git a/977. Squares of a Sorted Array/Program.cs b/977. Squares of a Sorted Array/Program.cs index 7ea5d78..bdea960 100644 --- a/977. Squares of a Sorted Array/Program.cs +++ b/977. Squares of a Sorted Array/Program.cs @@ -4,7 +4,7 @@ { static void Main(string[] args) { - var res = new Solution().SortedSquares(new int[] { -7, -2,-1 }); + var res = new Solution().SortedSquares(new int[] { -7, -2, -1 }); Console.WriteLine(String.Join(" ", res)); } } diff --git a/977. Squares of a Sorted Array/Solution.cs b/977. Squares of a Sorted Array/Solution.cs index b69ae1b..73658ac 100644 --- a/977. Squares of a Sorted Array/Solution.cs +++ b/977. Squares of a Sorted Array/Solution.cs @@ -6,7 +6,7 @@ public class Solution { int[] res = new int[nums.Length]; int firstNonNegative = -1; - for(int i = 0; i < nums.Length; i++) + for (int i = 0; i < nums.Length; i++) { if (nums[i] >= 0) { @@ -17,12 +17,12 @@ public class Solution int resIndex = 0; int positiveIndex = firstNonNegative; - int negativeIndex = firstNonNegative!=-1 ? positiveIndex - 1 : nums.Length-1; - while(resIndex < nums.Length) + int negativeIndex = firstNonNegative != -1 ? positiveIndex - 1 : nums.Length - 1; + while (resIndex < nums.Length) { - if(negativeIndex>=0 && positiveIndex < nums.Length && positiveIndex>=0) + if (negativeIndex >= 0 && positiveIndex < nums.Length && positiveIndex >= 0) { - if (nums[negativeIndex]*-1 < nums[positiveIndex]) + if (nums[negativeIndex] * -1 < nums[positiveIndex]) { res[resIndex++] = nums[negativeIndex] * nums[negativeIndex]; negativeIndex--; @@ -33,12 +33,12 @@ public class Solution positiveIndex++; } } - else if(negativeIndex >= 0) + else if (negativeIndex >= 0) { - res[resIndex++] = nums[negativeIndex]* nums[negativeIndex]; + res[resIndex++] = nums[negativeIndex] * nums[negativeIndex]; negativeIndex--; } - else if(positiveIndex >= 0) + else if (positiveIndex >= 0) { res[resIndex++] = nums[positiveIndex] * nums[positiveIndex]; positiveIndex++;