Skip to main content

Command Palette

Search for a command to run...

LeetCode:Valid Anagram(java)

Published
1 min readView as Markdown
LeetCode:Valid Anagram(java)
M
Software Engineer with 5+ years of experience designing and building clinical-grade systems, including Electronic Medical Records (EMR), medical imaging tools, and scalable backend infrastructures. I specialize in developing end-to-end healthcare solutions using Python and Django REST Framework, with a strong focus on clinical workflow automation, multilingual systems, and high-performance data handling. My work includes building modular EMR platforms, prescription engines, and hybrid search systems for accurate medical data retrieval. I have also worked on medical imaging applications, integrating Python-based tools with analysis modules to support diagnostic workflows and image-based decision-making.

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Example 1:

Input: s = "anagram", t = "nagaram" Output: true

Example 2:

Input: s = "rat", t = "car" Output: false

class Solution {
    public boolean isAnagram(String s, String t) {
        // convert s and t strings to arrays of characters
       char [] firstStr = s.toCharArray();
       char [] secondStr = t.toCharArray();

        // get array lenghts
        int l1 = firstStr.length;
        int l2 = secondStr.length;

        if(l1 != l2){
            return false;
        }
        // Sort Arrays
        Arrays.sort(firstStr);
        Arrays.sort(secondStr);


       return Arrays.equals(firstStr, secondStr);
}
    }

More from this blog

eikon

17 posts

Hello! I am Monyuy a software engineer. A day in my life consists of prepping web art, fixing front end bugs, adding API endpoint, database design and blogging.