[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..
[LeetCode] 3042. Count Prefix and Suffix Pairs I (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명You are given a 0-indexed string array words.Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:isPrefixAndSuffix(str1, str2) returns true if str1 is both a  prefix and a suffix of str2, and false otherwise.For example, isPrefixAndSuffix("aba", "ababa") is true because "aba" is a prefix of "ababa" and also a suffix, but isPrefixAndSuffix("abc",..
[LeetCode] 1408. String Matching in an Array (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명Given an array of string words, return all strings in words that is a substring of another word. You can return the answer in any order. A substring is a contiguous sequence of characters within a string 문제 예제Example 1:Input: words = ["mass","as","hero","superhero"] Output: ["as","hero"] Explanation: "as" is substring of "mass" and "hero" is substring of "superhero". ["hero","as"]..
[LeetCode] 1769. Minimum Number of Operations to Move All Balls to Each Box (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명 You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes. Return an array answer of size n, where an..
[LeetCode] 2381. Shifting Letters II (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명 You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0. Shifting a character forward means replacing it with the next letter in the alph..