daily log 10.07.20
2 minute read
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
# GETTING NEW HEAD
new_head = None
current_1 = head
while(new_head == None):
if current_1.next == None:
new_head = current_1
current_1 = current_1.next
print(new_head)
# ATTACHING THE REST
current = head
while(current):
new_head.next = current
# try:
# print(current.next.val)
# except:
# print('NOPE', current.val)
current = current.next
return new_head
# as a human computer, I:
# iterate over the list
# what does that mean?
# i look at the first node
# i then look at first.next
# then first.next.next
# unless I use recursion then I
# set current = first
# while current
# current = first.next
# ok as a human computer if I want to rotate ONE to the RIGHT
# I take first.next.next
THIS LOOPS LIKE I WANT:
current = head
while(current.next != None):
print(current.val)
current = current.next
return new_head
Having to stop here after 2 hours
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
# def getNewHead(head):
# # GETTING NEW HEAD
new_head = None
current_1 = head
while(new_head == None):
if current_1.next == None:
new_head = current_1
current_1 = current_1.next
print(new_head)
# ATTACHING THE REST
current = new_head
# current_new_head = new_head
# current = head
new_current = head
while(new_current):
current.next = new_current
# print(current.val)
current = current.next
new_current = new_current.next
# return new_head
new_head.next = head
return new_head
# as a human computer, I:
# iterate over the list
# what does that mean?
# i look at the first node
# i then look at first.next
# then first.next.next
# unless I use recursion then I
# set current = first
# while current
# current = first.next
# ok as a human computer if I want to rotate ONE to the RIGHT
# I take first.next.next
ENDED, UNFINISHED HERE
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
# def getNewHead(head):
# # GETTING NEW HEAD
new_head = None
current_1 = head
while(new_head == None):
if current_1.next == None:
new_head = current_1
current_1 = current_1.next
print(new_head)
# ATTACHING THE REST
current = new_head
# current_new_head = new_head
# current = head
new_current = head
while(new_current):
current.next = new_current
# print(current.val)
current = current.next
new_current = new_current.next
# return new_head
new_head.next = head
return new_head
# as a human computer, I:
# iterate over the list
# what does that mean?
# i look at the first node
# i then look at first.next
# then first.next.next
# unless I use recursion then I
# set current = first
# while current
# current = first.next
# ok as a human computer if I want to rotate ONE to the RIGHT
# I take first.next.next