23.05.03 Today’s Leetcode
2215. Find the Difference of Two Arrays (easy)
class Solution:
def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:
a, b = set(nums1), set(nums2)
res = []
temp = set()
for num in nums1:
if num not in b:
temp.add(num)
res.append(list(temp))
temp = set()
for num in nums2:
if num not in a:
temp.add(num)
res.append(list(temp))
return res
2216. Minimum Deletions to Make Array Beautiful (medium)
class Solution:
def minDeletion(self, nums: List[int]) -> int:
n = len(nums)
i = res = 0
while i + 1 < n:
if nums[i] == nums[i + 1]:
res += 1
i -= 1
i += 2
return res if (n - res) % 2 == 0 else res + 1
2217. Find Palindrome With Fixed Length (medium)
class Solution:
def kthPalindrome(self, queries: List[int], intLength: int) -> List[int]:
def get_palindrome(n, k):
num = 10 ** ((n - 1) // 2)
num += (k - 1)
a = str(num)
b = a[::-1]
if n % 2 != 0:
b = b[1:]
p = a + b
if len(p) != n:
return -1
return int(p)
res = []
for query in queries:
res.append(get_palindrome(intLength, query))
return res