File tree Expand file tree Collapse file tree 2 files changed +52
-2
lines changed Expand file tree Collapse file tree 2 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2+ from common_utils import *
3+
24
35class Solution_61_70 (object ):
6+ def rotateRight (self , head , k ):
7+ """
8+ 61
9+ :param head:
10+ :param k:
11+ :return:
12+ """
13+ if not head or not head .next :
14+ return head
15+
16+ list_len = 1
17+
18+ node = head
19+ while node .next :
20+ list_len += 1
21+ node = node .next
22+ last_node = node
23+ node = head .next
24+ prev_node = head
25+ if k % list_len == 0 :
26+ new_head = head
27+ else :
28+ for _ in range (list_len - k % list_len - 1 ):
29+ prev_node = prev_node .next
30+ node = node .next
31+ new_head = node
32+ prev_node .next = None
33+ last_node .next = head
34+ return new_head
35+
436 def addBinary (self , a , b ):
537 """
638 67
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22from sln_1_100 .solution_61_70 import Solution_61_70
3+ from common_utils import *
34from unittest import TestCase
5+
6+
47class TestSolution_61_70 (TestCase ):
58 def setUp (self ):
69 self .sln = Solution_61_70 ()
710
11+ def test_rotate_right (self ):
12+ l1 = ListNode (1 )
13+ l2 = ListNode (2 )
14+ l1 .next = l2
15+ l3 = ListNode (3 )
16+ l2 .next = l3
17+ l4 = ListNode (4 )
18+ l3 .next = l4
19+ l5 = ListNode (5 )
20+ l4 .next = l5
21+ node = self .sln .rotateRight (l1 , 8 )
22+ while node :
23+ print (node .val )
24+ node = node .next
25+
826 def test_addBinary (self ):
9- ret = self .sln .addBinary ('11' ,'1' )
10- print (ret )
27+ ret = self .sln .addBinary ('11' , '1' )
28+ print (ret )
You can’t perform that action at this time.
0 commit comments