[leetcode 92] Reverse Linked List II
ยท
๐Ÿข One step
LeetCode-92 Reverse Linked List II : Given the head of a singly linked list and two integers left and right where left
[leetcode-24] Swap-Nodes-In-Pairs_2
ยท
๐Ÿข One step
LeetCode-24 swap-nodes-in-pairs_2 : Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes note : only nodes themselves may be changed.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 swap..
[leetcode-2] Add Two Numbers
ยท
๐Ÿข One step
LeetCode-2 Add Two Numbers : Add Two Numbers in Linked List note : You may assume the two numbers do not contain any leading zero, except the number 0 itself.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 addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[Lis..
[leetcode-206] Reverse Linked List
ยท
๐Ÿข One step
LeetCode-206 Reverse Linked List : Reverse Linked List note : ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ ์—ญ์ˆœ์œผ๋กœ ์ •๋ ฌ :::python # Definition for singly-linked list. # class ListNode: # def init(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: def reverse(node: ListNode, prev: ListNode = None): if not node: return prev next, node.next = no..
[leetcode 234] Palindrom Linked List
ยท
๐Ÿข One step
LeetCode-234 Palindrome Linked List : ์ฃผ์–ด์ง„ head๊ฐ€ palindrome์ธ์ง€ ์•„๋‹Œ์ง€ note : range : 1~10^5MyAnswer :::python # Definition for singly-linked list. # class ListNode: # def init(self, val=0, next=None): # self.val = val # self.next = next class Solution: def isPalindrome(self, head: Optional[ListNode]) -> bool: temp: List = [] if not head: return True node = head while node is not None: temp.append(nod..
[leetcode-238] Product of Array Except Self
ยท
๐Ÿข One step
LeetCode-238 Product of Array Except Self : Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. note : Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)Answer :::python class Solution: def productExceptSelf(self..
[leetcode-561] Array Partition
ยท
๐Ÿข One step
LeetCode-561 Array Partition : find maximum (minimum list) note : len(list) = 2nmyAnswer :::python class Solution: def arrayPairSum(self, nums: List[int]) -> int: nums.sort() return sum(nums[::2]) Result : 267ms Memory: 16.7mb
[leetcode-15] Three Sum
ยท
๐Ÿข One step
LeetCode-15 Match Three sum : Notice that the solution set must not contain duplicate triplets. note : myAnswerMyAnswer(Time Limit Exceeded) O(n^2) :::python class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: a = [] nums.sort() for i, n in enumerate(nums): d = {} for j in range(i+1,len(nums)): complete = - (n + nums[j]) if complete in d: if sorted([n, nums[j], complete]) not..
๋‹คํ–ˆ๋‹ค
'Leetcode' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก (3 Page)