Skip to content

Commit 4e0ec1f

Browse files
Merge pull request youngyangyang04#2397 from eeee0717/master
Update0406.根据身高重建队列,添加C#
2 parents c79f957 + f292cba commit 4e0ec1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+213
-50
lines changed

problems/0005.最长回文子串.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ char * longestPalindrome(char * s){
618618
### C#:
619619

620620
動態規則:
621-
```c#
621+
```csharp
622622
public class Solution {
623623

624624
public string LongestPalindrome(string s) {
@@ -648,7 +648,7 @@ public class Solution {
648648
```
649649

650650
雙指針:
651-
```C#
651+
```csharp
652652
public class Solution {
653653
int maxlenth = 0;
654654
int left = 0;

problems/0017.电话号码的字母组合.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def backtracking(result, letter_map, digits, path, index)
733733
end
734734
```
735735
### C#
736-
```C#
736+
```csharp
737737
public class Solution
738738
{
739739
public IList<string> res = new List<string>();

problems/0024.两两交换链表中的节点.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl Solution {
462462
```
463463

464464
### C#
465-
```C#
465+
```csharp
466466
// 虚拟头结点
467467
public ListNode SwapPairs(ListNode head)
468468
{

problems/0028.实现strStr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ impl Solution {
13591359
```
13601360

13611361
>前缀表统一不减一
1362-
```C#
1362+
```csharp
13631363
public int StrStr(string haystack, string needle)
13641364
{
13651365
if (string.IsNullOrEmpty(needle))

problems/0034.在排序数组中查找元素的第一个和最后一个位置.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class Solution {
331331

332332
### C#
333333

334-
```c#
334+
```csharp
335335
public int[] SearchRange(int[] nums, int target) {
336336

337337
var leftBorder = GetLeftBorder(nums, target);

problems/0056.合并区间.md

+26
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,32 @@ impl Solution {
336336
}
337337
}
338338
```
339+
### C#
340+
```csharp
341+
public class Solution
342+
{
343+
public int[][] Merge(int[][] intervals)
344+
{
345+
if (intervals.Length == 0)
346+
return intervals;
347+
Array.Sort(intervals, (a, b) => a[0] - b[0]);
348+
List<List<int>> res = new List<List<int>>();
349+
res.Add(intervals[0].ToList());
350+
for (int i = 1; i < intervals.Length; i++)
351+
{
352+
if (res[res.Count - 1][1] >= intervals[i][0])
353+
{
354+
res[res.Count - 1][1] = Math.Max(res[res.Count - 1][1], intervals[i][1]);
355+
}
356+
else
357+
{
358+
res.Add(intervals[i].ToList());
359+
}
360+
}
361+
return res.Select(x => x.ToArray()).ToArray();
362+
}
363+
}
364+
```
339365

340366
<p align="center">
341367
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

problems/0062.不同路径.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ object Solution {
537537

538538
### c#
539539

540-
```c#
540+
```csharp
541541
public class Solution
542542
{
543543
public int UniquePaths(int m, int n)

problems/0070.爬楼梯.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ object Solution {
468468

469469
### C#
470470

471-
```c#
471+
```csharp
472472
public class Solution {
473473
public int ClimbStairs(int n) {
474474
if(n<=2) return n;

problems/0077.组合.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ end
793793

794794
```
795795
### C#
796-
```C#
796+
```csharp
797797
// 暴力
798798
public class Solution
799799
{

problems/0090.子集II.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ object Solution {
641641
}
642642
```
643643
### C#
644-
```c#
644+
```csharp
645645
public class Solution
646646
{
647647
public IList<IList<int>> res = new List<IList<int>>();

problems/0098.验证二叉搜索树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl Solution {
792792
}
793793
```
794794
### C#
795-
```C#
795+
```csharp
796796
// 递归
797797
public long val = Int64.MinValue;
798798
public bool IsValidBST(TreeNode root)

problems/0101.对称二叉树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ impl Solution {
898898
}
899899
```
900900
### C#
901-
```C#
901+
```csharp
902902
// 递归
903903
public bool IsSymmetric(TreeNode root)
904904
{

problems/0102.二叉树的层序遍历.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl Solution {
463463
}
464464
```
465465
### C#
466-
```C#
466+
```csharp
467467
public IList<IList<int>> LevelOrder(TreeNode root)
468468
{
469469
var res = new List<IList<int>>();
@@ -825,7 +825,7 @@ impl Solution {
825825
}
826826
```
827827
### C#
828-
```C#
828+
```csharp
829829
public IList<IList<int>> LevelOrderBottom(TreeNode root)
830830
{
831831
var res = new List<IList<int>>();

problems/0104.二叉树的最大深度.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ impl Solution {
10331033
}
10341034
```
10351035
### C#
1036-
```C#
1036+
```csharp
10371037
// 递归法
10381038
public int MaxDepth(TreeNode root) {
10391039
if(root == null) return 0;
@@ -1044,7 +1044,7 @@ public int MaxDepth(TreeNode root) {
10441044
return 1 + Math.Max(leftDepth, rightDepth);
10451045
}
10461046
```
1047-
```C#
1047+
```csharp
10481048
// 前序遍历
10491049
int result = 0;
10501050
public int MaxDepth(TreeNode root)
@@ -1065,7 +1065,7 @@ public void GetDepth(TreeNode root, int depth)
10651065
return;
10661066
}
10671067
```
1068-
```C#
1068+
```csharp
10691069
// 迭代法
10701070
public int MaxDepth(TreeNode root)
10711071
{

problems/0106.从中序与后序遍历序列构造二叉树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ impl Solution {
12291229
}
12301230
```
12311231
### C#
1232-
```C#
1232+
```csharp
12331233
public TreeNode BuildTree(int[] inorder, int[] postorder)
12341234
{
12351235
if (inorder.Length == 0 || postorder.Length == null) return null;

problems/0110.平衡二叉树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl Solution {
909909
}
910910
```
911911
### C#
912-
```C#
912+
```csharp
913913
public bool IsBalanced(TreeNode root)
914914
{
915915
return GetHeight(root) == -1 ? false : true;

problems/0111.二叉树的最小深度.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl Solution {
709709
}
710710
```
711711
### C#
712-
```C#
712+
```csharp
713713
// 递归
714714
public int MinDepth(TreeNode root)
715715
{
@@ -725,7 +725,7 @@ public int MinDepth(TreeNode root)
725725
return res;
726726
}
727727
```
728-
```C#
728+
```csharp
729729
// 迭代
730730
public int MinDepth(TreeNode root)
731731
{

problems/0112.路径总和.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ impl Solution {
15131513

15141514
```
15151515
### C#
1516-
```C#
1516+
```csharp
15171517
// 0112.路径总和
15181518
// 递归
15191519
public bool HasPathSum(TreeNode root, int targetSum)

problems/0151.翻转字符串里的单词.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ char * reverseWords(char * s){
973973
```
974974
975975
### C#
976-
```C# LINQ高级方法
976+
```csharp LINQ高级方法
977977
public string ReverseWords(string s) {
978978
return string.Join(' ', s.Trim().Split(' ',StringSplitOptions.RemoveEmptyEntries).Reverse());
979979
}

problems/0222.完全二叉树的节点个数.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl Solution {
868868
}
869869
```
870870
### C#
871-
```C#
871+
```csharp
872872
// 递归
873873
public int CountNodes(TreeNode root)
874874
{

problems/0235.二叉搜索树的最近公共祖先.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl Solution {
521521
}
522522
```
523523
### C#
524-
```C#
524+
```csharp
525525
// 递归
526526
public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q)
527527
{

problems/0236.二叉树的最近公共祖先.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl Solution {
432432
}
433433
```
434434
### C#
435-
```C#
435+
```csharp
436436
public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q)
437437
{
438438
if (root == null || root == p || root == q) return root;

problems/0257.二叉树的所有路径.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ impl Solution {
901901
}
902902
```
903903
### C#
904-
```C#
904+
```csharp
905905
public IList<string> BinaryTreePaths(TreeNode root)
906906
{
907907
List<int> path = new();

problems/0404.左叶子之和.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl Solution {
652652
}
653653
```
654654
### C#
655-
```C#
655+
```csharp
656656
// 递归
657657
public int SumOfLeftLeaves(TreeNode root)
658658
{

problems/0406.根据身高重建队列.md

+23
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ object Solution {
396396
}
397397
}
398398
```
399+
### C#
400+
```csharp
401+
public class Solution
402+
{
403+
public int[][] ReconstructQueue(int[][] people)
404+
{
405+
Array.Sort(people, (a, b) =>
406+
{
407+
if (a[0] == b[0])
408+
{
409+
return a[1] - b[1];
410+
}
411+
return b[0] - a[0];
412+
});
413+
var res = new List<int[]>();
414+
for (int i = 0; i < people.Length; i++)
415+
{
416+
res.Insert(people[i][1], people[i]);
417+
}
418+
return res.ToArray();
419+
}
420+
}
421+
```
399422

400423

401424
<p align="center">

problems/0435.无重叠区间.md

+21
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,27 @@ impl Solution {
441441
}
442442
}
443443
```
444+
### C#
445+
```csharp
446+
public class Solution
447+
{
448+
public int EraseOverlapIntervals(int[][] intervals)
449+
{
450+
if (intervals.Length == 0) return 0;
451+
Array.Sort(intervals, (a, b) => a[1].CompareTo(b[1]));
452+
int res = 1, end = intervals[0][1];
453+
for (int i = 1; i < intervals.Length; i++)
454+
{
455+
if (end <= intervals[i][0])
456+
{
457+
end = intervals[i][1];
458+
res++;
459+
}
460+
}
461+
return intervals.Length - res;
462+
}
463+
}
464+
```
444465

445466

446467
<p align="center">

problems/0450.删除二叉搜索树中的节点.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl Solution {
772772
### C#
773773

774774
> 递归法:
775-
```C#
775+
```csharp
776776
public TreeNode DeleteNode(TreeNode root, int key) {
777777
// 第一种情况:没找到删除的节点,遍历到空节点直接返回了
778778
if (root == null) return null;

problems/0452.用最少数量的箭引爆气球.md

+18
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,24 @@ object Solution {
332332
}
333333
}
334334
```
335+
### C#
336+
```csharp
337+
public class Solution
338+
{
339+
public int FindMinArrowShots(int[][] points)
340+
{
341+
if (points.Length == 0) return 0;
342+
Array.Sort(points, (a, b) => a[0].CompareTo(b[0]));
343+
int count = 1;
344+
for (int i = 1; i < points.Length; i++)
345+
{
346+
if (points[i][0] > points[i - 1][1]) count++;
347+
else points[i][1] = Math.Min(points[i][1], points[i - 1][1]);
348+
}
349+
return count;
350+
}
351+
}
352+
```
335353

336354
<p align="center">
337355
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

problems/0459.重复的子字符串.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl Solution {
682682
}
683683
```
684684
### C#
685-
```C#
685+
```csharp
686686
// 前缀表不减一
687687
public bool RepeatedSubstringPattern(string s)
688688
{

problems/0501.二叉搜索树中的众数.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ pub fn find_mode(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
10101010
}
10111011
```
10121012
### C#
1013-
```C#
1013+
```csharp
10141014
// 递归
10151015
public class Solution
10161016
{

0 commit comments

Comments
 (0)