File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
1
+ #-*- coding:utf-8 -*-
2
+ '''
3
+ Created on 2017年4月19日
4
+
5
+ @author: huangjiaxin
6
+ '''
7
+ # Definition for singly-linked list.
8
+ class ListNode (object ):
9
+ def __init__ (self , x ):
10
+ self .val = x
11
+ self .next = None
12
+
13
+ class Solution (object ):
14
+ def mergeTwoLists (self , l1 , l2 ):
15
+ """
16
+ :type l1: ListNode
17
+ :type l2: ListNode
18
+ :rtype: ListNode
19
+ """
20
+ if l1 and l2 :
21
+ if l1 .val > l2 .val :
22
+ l1 , l2 = l2 , l1
23
+ l1 .next = self .mergeTwoLists (l1 .next , l2 )
24
+ return l1 or l2
Original file line number Diff line number Diff line change
1
+ #-*- coding:utf-8 -*-
2
+ '''
3
+ Created on 2017年4月19日
4
+
5
+ @author: huangjiaxin
6
+ '''
7
+ class Solution (object ):
8
+ def removeDuplicates (self , nums ):
9
+ """
10
+ :type nums: List[int]
11
+ :rtype: int
12
+ """
13
+ if not nums :
14
+ return 0
15
+ i = 0
16
+ j = len (nums )
17
+ for num in range (1 , j ):
18
+ if nums [num ] != nums [num - 1 ]:
19
+ i += 1
20
+ nums [i ] = nums [num ]
21
+ return i + 1
22
+
23
+ if __name__ == '__main__' :
24
+ nums = [1 , 1 ]
25
+ print Solution ().removeDuplicates (nums )
Original file line number Diff line number Diff line change
1
+ #-*- coding:utf-8 -*-
2
+ '''
3
+ Created on 2017年4月19日
4
+
5
+ @author: huangjiaxin
6
+ '''
7
+ class Solution (object ):
8
+ def removeElement (self , nums , val ):
9
+ """
10
+ :type nums: List[int]
11
+ :type val: int
12
+ :rtype: int
13
+ """
14
+ if not nums :
15
+ return 0
16
+ newlen = 0
17
+ for i in range (len (nums )):
18
+ if nums [i ] != val :
19
+ nums [newlen ] = nums [i ]
20
+ newlen += 1
21
+ return newlen
22
+
23
+ if __name__ == '__main__' :
24
+ nums = [4 ,4 ,0 ,1 ,0 ,2 ]
25
+ val = 0
26
+ print Solution ().removeElement (nums , val )
You can’t perform that action at this time.
0 commit comments