From b05f66d853a42afa17bb98963c2fdf65c3bcd6a8 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Thu, 4 Jan 2024 10:41:09 +0800 Subject: [PATCH 1/8] =?UTF-8?q?Update0406.=E6=A0=B9=E6=8D=AE=E5=AE=A1?= =?UTF-8?q?=E7=A8=BF=E9=87=8D=E5=BB=BA=E9=98=9F=E5=88=97=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0406.根据身高重建队列.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md index 9cd78fac..b0b02c14 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -396,6 +396,29 @@ object Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int[][] ReconstructQueue(int[][] people) + { + Array.Sort(people, (a, b) => + { + if (a[0] == b[0]) + { + return a[1] - b[1]; + } + return b[0] - a[0]; + }); + var res = new List(); + for (int i = 0; i < people.Length; i++) + { + res.Insert(people[i][1], people[i]); + } + return res.ToArray(); + } +} +```

From 709b5babf0c01f4aa35034ab45f948531e15964e Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Thu, 4 Jan 2024 11:12:29 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DC#=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=AB=98=E4=BA=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0005.最长回文子串.md | 4 ++-- problems/0017.电话号码的字母组合.md | 2 +- problems/0024.两两交换链表中的节点.md | 2 +- problems/0028.实现strStr.md | 2 +- ...组中查找元素的第一个和最后一个位置.md | 2 +- problems/0062.不同路径.md | 2 +- problems/0070.爬楼梯.md | 2 +- problems/0077.组合.md | 2 +- problems/0090.子集II.md | 2 +- problems/0098.验证二叉搜索树.md | 2 +- problems/0101.对称二叉树.md | 2 +- problems/0102.二叉树的层序遍历.md | 4 ++-- problems/0104.二叉树的最大深度.md | 6 +++--- .../0106.从中序与后序遍历序列构造二叉树.md | 2 +- problems/0110.平衡二叉树.md | 2 +- problems/0111.二叉树的最小深度.md | 4 ++-- problems/0112.路径总和.md | 2 +- problems/0151.翻转字符串里的单词.md | 2 +- problems/0222.完全二叉树的节点个数.md | 2 +- problems/0235.二叉搜索树的最近公共祖先.md | 2 +- problems/0236.二叉树的最近公共祖先.md | 2 +- problems/0257.二叉树的所有路径.md | 2 +- problems/0404.左叶子之和.md | 2 +- problems/0450.删除二叉搜索树中的节点.md | 2 +- problems/0459.重复的子字符串.md | 2 +- problems/0501.二叉搜索树中的众数.md | 2 +- problems/0509.斐波那契数.md | 4 ++-- problems/0513.找树左下角的值.md | 2 +- problems/0530.二叉搜索树的最小绝对差.md | 2 +- problems/0538.把二叉搜索树转换为累加树.md | 2 +- problems/0617.合并二叉树.md | 2 +- problems/0654.最大二叉树.md | 2 +- problems/0669.修剪二叉搜索树.md | 2 +- problems/0700.二叉搜索树中的搜索.md | 2 +- problems/0707.设计链表.md | 2 +- problems/0746.使用最小花费爬楼梯.md | 2 +- problems/二叉树的统一迭代法.md | 6 +++--- problems/二叉树的迭代遍历.md | 2 +- problems/二叉树的递归遍历.md | 6 +++--- problems/面试题02.07.链表相交.md | 2 +- 40 files changed, 50 insertions(+), 50 deletions(-) diff --git a/problems/0005.最长回文子串.md b/problems/0005.最长回文子串.md index 614f6051..b13f9ac3 100644 --- a/problems/0005.最长回文子串.md +++ b/problems/0005.最长回文子串.md @@ -618,7 +618,7 @@ char * longestPalindrome(char * s){ ### C#: 動態規則: -```c# +```csharp public class Solution { public string LongestPalindrome(string s) { @@ -648,7 +648,7 @@ public class Solution { ``` 雙指針: -```C# +```csharp public class Solution { int maxlenth = 0; int left = 0; diff --git a/problems/0017.电话号码的字母组合.md b/problems/0017.电话号码的字母组合.md index 8a16008a..cbd99f8d 100644 --- a/problems/0017.电话号码的字母组合.md +++ b/problems/0017.电话号码的字母组合.md @@ -733,7 +733,7 @@ def backtracking(result, letter_map, digits, path, index) end ``` ### C# -```C# +```csharp public class Solution { public IList res = new List(); diff --git a/problems/0024.两两交换链表中的节点.md b/problems/0024.两两交换链表中的节点.md index 405f4183..b2a830a7 100644 --- a/problems/0024.两两交换链表中的节点.md +++ b/problems/0024.两两交换链表中的节点.md @@ -462,7 +462,7 @@ impl Solution { ``` ### C# -```C# +```csharp // 虚拟头结点 public ListNode SwapPairs(ListNode head) { diff --git a/problems/0028.实现strStr.md b/problems/0028.实现strStr.md index bf4ad600..25b81799 100644 --- a/problems/0028.实现strStr.md +++ b/problems/0028.实现strStr.md @@ -1359,7 +1359,7 @@ impl Solution { ``` >前缀表统一不减一 -```C# +```csharp public int StrStr(string haystack, string needle) { if (string.IsNullOrEmpty(needle)) diff --git a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md index 3bf90e3b..22936fef 100644 --- a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md +++ b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md @@ -331,7 +331,7 @@ class Solution { ### C# -```c# +```csharp public int[] SearchRange(int[] nums, int target) { var leftBorder = GetLeftBorder(nums, target); diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md index b7ce542e..5131fdbb 100644 --- a/problems/0062.不同路径.md +++ b/problems/0062.不同路径.md @@ -537,7 +537,7 @@ object Solution { ### c# -```c# +```csharp public class Solution { public int UniquePaths(int m, int n) diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md index 7a59221d..d300683e 100644 --- a/problems/0070.爬楼梯.md +++ b/problems/0070.爬楼梯.md @@ -470,7 +470,7 @@ object Solution { ### C# -```c# +```csharp public class Solution { public int ClimbStairs(int n) { if(n<=2) return n; diff --git a/problems/0077.组合.md b/problems/0077.组合.md index 8bca6f24..103fb627 100644 --- a/problems/0077.组合.md +++ b/problems/0077.组合.md @@ -793,7 +793,7 @@ end ``` ### C# -```C# +```csharp // 暴力 public class Solution { diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md index 9fc334a4..1bb63a34 100644 --- a/problems/0090.子集II.md +++ b/problems/0090.子集II.md @@ -641,7 +641,7 @@ object Solution { } ``` ### C# -```c# +```csharp public class Solution { public IList> res = new List>(); diff --git a/problems/0098.验证二叉搜索树.md b/problems/0098.验证二叉搜索树.md index 319ad1aa..88e16282 100644 --- a/problems/0098.验证二叉搜索树.md +++ b/problems/0098.验证二叉搜索树.md @@ -792,7 +792,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public long val = Int64.MinValue; public bool IsValidBST(TreeNode root) diff --git a/problems/0101.对称二叉树.md b/problems/0101.对称二叉树.md index 1b777dd5..8442f0ab 100644 --- a/problems/0101.对称二叉树.md +++ b/problems/0101.对称二叉树.md @@ -898,7 +898,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public bool IsSymmetric(TreeNode root) { diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index e977279c..4411b560 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -463,7 +463,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public IList> LevelOrder(TreeNode root) { var res = new List>(); @@ -825,7 +825,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public IList> LevelOrderBottom(TreeNode root) { var res = new List>(); diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index b89dbf45..f4c6cfc8 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -1033,7 +1033,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归法 public int MaxDepth(TreeNode root) { if(root == null) return 0; @@ -1044,7 +1044,7 @@ public int MaxDepth(TreeNode root) { return 1 + Math.Max(leftDepth, rightDepth); } ``` -```C# +```csharp // 前序遍历 int result = 0; public int MaxDepth(TreeNode root) @@ -1065,7 +1065,7 @@ public void GetDepth(TreeNode root, int depth) return; } ``` -```C# +```csharp // 迭代法 public int MaxDepth(TreeNode root) { diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md index dc517480..0e0ab1d7 100644 --- a/problems/0106.从中序与后序遍历序列构造二叉树.md +++ b/problems/0106.从中序与后序遍历序列构造二叉树.md @@ -1229,7 +1229,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public TreeNode BuildTree(int[] inorder, int[] postorder) { if (inorder.Length == 0 || postorder.Length == null) return null; diff --git a/problems/0110.平衡二叉树.md b/problems/0110.平衡二叉树.md index 41669bff..40fdcd14 100644 --- a/problems/0110.平衡二叉树.md +++ b/problems/0110.平衡二叉树.md @@ -909,7 +909,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public bool IsBalanced(TreeNode root) { return GetHeight(root) == -1 ? false : true; diff --git a/problems/0111.二叉树的最小深度.md b/problems/0111.二叉树的最小深度.md index 46523349..6d1632d5 100644 --- a/problems/0111.二叉树的最小深度.md +++ b/problems/0111.二叉树的最小深度.md @@ -709,7 +709,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public int MinDepth(TreeNode root) { @@ -725,7 +725,7 @@ public int MinDepth(TreeNode root) return res; } ``` -```C# +```csharp // 迭代 public int MinDepth(TreeNode root) { diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index f1ce7637..28134a7c 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -1513,7 +1513,7 @@ impl Solution { ``` ### C# -```C# +```csharp // 0112.路径总和 // 递归 public bool HasPathSum(TreeNode root, int targetSum) diff --git a/problems/0151.翻转字符串里的单词.md b/problems/0151.翻转字符串里的单词.md index d15bb5f3..520f17a7 100644 --- a/problems/0151.翻转字符串里的单词.md +++ b/problems/0151.翻转字符串里的单词.md @@ -973,7 +973,7 @@ char * reverseWords(char * s){ ``` ### C# -```C# LINQ高级方法 +```csharp LINQ高级方法 public string ReverseWords(string s) { return string.Join(' ', s.Trim().Split(' ',StringSplitOptions.RemoveEmptyEntries).Reverse()); } diff --git a/problems/0222.完全二叉树的节点个数.md b/problems/0222.完全二叉树的节点个数.md index ef6e88aa..d93d2a33 100644 --- a/problems/0222.完全二叉树的节点个数.md +++ b/problems/0222.完全二叉树的节点个数.md @@ -868,7 +868,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public int CountNodes(TreeNode root) { diff --git a/problems/0235.二叉搜索树的最近公共祖先.md b/problems/0235.二叉搜索树的最近公共祖先.md index b27a231e..cec8a1dd 100644 --- a/problems/0235.二叉搜索树的最近公共祖先.md +++ b/problems/0235.二叉搜索树的最近公共祖先.md @@ -514,7 +514,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { diff --git a/problems/0236.二叉树的最近公共祖先.md b/problems/0236.二叉树的最近公共祖先.md index 0e99f1c2..049f70c7 100644 --- a/problems/0236.二叉树的最近公共祖先.md +++ b/problems/0236.二叉树的最近公共祖先.md @@ -432,7 +432,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null || root == p || root == q) return root; diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md index 9ba165c7..4c6c92c5 100644 --- a/problems/0257.二叉树的所有路径.md +++ b/problems/0257.二叉树的所有路径.md @@ -901,7 +901,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public IList BinaryTreePaths(TreeNode root) { List path = new(); diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md index 6dfcc886..3d0f5a8a 100644 --- a/problems/0404.左叶子之和.md +++ b/problems/0404.左叶子之和.md @@ -652,7 +652,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public int SumOfLeftLeaves(TreeNode root) { diff --git a/problems/0450.删除二叉搜索树中的节点.md b/problems/0450.删除二叉搜索树中的节点.md index 13c25023..8922a14e 100644 --- a/problems/0450.删除二叉搜索树中的节点.md +++ b/problems/0450.删除二叉搜索树中的节点.md @@ -772,7 +772,7 @@ impl Solution { ### C# > 递归法: -```C# +```csharp public TreeNode DeleteNode(TreeNode root, int key) { // 第一种情况:没找到删除的节点,遍历到空节点直接返回了 if (root == null) return null; diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index 3245d948..311e3a69 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -682,7 +682,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 前缀表不减一 public bool RepeatedSubstringPattern(string s) { diff --git a/problems/0501.二叉搜索树中的众数.md b/problems/0501.二叉搜索树中的众数.md index 5b26d580..20627d1a 100644 --- a/problems/0501.二叉搜索树中的众数.md +++ b/problems/0501.二叉搜索树中的众数.md @@ -1010,7 +1010,7 @@ pub fn find_mode(root: Option>>) -> Vec { } ``` ### C# -```C# +```csharp // 递归 public class Solution { diff --git a/problems/0509.斐波那契数.md b/problems/0509.斐波那契数.md index 0c073db5..71c022bd 100644 --- a/problems/0509.斐波那契数.md +++ b/problems/0509.斐波那契数.md @@ -439,7 +439,7 @@ object Solution { 动态规划: -```c# +```csharp public class Solution { public int Fib(int n) @@ -459,7 +459,7 @@ public class Solution 递归: -```c# +```csharp public class Solution { public int Fib(int n) diff --git a/problems/0513.找树左下角的值.md b/problems/0513.找树左下角的值.md index 0e2f4266..3cdcc801 100644 --- a/problems/0513.找树左下角的值.md +++ b/problems/0513.找树左下角的值.md @@ -685,7 +685,7 @@ impl Solution { } ``` ### C# -```C# +```csharp //递归 int maxDepth = -1; int res = 0; diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md index f08df577..82b3f5d4 100644 --- a/problems/0530.二叉搜索树的最小绝对差.md +++ b/problems/0530.二叉搜索树的最小绝对差.md @@ -648,7 +648,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public class Solution { diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md index 07cae1ad..7fcb5efd 100644 --- a/problems/0538.把二叉搜索树转换为累加树.md +++ b/problems/0538.把二叉搜索树转换为累加树.md @@ -530,7 +530,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public class Solution { diff --git a/problems/0617.合并二叉树.md b/problems/0617.合并二叉树.md index 9efeb56d..3478a2af 100644 --- a/problems/0617.合并二叉树.md +++ b/problems/0617.合并二叉树.md @@ -789,7 +789,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public TreeNode MergeTrees(TreeNode root1, TreeNode root2) { if (root1 == null) return root2; diff --git a/problems/0654.最大二叉树.md b/problems/0654.最大二叉树.md index 6b343840..f54558a6 100644 --- a/problems/0654.最大二叉树.md +++ b/problems/0654.最大二叉树.md @@ -583,7 +583,7 @@ impl Solution { } ``` ### C# -```C# +```csharp public TreeNode ConstructMaximumBinaryTree(int[] nums) { if (nums.Length == 0) return null; diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md index 229a2ab1..916013c5 100644 --- a/problems/0669.修剪二叉搜索树.md +++ b/problems/0669.修剪二叉搜索树.md @@ -568,7 +568,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public TreeNode TrimBST(TreeNode root, int low, int high) { diff --git a/problems/0700.二叉搜索树中的搜索.md b/problems/0700.二叉搜索树中的搜索.md index 65e69219..9efb1e05 100644 --- a/problems/0700.二叉搜索树中的搜索.md +++ b/problems/0700.二叉搜索树中的搜索.md @@ -465,7 +465,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 递归 public TreeNode SearchBST(TreeNode root, int val) { diff --git a/problems/0707.设计链表.md b/problems/0707.设计链表.md index a08227d9..fecdbc3c 100644 --- a/problems/0707.设计链表.md +++ b/problems/0707.设计链表.md @@ -1486,7 +1486,7 @@ impl MyLinkedList { ``` ### C# -```C# +```csharp class ListNode { public int val; diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index 6fb518c3..d13ff19f 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -500,7 +500,7 @@ object Solution { ### C# -```c# +```csharp public class Solution { public int MinCostClimbingStairs(int[] cost) diff --git a/problems/二叉树的统一迭代法.md b/problems/二叉树的统一迭代法.md index ad79424d..ee4899b1 100644 --- a/problems/二叉树的统一迭代法.md +++ b/problems/二叉树的统一迭代法.md @@ -742,7 +742,7 @@ impl Solution{ } ``` ### C# -```C# +```csharp // 前序遍历 public IList PreorderTraversal(TreeNode root) { @@ -772,7 +772,7 @@ public IList PreorderTraversal(TreeNode root) return res; } ``` -```C# +```csharp // 中序遍历 public IList InorderTraversal(TreeNode root) { @@ -803,7 +803,7 @@ public IList InorderTraversal(TreeNode root) } ``` -```C# +```csharp // 后序遍历 public IList PostorderTraversal(TreeNode root) { diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md index e39709b8..35a01a7f 100644 --- a/problems/二叉树的迭代遍历.md +++ b/problems/二叉树的迭代遍历.md @@ -696,7 +696,7 @@ impl Solution { } ``` ### C# -```C# +```csharp // 前序遍历 public IList PreorderTraversal(TreeNode root) { diff --git a/problems/二叉树的递归遍历.md b/problems/二叉树的递归遍历.md index 6dad6e56..92a8341f 100644 --- a/problems/二叉树的递归遍历.md +++ b/problems/二叉树的递归遍历.md @@ -566,7 +566,7 @@ impl Solution { ``` ### C# -```C# +```csharp // 前序遍历 public IList PreorderTraversal(TreeNode root) { @@ -584,7 +584,7 @@ public void Traversal(TreeNode cur, IList res) Traversal(cur.right, res); } ``` -```C# +```csharp // 中序遍历 public IList InorderTraversal(TreeNode root) { @@ -601,7 +601,7 @@ public void Traversal(TreeNode cur, IList res) Traversal(cur.right, res); } ``` -```C# +```csharp // 后序遍历 public IList PostorderTraversal(TreeNode root) { diff --git a/problems/面试题02.07.链表相交.md b/problems/面试题02.07.链表相交.md index adeaa413..d0967b8b 100644 --- a/problems/面试题02.07.链表相交.md +++ b/problems/面试题02.07.链表相交.md @@ -503,7 +503,7 @@ object Solution { } ``` ### C# -```C# +```csharp public ListNode GetIntersectionNode(ListNode headA, ListNode headB) { if (headA == null || headB == null) return null; From 55d676e194180cb33564a7b3019068ccd1ad834f Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Fri, 5 Jan 2024 14:08:10 +0800 Subject: [PATCH 3/8] =?UTF-8?q?Update=200452.=E7=94=A8=E6=9C=80=E5=B0=91?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94?= =?UTF-8?q?=E7=90=83=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0452.用最少数量的箭引爆气球.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md index 90cd7085..cd57f83b 100644 --- a/problems/0452.用最少数量的箭引爆气球.md +++ b/problems/0452.用最少数量的箭引爆气球.md @@ -332,6 +332,24 @@ object Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int FindMinArrowShots(int[][] points) + { + if (points.Length == 0) return 0; + Array.Sort(points, (a, b) => a[0].CompareTo(b[0])); + int count = 1; + for (int i = 1; i < points.Length; i++) + { + if (points[i][0] > points[i - 1][1]) count++; + else points[i][1] = Math.Min(points[i][1], points[i - 1][1]); + } + return count; + } +} +```

From 6add8c3287ade5bbfefd6d7042863376cff1ca39 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sat, 6 Jan 2024 09:33:13 +0800 Subject: [PATCH 4/8] =?UTF-8?q?Update=200435.=E6=97=A0=E9=87=8D=E5=8F=A0?= =?UTF-8?q?=E5=8C=BA=E9=97=B4=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0435.无重叠区间.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md index c307532e..1a33f98e 100644 --- a/problems/0435.无重叠区间.md +++ b/problems/0435.无重叠区间.md @@ -441,6 +441,27 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int EraseOverlapIntervals(int[][] intervals) + { + if (intervals.Length == 0) return 0; + Array.Sort(intervals, (a, b) => a[1].CompareTo(b[1])); + int res = 1, end = intervals[0][1]; + for (int i = 1; i < intervals.Length; i++) + { + if (end <= intervals[i][0]) + { + end = intervals[i][1]; + res++; + } + } + return intervals.Length - res; + } +} +```

From 20f331f9043725ad9c39d27bf9912c441b6bcf48 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sun, 7 Jan 2024 10:04:45 +0800 Subject: [PATCH 5/8] =?UTF-8?q?Update=200763.=E5=88=92=E5=88=86=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E5=8C=BA=E9=97=B4=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0763.划分字母区间.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md index 41314456..4e9ec578 100644 --- a/problems/0763.划分字母区间.md +++ b/problems/0763.划分字母区间.md @@ -404,6 +404,32 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public IList PartitionLabels(string s) + { + int[] location = new int[27]; + for (int i = 0; i < s.Length; i++) + { + location[s[i] - 'a'] = i; + } + List res = new List(); + int left = 0, right = 0; + for (int i = 0; i < s.Length; i++) + { + right = Math.Max(right, location[s[i] - 'a']); + if (i == right) + { + res.Add(right - left + 1); + left = i + 1; + } + } + return res; + } +} +```

From 98827c14d0efdceaeb6ebed14f82c4c196e01f5c Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Mon, 8 Jan 2024 10:10:12 +0800 Subject: [PATCH 6/8] =?UTF-8?q?Update=200056.=E5=90=88=E5=B9=B6=E5=8C=BA?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0056.合并区间.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/problems/0056.合并区间.md b/problems/0056.合并区间.md index 95781b1a..122e783a 100644 --- a/problems/0056.合并区间.md +++ b/problems/0056.合并区间.md @@ -336,6 +336,32 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int[][] Merge(int[][] intervals) + { + if (intervals.Length == 0) + return intervals; + Array.Sort(intervals, (a, b) => a[0] - b[0]); + List> res = new List>(); + res.Add(intervals[0].ToList()); + for (int i = 1; i < intervals.Length; i++) + { + if (res[res.Count - 1][1] >= intervals[i][0]) + { + res[res.Count - 1][1] = Math.Max(res[res.Count - 1][1], intervals[i][1]); + } + else + { + res.Add(intervals[i].ToList()); + } + } + return res.Select(x => x.ToArray()).ToArray(); + } +} +```

From 6b38053a63c0a1896ac6ec7905fc17a0a770f91b Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Tue, 9 Jan 2024 10:47:42 +0800 Subject: [PATCH 7/8] =?UTF-8?q?Update=200738.=E5=8D=95=E8=B0=83=E9=80=92?= =?UTF-8?q?=E5=A2=9E=E7=9A=84=E6=95=B0=E5=AD=97=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0738.单调递增的数字.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md index c2215cf6..400dc90d 100644 --- a/problems/0738.单调递增的数字.md +++ b/problems/0738.单调递增的数字.md @@ -392,6 +392,30 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int MonotoneIncreasingDigits(int n) + { + char[] s = n.ToString().ToCharArray(); + int flag = s.Length; + for (int i = s.Length - 1; i > 0; i--) + { + if (s[i - 1] > s[i]) + { + flag = i; + s[i - 1]--; + } + } + for (int i = flag; i < s.Length; i++) + { + s[i] = '9'; + } + return int.Parse(new string(s)); + } +} +```

From f292cbaf2ed861021db70f6b4c2aba7d028f2d64 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 10 Jan 2024 10:02:48 +0800 Subject: [PATCH 8/8] =?UTF-8?q?Update=200968.=E7=9B=91=E6=8E=A7=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=A0=91=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0968.监控二叉树.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/problems/0968.监控二叉树.md b/problems/0968.监控二叉树.md index be04bd47..305f3ae5 100644 --- a/problems/0968.监控二叉树.md +++ b/problems/0968.监控二叉树.md @@ -726,6 +726,31 @@ impl Solution { } } +``` +### C# +```csharp +public class Solution +{ + public int res = 0; + public int MinCameraCover(TreeNode root) + { + if (Traversal(root) == 0) res++; + return res; + } + public int Traversal(TreeNode cur) + { + if (cur == null) return 2; + int left = Traversal(cur.left); + int right = Traversal(cur.right); + if (left == 2 && right == 2) return 0; + else if (left == 0 || right == 0) + { + res++; + return 1; + } + else return 2; + } +} ```