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 46 "406. Queue Reconstruction by Height" 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 Easy. It may not be so difficult because it is a problem solved like a chopstick rest.
The problem is to design a function that returns the longest intersection of each string in a given array of strings.
If there is nothing in common, it returns " "
.
Input: ["flower","flow","flight"] Output: "fl" Example 2:
Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings.
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if not strs:
return ""
ans = ""
for num in zip(*strs):
if len(set(num)) == 1:
ans += num[0]
else:
return ans
return ans
# Runtime: 32 ms, faster than 74.42% of Python3 online submissions for Longest Common Prefix.
# Memory Usage: 14.1 MB, less than 22.07% of Python3 online submissions for Longest Common Prefix
I solved it using the zip function. It wasn't that difficult because it was easy, but it was fun as a head exercise, so I recommend you to try it.
~~ There is nothing special to explain ... ~~
Then it's a matter of chopstick rest, so this time it's up to here. Thank you for your hard work.
Recommended Posts