Java

How to initialise HashSet while declaring in Java

Before delving into initialization, let’s understand the allure of a HashSet. This data structure, based on the principles of a set in mathematics, provides rapid access to elements and ensures uniqueness—no duplicates allowed. Perfect for scenarios where order doesn’t matter, and you need swift membership checks. Techniques for Initializing HashSet During Declaration Method 1: Traditional…

Leetcode

1704. Determine if String Halves Are Alike

Problem: https://leetcode.com/problems/determine-if-string-halves-are-alike/description/ Breaking Down the Solution Converting String to Char Array: The input string s is converted into a character array a. This facilitates easy traversal and access to individual characters. Initialization and Set of Vowels: A HashSet vowels is created to store the vowels that need to be checked. The size of the array…