[LeetCode] 2429. Minimize XOR (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명Given two positive integers num1 and num2, find the positive integer x such that:x has the same number of set bits as num2, andThe value x XOR num1 is minimal.Note that XOR is the bitwise XOR operation. Return the integer x. The test cases are generated such that x is uniquely determined. The number of set bits of an integer is the number of 1's in its binary representation. 문제 ..
[LeetCode] 2657. Find the Prefix Common Array of Two Arrays (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given two 0-indexed integer permutations A and B of length n. A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B. Return the prefix common array of A and B. A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once. 문제 예제Exampl..
[LeetCode] 3223. Minimum Length of String After Operations (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a string s.You can perform the following process on s any number of times:Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].Delete the closest character to the left of index i that is equal to s[i].Delete the closest character to ..
[LeetCode] 1400. Construct K Palindrome Strings (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise. 문제 예제Example 1:Input: s = "annabelle", k = 2Output: trueExplanation: You can construct two palindromes using all characters in s.Some possible constructions "anna" + "elble", "anbna" + "elle", "anellena" + "b"Example 2:Input: s = "leetcode",..
[LeetCode] 916. Word Subsets (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given two string arrays words1 and words2.A string b is a subset of string a if every letter in b occurs in a including multiplicity.For example, "wrr" is a subset of "warrior" but is not a subset of "world".A string a from words1 is universal if for every string b in words2, b is a subset of a.Return an array of all the universal strings in words1. You may return the an..
[LeetCode] 2185. Counting Words With a Given Prefix (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명You are given an array of strings words and a string pref. Return the number of strings in words that contain pref as a prefix. A prefix of a string s is any leading contiguous substring of s. 문제 예제Example 1:Input: words = ["pay","attention","practice","attend"],pref= "at"Output: 2Explanation: The 2 strings that contain "at" as a prefix are: "attention" and "attend".Example 2:Inpu..