diff --git a/Week_01/id_34/LeetCode_83_0.cs b/Week_01/id_34/LeetCode_83_0.cs new file mode 100644 index 00000000..fa2286c4 --- /dev/null +++ b/Week_01/id_34/LeetCode_83_0.cs @@ -0,0 +1,29 @@ + public class Solution + { + public ListNode DeleteDuplicates(ListNode head) + { + int currentValue = head.val; + int nextValue = 0; + + + if(head == null|| head.next==null) + { return head; } + + ListNode copyHead = head; + while(copyHead.next!=null) + { + currentValue = copyHead.val; + nextValue = copyHead.next.val; + if(currentValue==nextValue) + { + copyHead.next = copyHead.next.next; + } + else + { + copyHead = copyHead.next; + } + } + + return head; + } + } diff --git a/Week_01/id_34/LeetCode_905_0.cs b/Week_01/id_34/LeetCode_905_0.cs new file mode 100644 index 00000000..2ca32675 --- /dev/null +++ b/Week_01/id_34/LeetCode_905_0.cs @@ -0,0 +1,38 @@ + public class Solution + { + public int[] SortArrayByParity(int[] A) + { + if (A == null && A.Length == 0) + { + return A; + } + int indexHead = 0; + int indexTail = A.Length - 1; + int tempValue = 0; + while (indexHead < indexTail) + { + if (A[indexHead] % 2 == 1 && A[indexTail] % 2 == 0) + { + tempValue = A[indexHead]; + A[indexHead] = A[indexTail]; + A[indexTail] = tempValue; + indexHead++; + indexTail--; + } + else if (A[indexHead] % 2 == 0 && A[indexTail] % 2 == 1) + { + indexHead++; + indexTail--; + } + else if (A[indexHead] % 2 == 1) + { + indexTail--; + } + else if (A[indexTail] % 2 == 0) + { + indexHead++; + } + } + return A; + } + }