File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,37 @@ const rotateRight = function(head, k) {
29
29
30
30
return dummy . next ;
31
31
} ;
32
+
33
+ // another
34
+
35
+ /**
36
+ * Definition for singly-linked list.
37
+ * function ListNode(val, next) {
38
+ * this.val = (val===undefined ? 0 : val)
39
+ * this.next = (next===undefined ? null : next)
40
+ * }
41
+ */
42
+ /**
43
+ * @param {ListNode } head
44
+ * @param {number } k
45
+ * @return {ListNode }
46
+ */
47
+ const rotateRight = function ( head , k ) {
48
+ if ( head == null ) return null
49
+ let len = 1
50
+ let tmp = head
51
+ while ( tmp . next ) {
52
+ len ++
53
+ tmp = tmp . next
54
+ }
55
+ k = k % len
56
+ if ( k === 0 ) return head
57
+ let tail = head
58
+ for ( let i = 1 ; i < len - k ; i ++ ) {
59
+ tail = tail . next
60
+ }
61
+ const newHead = tail . next
62
+ tmp . next = head
63
+ tail . next = null
64
+ return newHead
65
+ } ;
You can’t perform that action at this time.
0 commit comments