[leetcode-6] Zigzag Conversion
ยท
๐Ÿข One step
LeetCode-6 Zigzag Conversion : The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows note : like this: (you may want to display this pattern in a fixed font for better legibility)Answer :::python class Solution: def convert(self, s: str, numRows: int) -> str: if numRows==1: return s answer = '' interval = numRows + (numRows-2) ls = [[''] for _ in ra..
[leetcode-7] Reverse Integer
ยท
๐Ÿข One step
LeetCode-7 Reverse Integer : Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. note : Assume the environment does not allow you to store 64-bit integers (signed or unsigned).Answer :::python class Solution: def reverse(self, x: int) -> int: if x > 0: x = int(str(x)[::-1..
[leetcode-9] Palindrome Number
ยท
๐Ÿข One step
LeetCode-9 PalindromeNumber : Given an integer x, return true if x is a palindrome, and false otherwise. note : From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.Answer :::python class Solution: def isPalindrome(self, x: int) -> bool: return str(x) == str(x)[::-1] Result : 57ms Memory: 13.7mb PalindromeNumber PalindromeNumber๋Š” ์•ž์œผ๋กœ ์ฝ์œผ๋‚˜ ๋’ค๋กœ ์ฝ์œผ๋‚˜..
[leetcode-4] Median of Two Sorted Arrays
ยท
๐Ÿข One step
LeetCode-4 Median of Two Sorted Arrays : Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. note : The overall run time complexity should be O(log (m+n)).Answer :::python class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: p = nums1 + nums2 p.sort() if len(p)%2!=0: median = p[len(p)//2] else..
[leetcode-3] Longest Substring Without Repeating Characters
ยท
๐Ÿข One step
LeetCode-3 Longest Substring Without Repeating Characters : Given a string s, find the length of the longest substring without repeating characters. note : s consists of English letters, digits, symbols and spaces.Answer :::python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if len(s)==1: return 1 left, right, answer_max = 0, 1, 0 for _ in range(len(s)): while (left
[leetcode-23] Merge k Sorted Lists
ยท
๐Ÿข One step
LeetCode-23 Merge k Sorted Lists : You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. note : Merge all the linked-lists into one sorted linked-list and return it.MyAnswer :::python # Definition for singly-linked list. # class ListNode: # def init(self, val=0, next=None): # self.val = val # self.next = next class Solution: def mergeKLists(self, lists: L..
[leetcode-641] Design Circular Deque
ยท
๐Ÿข One step
LeetCode-641 Design Circular Deque : Design your implementation of the circular double-ended queue (deque). note : Returns -1 if the deque is empty.MyAnswer :::python class MyCircularDeque: def init(self, k: int): self.maxsize = k self.deq = collections.deque(maxlen=k) self.deq_size = 0 def insertFront(self, value: int) -> bool: if self.deq_size bool: if self.deq_size bool: if self.deq_size > 0:..
[leetcode-622] Design Circular Queue
ยท
๐Ÿข One step
LeetCode-622 Design Circular Queue : Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle, and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". note : You must solve the problem without using the built-in queue d..
๋‹คํ–ˆ๋‹ค
'๐Ÿข One step' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (3 Page)