@@ -28,74 +28,13 @@ Tags are following:
28
28
# Details:
29
29
## Array tag:
30
30
* [ #35 Search Insert Position] ( /Array/Array.Console/Array.Lib/SearchInsertPosition.cs )
31
- ``` C#
32
- public int SearchInsert (int [] nums , int target ) {
33
- int lo = 0 ;
34
- int hi = nums .Length ;
35
- while (lo < hi ){
36
- int mi = (lo + hi )>> 1 ;
37
- if (target <= nums [mi ]) // 目标值不大于中间位置的数时,hi变小
38
- hi = mi ;
39
- else if (target > nums [mi ]) // 大于中间位置的值,lo加1
40
- lo = lo + 1 ;
41
- }
42
- return lo ;
43
- }
44
- ```
31
+
45
32
* [ #118 Pascal’s Triangle] ( /Array/Array.Console/Array.Lib/PascalsTriangle.cs )
46
- ``` C#
47
- public IList < IList < int >> Generate (int numRows )
48
- {
49
- IList < IList < int >> rtn = new List <IList <int >>();
50
- for (int i = 0 ; i < numRows ;i ++ )
51
- {
52
- IList < int > ints = new List <int >();
53
- ints .Add (1 );
54
- for (int j = 1 ;j < i ;j ++ )
55
- {
56
- IList < int > intsPreRow = rtn [i - 1 ];
57
- ints .Add (intsPreRow [j - 1 ]+ intsPreRow [j ]);
58
- }
59
- if (i > 0 )
60
- ints .Add (1 );
61
33
62
- rtn .Add (ints );
63
- }
64
- return rtn ;
65
- }
66
- ```
67
34
* [ #119 Pascal’s Triangle II] ( /Array/Array.Console/Array.Lib/PascalsTriangleII.cs )
68
- ``` C#
69
- public IList < int > GetRow (int rowIndex ) {
70
- if ( rowIndex < 0 ) return new List <int >();
71
- IList < int > levelList = new List <int >();
72
- for (int i = 0 ;i <= rowIndex ;i ++ )
73
- {
74
- int k = levelList .Count ;
75
- for (int j = k - 1 ;j >= 1 ;j -- ) // 这个循环是最重要的一部分,巧妙的运用了Pascal三角的特点
76
- {
77
- levelList [j ]= levelList [j - 1 ]+ levelList [j ];
78
- }
79
- levelList .Add (1 );
80
- }
81
- return levelList ;
82
- }
83
- ```
35
+
84
36
* [ #414 Third Maximum Number] ( /Array/Array.Console/Array.Lib/ThirdMaximumNumber.cs )
85
- ``` C#
86
- public int GetThirdMax (int [] a )
87
- {
88
- int first = a .Max ();
89
- int [] a2 = a .Where (r => r != first ).ToArray ();
90
- if (a2 .Length == 0 )
91
- return first ;
92
- int second = a2 .Max ();
93
- int [] a3 = a2 .Where (r => r != second ).ToArray ();
94
- if (a3 .Length == 0 )
95
- return first ;
96
- return a3 .Max ();
97
- }
98
- ```
37
+
99
38
* [ #66 Plus One] ( http://blog.csdn.net/daigualu/article/details/71056697 )
100
39
``` C#
101
40
public int [] PlusOne (int [] digits )
0 commit comments