java.lang.Object
g1701_1800.s1704_determine_if_string_halves_are_alike.Solution

public class Solution extends Object
1704 - Determine if String Halves Are Alike.<p>Easy</p> <p>You are given a string <code>s</code> of even length. Split this string into two halves of equal lengths, and let <code>a</code> be the first half and <code>b</code> be the second half.</p> <p>Two strings are <strong>alike</strong> if they have the same number of vowels (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>, <code>'A'</code>, <code>'E'</code>, <code>'I'</code>, <code>'O'</code>, <code>'U'</code>). Notice that <code>s</code> contains uppercase and lowercase letters.</p> <p>Return <code>true</code> <em>if</em> <code>a</code> <em>and</em> <code>b</code> <em>are <strong>alike</strong></em>. Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;book&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> a = &ldquo;bo&rdquo; and b = &ldquo;ok&rdquo;. a has 1 vowel and b has 1 vowel. Therefore, they are alike.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;textbook&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> a = &ldquo;text&rdquo; and b = &ldquo;book&rdquo;. a has 1 vowel whereas b has 2. Therefore, they are not alike. Notice that the vowel o is counted twice.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= s.length <= 1000</code></li> <li><code>s.length</code> is even.</li> <li><code>s</code> consists of <strong>uppercase and lowercase</strong> letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • halvesAreAlike

      public boolean halvesAreAlike(String s)