File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Definition for singly-linked list.
3+ * public class ListNode {
4+ * int val;
5+ * ListNode next;
6+ * ListNode() {}
7+ * ListNode(int val) { this.val = val; }
8+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+ * }
10+ */
11+ class Solution {
12+ public ListNode mergeTwoLists (ListNode list1 , ListNode list2 ) {
13+ // O(N)
14+ // 2포인터로 지나가용 하면 되는 문제
15+ ListNode result = new ListNode ();
16+ ListNode nowNode = result ;
17+
18+
19+ while (list1 !=null || list2 !=null ) {
20+ int first = list1 ==null ? 101 : list1 .val ;
21+ int second = list2 ==null ? 101 : list2 .val ;
22+
23+ if (first < second ) {
24+ nowNode .next = new ListNode (first );
25+ nowNode = nowNode .next ;
26+ list1 = list1 .next ;
27+ } else {
28+ nowNode .next = new ListNode (second );
29+ nowNode = nowNode .next ;
30+ list2 = list2 .next ;
31+ }
32+ }
33+
34+ return result .next ;
35+ }
36+ }
37+
Original file line number Diff line number Diff line change 1+ import java .util .Arrays ;
2+ import java .util .Collections ;
3+ import java .util .HashSet ;
4+ import java .util .Set ;
5+ import java .util .stream .Collectors ;
6+
7+ // O(N)
8+ class Solution {
9+ public int missingNumber (int [] nums ) {
10+ Set <Integer > numSet = Arrays .stream (nums ).boxed ().collect (Collectors .toSet ());
11+
12+ for (int i =0 ; i <nums .length ; i ++) {
13+ if (!numSet .contains (i )) return i ;
14+ }
15+
16+ return nums .length ;
17+ }
18+ }
19+
You can’t perform that action at this time.
0 commit comments