Skip to content

Commit cd4a798

Browse files
Merge pull request #77 from hotboy/master
034-week1_work
2 parents 8e01bcf + 9309e45 commit cd4a798

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Week_01/id_34/LeetCode_83_0.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Solution
2+
{
3+
public ListNode DeleteDuplicates(ListNode head)
4+
{
5+
int currentValue = head.val;
6+
int nextValue = 0;
7+
8+
9+
if(head == null|| head.next==null)
10+
{ return head; }
11+
12+
ListNode copyHead = head;
13+
while(copyHead.next!=null)
14+
{
15+
currentValue = copyHead.val;
16+
nextValue = copyHead.next.val;
17+
if(currentValue==nextValue)
18+
{
19+
copyHead.next = copyHead.next.next;
20+
}
21+
else
22+
{
23+
copyHead = copyHead.next;
24+
}
25+
}
26+
27+
return head;
28+
}
29+
}

Week_01/id_34/LeetCode_905_0.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
public class Solution
2+
{
3+
public int[] SortArrayByParity(int[] A)
4+
{
5+
if (A == null && A.Length == 0)
6+
{
7+
return A;
8+
}
9+
int indexHead = 0;
10+
int indexTail = A.Length - 1;
11+
int tempValue = 0;
12+
while (indexHead < indexTail)
13+
{
14+
if (A[indexHead] % 2 == 1 && A[indexTail] % 2 == 0)
15+
{
16+
tempValue = A[indexHead];
17+
A[indexHead] = A[indexTail];
18+
A[indexTail] = tempValue;
19+
indexHead++;
20+
indexTail--;
21+
}
22+
else if (A[indexHead] % 2 == 0 && A[indexTail] % 2 == 1)
23+
{
24+
indexHead++;
25+
indexTail--;
26+
}
27+
else if (A[indexHead] % 2 == 1)
28+
{
29+
indexTail--;
30+
}
31+
else if (A[indexTail] % 2 == 0)
32+
{
33+
indexHead++;
34+
}
35+
}
36+
return A;
37+
}
38+
}

0 commit comments

Comments
 (0)