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 15 "283. Move Zeroes" starting from zero
Basically, I would like to solve the easy acceptance in descending order.
The problem is that the strings in the given array are inverted and returned.
Example 1: Input: ["h","e","l","l","o"] Output: ["o","l","l","e","h"]
Example 2: Input: ["H","a","n","n","a","h"] Output: ["h","a","n","n","a","H"]
I've relied too much on Python's built-in functions, so I've listed some simple ones.
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
return s.reverse()
# Runtime: 208 ms, faster than 82.72% of Python3 online submissions for Reverse String.
# Memory Usage: 18.3 MB, less than 5.81% of Python3 online submissions for Reverse String.
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
return s[::-1]
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
return ''.join(reversed(list(s)))
Python's built-in functions are useful. If there is a better answer, I will add it.
Recommended Posts