Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.12 KB

1347. Minimum Number of Steps to Make Two Strings Anagram.md

File metadata and controls

54 lines (41 loc) · 1.12 KB

1347. Minimum Number of Steps to Make Two Strings Anagram

Minimum Number of Steps to Make Two Strings Anagram - LeetCode

Code1

class Solution {
    public int minSteps(String s, String t) {
        byte[] sb = s.getBytes();
        byte[] tb = t.getBytes();
       
        int[] arr = new int[26];
        int count = 0;

        for (int i = 0; i < sb.length; i++) {
            arr[sb[i] - 'a']++;
            arr[tb[i] - 'a']--;
        }

        for (int num : arr) {
            if (num > 0 ) count += num;
        }

        return count;
    }
}

Code2

class Solution {
    public int minSteps(String s, String t) {
        char[] sArray = s.toCharArray();
        char[] tArray = t.toCharArray();

        int [] arr = new int[26];
        int count = 0;

        for (int i = 0; i < s.length(); i++)
        {
            arr[sArray[i] - 'a']++;
            arr[tArray[i] - 'a']--;
        }

        for (int num : arr) {
            if (num > 0 ) count += num;
        }

        return count;
    }
}