@@ -792,7 +792,59 @@ def backtracking(result, path, n, j, k)
792
792
end
793
793
794
794
```
795
-
795
+ ### C#
796
+ ``` C#
797
+ // 暴力
798
+ public class Solution
799
+ {
800
+ public IList <IList <int >> res = new List <IList <int >>();
801
+ public IList <int > path = new List <int >();
802
+ public IList <IList <int >> Combine (int n , int k )
803
+ {
804
+ BackTracking (n , k , 1 );
805
+ return res ;
806
+ }
807
+ public void BackTracking (int n , int k , int start )
808
+ {
809
+ if (path .Count == k )
810
+ {
811
+ res .Add (new List <int >(path ));
812
+ return ;
813
+ }
814
+ for (int i = start ; i <= n ; i ++ )
815
+ {
816
+ path .Add (i );
817
+ BackTracking (n , k , i + 1 );
818
+ path .RemoveAt (path .Count - 1 );
819
+ }
820
+ }
821
+ }
822
+ // 剪枝
823
+ public class Solution
824
+ {
825
+ public IList <IList <int >> res = new List <IList <int >>();
826
+ public IList <int > path = new List <int >();
827
+ public IList <IList <int >> Combine (int n , int k )
828
+ {
829
+ BackTracking (n , k , 1 );
830
+ return res ;
831
+ }
832
+ public void BackTracking (int n , int k , int start )
833
+ {
834
+ if (path .Count == k )
835
+ {
836
+ res .Add (new List <int >(path ));
837
+ return ;
838
+ }
839
+ for (int i = start ; i <= n - (k - path .Count ) + 1 ; i ++ )
840
+ {
841
+ path .Add (i );
842
+ BackTracking (n , k , i + 1 );
843
+ path .RemoveAt (path .Count - 1 );
844
+ }
845
+ }
846
+ }
847
+ ```
796
848
<p align =" center " >
797
849
<a href =" https://programmercarl.com/other/kstar.html " target =" _blank " >
798
850
<img src =" ../pics/网站星球宣传海报.jpg " width =" 1000 " />
0 commit comments