Skip to content

Commit 496366a

Browse files
committed
update
1 parent beed143 commit 496366a

File tree

1 file changed

+62
-31
lines changed

1 file changed

+62
-31
lines changed

README.md

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public IList<int> GetRow(int rowIndex) {
8484
}
8585
```
8686
* [#66 Plus One](http://blog.csdn.net/daigualu/article/details/71056697)
87-
```
87+
```C#
8888
public int[] PlusOne(int[] digits)
8989
{
9090
int index = digits.Length - 1;
@@ -111,7 +111,7 @@ public IList<int> GetRow(int rowIndex) {
111111
}
112112
```
113113
* [#121 Best time to buy and sell stock](http://blog.csdn.net/daigualu/article/details/71038726)
114-
```
114+
```C#
115115
public int MaxProfit(int[] prices) {
116116
int premax = 0;
117117
int curmax = 0;
@@ -125,7 +125,7 @@ public IList<int> GetRow(int rowIndex) {
125125
}
126126
```
127127
* [#26 Remove Duplicates from Sorted Array](http://blog.csdn.net/daigualu/article/details/71064545)
128-
```
128+
```C#
129129
public int RemoveDuplicates(int[] nums)
130130
{
131131
//nums have been sorted
@@ -149,6 +149,37 @@ public IList<int> GetRow(int rowIndex) {
149149
}
150150
```
151151

152+
* [#122 BestTimeToBuyandSellStockII](http://blog.csdn.net/daigualu/article/details/71104584)
153+
```C#
154+
public int MaxProfit(int[] prices) {
155+
int totalProfit = 0;
156+
for(int i=0;i<prices.Length-1;i++)
157+
{
158+
if(prices[i+1]>prices[i])
159+
totalProfit += prices[i+1] - prices[i];
160+
}
161+
return totalProfit;
162+
}
163+
```
164+
* [#27 Remove element](http://blog.csdn.net/daigualu/article/details/71104482)
165+
```C#
166+
public int RemoveElement(int[] nums, int val)
167+
{
168+
int i=0; //指向不等于元素val
169+
for(int j=0; j<nums.Length;j++)
170+
{
171+
while(j<nums.Length&&nums[j]==val)
172+
j++;
173+
if(i<j && j<nums.Length)
174+
nums[i]= nums[j];
175+
if(j<nums.Length)
176+
i++;
177+
}
178+
return i;
179+
}
180+
```
181+
182+
152183
## Hash Table
153184
* [#136 Single number](/HashTable/HashTable.Lib/SingleOneSln.cs)
154185

@@ -300,7 +331,7 @@ public int[] TwoSum(int[] nums, int target)
300331
```
301332
## Linked List
302333
[#141 Linked List Cycle](http://blog.csdn.net/daigualu/article/details/69055927)
303-
```
334+
```C#
304335
public bool HasCycle(ListNode head)
305336
{
306337
if (head == null) return false;
@@ -325,7 +356,7 @@ public int[] TwoSum(int[] nums, int target)
325356
}
326357
```
327358
[#237 Delete Node in a Linked List](http://blog.csdn.net/daigualu/article/details/69055991)
328-
```
359+
```C#
329360
void deleteNode(ListNode node) {
330361
if(node==null)
331362
return;
@@ -334,7 +365,7 @@ void deleteNode(ListNode node) {
334365
}
335366
```
336367
[#83 Remove Duplicates from Sorted List](http://blog.csdn.net/daigualu/article/details/69093677)
337-
```
368+
```C#
338369
public ListNode DeleteDuplicates(ListNode head)
339370
{
340371
ListNode diff = head;
@@ -354,7 +385,7 @@ void deleteNode(ListNode node) {
354385
}
355386
```
356387
[#160 Intersection of Two Linked Lists](http://blog.csdn.net/daigualu/article/details/69526717)
357-
```
388+
```C#
358389
public ListNode GetIntersectionNode(ListNode headA, ListNode headB)
359390
{
360391
if (headA == null || headB == null)
@@ -386,7 +417,7 @@ void deleteNode(ListNode node) {
386417
```
387418

388419
[#203 Remove Linked List Elements](http://blog.csdn.net/daigualu/article/details/69389243)
389-
```
420+
```C#
390421
public ListNode RemoveElements(ListNode head, int val)
391422
{
392423
if (head == null)
@@ -418,7 +449,7 @@ void deleteNode(ListNode node) {
418449
}
419450
```
420451
[#206 Reverse Linked List](http://blog.csdn.net/daigualu/article/details/69372119)
421-
```
452+
```C#
422453
public ListNode ReverseList(ListNode head)
423454
{
424455
if (head == null || head.next == null)
@@ -437,7 +468,7 @@ void deleteNode(ListNode node) {
437468
}
438469
```
439470
[#234 Palindrome Linked List](http://blog.csdn.net/daigualu/article/details/69388513)
440-
```
471+
```C#
441472
public bool IsPalindrome(ListNode head)
442473
{
443474
int nodeCnt = nodeCount(head);
@@ -473,7 +504,7 @@ void deleteNode(ListNode node) {
473504
}
474505
```
475506
[#21 Merge Two Sorted Lists](http://blog.csdn.net/daigualu/article/details/69565969)
476-
```
507+
```C#
477508
public ListNode MergeTwoLists(ListNode l1, ListNode l2)
478509
{
479510
if (l1 == null) return l2;
@@ -526,7 +557,7 @@ void deleteNode(ListNode node) {
526557
## Math
527558
[#231 Power of Two](http://blog.csdn.net/daigualu/article/details/69102931)
528559

529-
```
560+
```C#
530561
public bool IsPowerOfTwo(int n)
531562
{
532563
if (n<=0) return false;
@@ -541,7 +572,7 @@ void deleteNode(ListNode node) {
541572

542573
[#268 Missing Number](http://blog.csdn.net/daigualu/article/details/69220202)
543574

544-
```
575+
```C#
545576
public int MissingNumber(int[] nums)
546577
{
547578
int xor = 0, i = 0;
@@ -556,7 +587,7 @@ void deleteNode(ListNode node) {
556587

557588
[#507 Perfect Number](http://blog.csdn.net/daigualu/article/details/69233798)
558589

559-
```
590+
```C#
560591
public bool CheckPerfectNumber(int num)
561592
{
562593
int sum = 1;
@@ -575,7 +606,7 @@ void deleteNode(ListNode node) {
575606
## Two Pointers
576607
[#345 Reverse Vowels of a String](http://blog.csdn.net/daigualu/article/details/69257693)
577608

578-
```
609+
```C#
579610
private List<char> vowels = new List<char> {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'};
580611
private char[] chars;
581612

@@ -618,7 +649,7 @@ void deleteNode(ListNode node) {
618649
[#283 Move Zeroes](http://blog.csdn.net/daigualu/article/details/69329038)
619650

620651

621-
```
652+
```C#
622653
public void MoveZeroes(int[] nums)
623654
{
624655
int i, j = 0; //j始终指向非零数
@@ -643,7 +674,7 @@ void deleteNode(ListNode node) {
643674

644675
[#88 Merge Sorted Array](http://blog.csdn.net/daigualu/article/details/69367334)
645676

646-
```
677+
```C#
647678
public void Merge(int[] nums1, int m, int[] nums2, int n)
648679
{
649680
int i = m - 1; //指向nums1
@@ -661,7 +692,7 @@ void deleteNode(ListNode node) {
661692

662693
[#234Palindrome Linked List](http://blog.csdn.net/daigualu/article/details/69388513)
663694

664-
```
695+
```C#
665696
public bool IsPalindrome(ListNode head)
666697
{
667698
int nodeCnt = nodeCount(head);
@@ -701,7 +732,7 @@ void deleteNode(ListNode node) {
701732
## String
702733
[#58 Length of Last Word](http://blog.csdn.net/daigualu/article/details/69568460)
703734

704-
```
735+
```C#
705736
public int LengthOfLastWord1(string s)
706737
{
707738
s = s.Trim(); //去掉前,后空格
@@ -714,7 +745,7 @@ public int LengthOfLastWord1(string s)
714745

715746
[#20 Valid Parentheses](http://blog.csdn.net/daigualu/article/details/69569622)
716747

717-
```
748+
```C#
718749
public bool IsValid(string s)
719750
{
720751
if (string.IsNullOrEmpty(s)) return true;
@@ -754,7 +785,7 @@ public bool IsValid(string s)
754785

755786
[#520 Detect Capital](http://blog.csdn.net/daigualu/article/details/69663210)
756787

757-
```
788+
```C#
758789
public bool DetectCapitalUse(string word)
759790
{
760791
if (string.IsNullOrEmpty(word)) return true;
@@ -797,7 +828,7 @@ public bool DetectCapitalUse(string word)
797828

798829
[#459 Repeated Substring Pattern](http://blog.csdn.net/daigualu/article/details/69663545)
799830

800-
```
831+
```C#
801832
public bool RepeatedSubstringPattern(string s)
802833
{
803834
for (int i = s.Length/2; i > 0 ; i--)
@@ -826,7 +857,7 @@ public bool DetectCapitalUse(string word)
826857

827858
[#434 Number of Segments in a String](http://blog.csdn.net/daigualu/article/details/69664369)
828859

829-
```
860+
```C#
830861
public int CountSegments(string s)
831862
{
832863
if (string.IsNullOrEmpty(s))
@@ -849,7 +880,7 @@ public int CountSegments(string s)
849880

850881
[#14 Longest Common Prefix](http://blog.csdn.net/daigualu/article/details/69665015)
851882

852-
```
883+
```C#
853884
public string LongestCommonPrefix(string[] strs)
854885
{
855886
if(strs==null || strs.Length==0)
@@ -895,7 +926,7 @@ public int CountSegments(string s)
895926

896927
[#383 Ransom Note](http://blog.csdn.net/daigualu/article/details/69665190)
897928

898-
```
929+
```C#
899930
public bool CanConstruct(string ransomNote, string magazine)
900931
{
901932
if (magazine == null && ransomNote == null) return true;
@@ -925,7 +956,7 @@ public bool CanConstruct(string ransomNote, string magazine)
925956

926957
## Binary Search
927958
* [#367 Valid Perfect Square](http://blog.csdn.net/daigualu/article/details/69787644)
928-
```
959+
```C#
929960
public bool IsPerfectSquare(int num)
930961
{
931962
int low = 1, high = num;
@@ -949,7 +980,7 @@ public bool IsPerfectSquare(int num)
949980
}
950981
```
951982
* [#167 Two Sum II - Input array is sorted](http://blog.csdn.net/daigualu/article/details/69787679)
952-
```
983+
```C#
953984
public int[] TwoSum2(int[] num, int target)
954985
{
955986
//因为一定存在解,所以不做边界检查
@@ -968,7 +999,7 @@ public bool IsPerfectSquare(int num)
968999
}
9691000
```
9701001
* [#441 Arranging Coins](http://blog.csdn.net/daigualu/article/details/69788500)
971-
```
1002+
```C#
9721003
public int ArrangeCoins(int n)
9731004
{
9741005
long low = 1, high = n;
@@ -985,7 +1016,7 @@ public bool IsPerfectSquare(int num)
9851016
```
9861017

9871018
* [#278 First Bad Version](http://blog.csdn.net/daigualu/article/details/69802371)
988-
```
1019+
```C#
9891020
public int FirstBadVersion(int n)
9901021
{
9911022
long lo = 0; //指向好的版本
@@ -1005,7 +1036,7 @@ public bool IsPerfectSquare(int num)
10051036

10061037
* [#349 Intersection of Two Arrays 350. Intersection of Two Arrays II](http://blog.csdn.net/daigualu/article/details/69666351)
10071038

1008-
```
1039+
```C#
10091040
//交集定义,元素可重复
10101041
public int[] Intersection(int[] nums1, int[] nums2)
10111042
{
@@ -1089,7 +1120,7 @@ public bool IsPerfectSquare(int num)
10891120
```
10901121
* [#349 Intersection of Two Arrays](http://blog.csdn.net/daigualu/article/details/69666198)
10911122

1092-
```
1123+
```C#
10931124
public int[] Intersection(int[] nums1, int[] nums2)
10941125
{
10951126
if (nums1 == null || nums1.Length == 0) return new int[] { };

0 commit comments

Comments
 (0)