Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two solves to two challenges #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions middle-of-the-linked-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Given the head of a singly linked list, return the middle node of the linked list.

If there are two middle nodes, return the second middle node.

Input: head = [1,2,3,4,5]
Output: [3,4,5]
Explanation: The middle node of the list is node 3.


Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.

The number of nodes in the list is in the range [1, 100].
1 <= Node.val <= 100
"""





# 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 middleNode(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
node_counter = 1
current_node = head
if current_node.next == None:
node_counter = 0
else:
while current_node.next:
current_node = current_node.next
node_counter += 1
index = (node_counter / 2) + 1
print(index)
next_counter = 0
current_node = head
while next_counter < (index - 1):
next_counter += 1
current_node = current_node.next
return current_node
21 changes: 21 additions & 0 deletions weekday.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
print("What day is it?")
day = input("> ")

print("How many days from today?")
duration = input("> ")

week = {
"monday": 0,
"tuesday": 1,
"wednesday": 2,
"thursday": 3,
"friday": 4,
"saturday": 5,
"sunday": 6
}

week_arr = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]

remainder = (week[day] + int(duration)) % 7
print(week_arr[remainder])