It seems that coding tests are conducted overseas in interviews with engineers, and in many cases, the main thing is to implement specific functions and classes according to the theme.
As a countermeasure, it seems that a site called Let Code will take measures.
A site that trains algorithmic power that can withstand coding tests that are often done in the home.
I think it's better to have the algorithm power of a human being, so I'll solve the problem irregularly and write down the method I thought at that time as a memo.
Leet Code Table of Contents Starting from Zero
Last time Leet Code Day 41 "394. Decode String" starting from zero
I'm currently solving the Top 100 Liked Questions Medium. I solved all Easy, so if you are interested, please go to the table of contents.
Twitter I'm doing it.
The difficulty level is Medium. Excerpt from Top 100 Liked Questions.
Given a non-empty linked list, design an algorithm that adds each given number digit by digit, inverts it, and returns it.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
tempsum = 0
root = cur = ListNode(0)
while l1 or l2 or tempsum:
if l1: tempsum += l1.val; l1 = l1.next
if l2: tempsum += l2.val; l2 = l2.next
cur.next = cur = ListNode(tempsum % 10)
tempsum //= 10
return root.next
# Runtime: 64 ms, faster than 95.04% of Python3 online submissions for Add Two Numbers.
# Memory Usage: 13.9 MB, less than 5.67% of Python3 online submissions for Add Two Numbers.
It's simple, but it's good. I feel that the first question number is a good set of questions. I feel that there are many problems that can be solved by thinking about the flowchart with your head rather than with solid mathematical knowledge like this time.
This time around here. Thank you for your hard work.
Recommended Posts