rioxshen
Reputation Top 1%
Rio Shen
8 Snippets  (107th place)
Published
2 Channels
Created
1 Channel
Following
210 points  (144th place)
Reputation
Junior Code Generator
Serious Code Generator
Junior Publisher
Serious Publisher
Junior Topic Creator
Junior Topic Hub
Junior Trend Maker
Junior Popular Coder
Serious Popular Coder
Junior Autobiographer
Senior Autobiographer
Serious Famous Coder

## Recent Snippets See all snippets by rioxshen

### [LeetCode] Remove duplicates from sorted list - Set

```public class Solution {

Set<Integer> set = new HashSet<>();
while (current.next != null) {
current.next = current.next.next;
} else {
current = current.next;
}
}

}
}```
;

### [LeetCode] remove duplicates from sorted list

```public class Solution {

while (current.next != null) {
if (current.val == current.next.val) {
current.next = current.next.next;
} else {
current = current.next;
}
}

}
}```
;

### [LeetCode] Partition Problem

Partition a list around the value x.
```public class Solution {
public ListNode partition(ListNode head, int x) {

ListNode leftDummy = new ListNode(Integer.MIN_VALUE);
ListNode rightDummy = new ListNode(Integer.MIN_VALUE);
ListNode left = leftDummy;
ListNode right = rightDummy;

left = left.next;
} else {
right = right.next;
}
}

left.next = rightDummy.next;
right.next = null;

return leftDummy.next;
}
}```
;

#### public by rioxshen  1846  1  5  1

```public class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
int carry = 0;
ListNode dummy = new ListNode(Integer.MIN_VALUE);
ListNode current = dummy;

while (l1 != null || l2 != null) {
int a = l1 == null ? 0 : l1.val;
int b = l2 == null ? 0 : l2.val;
int sum = a + b + carry;
current.next = new ListNode(sum % 10);

carry = sum / 10;
l1 = l1 == null ? null : l1.next;
l2 = l2 == null ? null : l2.next;
current = current.next;
}

if (carry > 0) current.next = new ListNode(carry);

return dummy.next;
}
}```
;

### [leetcode] Insert Interval

```class Interval:
def __init__(self, s=0, e=0):
self.start = s
self.end = e

class Solution:
def insert(self, intervals, newIntervals):
""" Inserts the new interval into the list and
returns merged intervals.

1. Appends the new interval to the list.
2. Sorts the list.
3. Iterates through and merges the new interval list.
"""
if not intervals:
return [newInterval]

intervals.append(newInterval)
intervals.sort(lambda x, y: x.start - y.start)

result = []
length = len(intervals)
last = intervals[0]
for i in range(1, length):
current = intervals[i]
if current.start <= last.end: # Merge intercetions
last.end = max(last.end, current.end)
else:
result.append(last)
last = current
result.append(last)

return result
```
;