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.
Apparently, many engineers take measures on the site called LetCode.
It is a site that trains the algorithmic power that can withstand the coding test that is done in the early story, and it is an inevitable path for those who want to build a career at an overseas tech company.
I wrote it in a big way, but I have no plans to have such an interview at the moment.
However, as an IT engineer, it would be better to have the same level of algorithm power as a person, so I would like to solve the problem irregularly and write down the method I thought at that time as a memo.
I'm solving it with Python3.
Leet Code Table of Contents Starting from Zero
Last time Leet Code Day75 "15.3 Sum" starting from zero
Right now, I'm prioritizing the Medium of the Top 100 Liked Questions. I solved all Easy, so if you are interested, please go to the table of contents.
Twitter I'm doing it.
** Technical Blog Started! !! ** ** I think the technology will write about LetCode, Django, Nuxt, and so on. ** This is faster to update **, so please bookmark it!
3. Longest Substring Without Repeating Characters The difficulty level is Medium.
The problem is, given a string, find the length of the longest substring without repeating the character.
Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3.
Example 2: Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1.
Example 3: Input: "pwwkew" Output: 3
Explanation: The answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
dic,length,start = {},0,0
for i,j in enumerate(s):
if j in dic:
sums = dic[j] + 1
if sums > start:
start = sums
num = i - start + 1
if num > length:
length = num
dic[j] = i
return length
# Runtime: 60 ms, faster than 76.33% of Python3 online submissions for Longest Substring Without Repeating Characters.
# Memory Usage: 13.9 MB, less than 55.58% of Python3 online submissions for Longest Substring Without Repeating Characters.
length
holds the maximum length, and start
holds the start position of the substring.
I don't write that much ...
By the way, is it unique to Python that built-in functions are convenient? Depending on the language, it may be easier to implement with built-in functions ...
It's interesting to try to solve it in other languages, so I sometimes write it in Java, but it's hard to get used to.
So that's it for this time. Thank you for your hard work.
Recommended Posts