Category Archives: PHP
Leetcode 75 – 151. Reverse Words in a String
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only…
Leetcode 75 – 345. Reverse Vowels of a String
Given a string s, reverse only all the vowels in the string and return it. The vowels are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’, and they can appear in both lower and upper cases, more than once. Example 1: Input: s = “IceCreAm” Output: “AceCreIm” Explanation: The vowels in s are [‘I’, ‘e’, ‘e’, ‘A’]. On reversing the vowels, s becomes “AceCreIm”. Example 2: Input: s = “leetcode”…
Leetcode 75 – 605. Can Place Flowers
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0‘s and 1‘s, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise. Example 1: Input: flowerbed = [1,0,0,0,1], n…
Leetcode 75 – Kids With the Greatest Number of Candies
There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have. Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise. Note that multiple kids can have…
Leetcode 75 – 1071. Greatest Common Divisor of Strings
For two strings s and t, we say “t divides s” if and only if s = t + t + t + … + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. Example 1: Input: str1 = “ABCABC”, str2 = “ABC” Output: “ABC” Example 2: Input: str1 = “ABABAB”, str2…
Leetcode 75 – 1768. Merge Strings Alternately
You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string. Return the merged string. Example 1: Input: word1 = “abc”, word2 = “pqr” Output: “apbqcr” Explanation: The merged string will be merged…