[leetcode-38] Count and Say
ยท
๐Ÿข One step
LeetCode-38 Count and Say : The count-and-say sequence is a sequence of digit strings defined by the recursive formula: note : To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.Answer :::py..
[leetcode-48] Rotate Image
ยท
๐Ÿข One step
LeetCode-48 Rotate Image : You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). note : You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.Answer :::python class Solution: def rotate(self, matrix: List[List[int]]) -> None: if len(matrix[0])==1: retu..
[leetcode-347] Top K Frequent Elements
ยท
๐Ÿข One step
LeetCode-347 Top K Frequent Elements : Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. note : time complexity must be better than O(n log n), where n is the array s size.Over * :::python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: if len(set(nums))==1: return [nums[0]] answer = [] count =..
[leetcode-43] Multiply Strings
ยท
๐Ÿข One step
LeetCode-43 Multiply Strings : Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. note : Note: You must not use any built-in BigInteger library or convert the inputs to integer directly. :::python class Solution: def multiply(self, num1: str, num2: str) -> str: if (num1=='0') or (num2=='0'): ret..
[leetcode-14] Longest Common Prefix
ยท
๐Ÿข One step
LeetCode-14 Longest Common Prefix : Write a function to find the longest common prefix string amongst an array of strings. note : If there is no common prefix, return an empty string "".Answer :::python class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if len(strs)==1: return strs[0] answer = '' i = 0 min_p = min([len(s) for s in strs]) if min_p==0: return "" while i
[leetcode-12] Integer to Roman
ยท
๐Ÿข One step
LeetCode-12 Integer to Roman : Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. note : Given an integer, convert it to a roman numeral.Answer :::python class Solution: def intToRoman(self, num: int) -> str: roman_dict = { 0 : "V" ,1 : "L" ,2 : "D" } d_dict= { 0 : "I" ,1 : "X" ,2 : "C" ,3 : "M" } answer = '' set_num = 3 while set_num >= 0: remain = num //..
[leetcode-10] Regular Expression Matching
ยท
๐Ÿข One step
LeetCode-10 Regular Expression Matching : Given an input string s and a pattern p, implement regular expression matching note : The matching should cover the entire input string (not partial).Answer :::python class Solution: def isMatch(self, s: str, p: str) -> bool: if len(re.findall(p,s))>0: return s == re.findall(p,s)[0] else: return False Result : 201ms Memory: 13.9mbSolve :::python class So..
[leetcode-8] String to Integer (atoi)
ยท
๐Ÿข One step
LeetCode-8 String to Integer (atoi) : Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). note : integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.Answer :::python class Solution: def myAtoi(self, s: str) -> int: left = 0 k = '' p = '' for l ..
๋‹คํ–ˆ๋‹ค
'๐Ÿข One step' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)