File tree 3 files changed +70
-0
lines changed
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ # @return: The same instance of this class every time
3
+ @classmethod
4
+ def getInstance (cls ):
5
+ # write your code here
6
+ return cls
Original file line number Diff line number Diff line change
1
+ """
2
+ Definition of ListNode
3
+
4
+ """
5
+
6
+ class ListNode (object ):
7
+
8
+ def __init__ (self , val , next = None ):
9
+ self .val = val
10
+ self .next = next
11
+
12
+ class Solution :
13
+ """
14
+ @param head: n
15
+ @return: The new head of reversed linked list.
16
+ """
17
+ def reverse (self , head ):
18
+ # write your code here
19
+ if head == None or head .next == None :
20
+ return head
21
+ pointTo = None
22
+ while head != None and head .next != None :
23
+ Sec = head .next
24
+ nextHead = Sec .next
25
+ Sec .next = head
26
+ head .next = pointTo
27
+ head = nextHead
28
+ pointTo = Sec
29
+ if head == None :
30
+ return pointTo
31
+ else :
32
+ head .next = pointTo
33
+ return head
34
+
35
+ l1 = ListNode (1 )
36
+ l2 = ListNode (2 , l1 )
37
+ l3 = ListNode (3 , l2 )
38
+ l4 = ListNode (4 , l3 )
39
+ l5 = ListNode (5 , l4 )
40
+
41
+ tmp = Solution .reverse (1 , l5 )
42
+ while tmp != None :
43
+ print (tmp .val , "->" )
44
+ tmp = tmp .next
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ """
3
+ @param n: An integer
4
+ @return: A list of strings.
5
+ """
6
+ def fizzBuzz (self , n ):
7
+ # write your code here
8
+ res = []
9
+ for i in range (1 , n + 1 ):
10
+ if i % 3 == 0 :
11
+ if i % 5 == 0 :
12
+ res .append ("fizz buzz" )
13
+ else :
14
+ res .append ("fizz" )
15
+ else :
16
+ if i % 5 == 0 :
17
+ res .append ("buzz" )
18
+ else :
19
+ res .append (str (i ))
20
+ return res
You can’t perform that action at this time.
0 commit comments