-
1347. Minimum Number of Steps to Make Two Strings Anagram릿코드(LEETCODE) 2020. 2. 14. 14:03반응형
https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/
D 풀이
anagram
hello = olleh와 같이 같은 요소로 구성되어있는 문자열을 anagram이라고 함
t에서 몇 개의 alphabet 변경해야 s와 anagram 이 되는지 변경할 문자의 개수를 출력하는 문제
class Solution { public: int minSteps(string s, string t) { int alphabet[27] = { 0, }, alphabet2[27] = { 0, }; for (int i = 0; i < s.size(); i++) { alphabet[s[i] - 'a']++; alphabet2[t[i] - 'a']++; } int sol = 0; for (int i = 0; i < 26; ++i) { int need = max(0, alphabet[i] - alphabet2[i]); sol += need; } return sol; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
119. Pascal's Triangle II (0) 2020.02.14 118. Pascal's Triangle (0) 2020.02.14 1346. Check If N and Its Double Exist (0) 2020.02.14 1025. Divisor Game (0) 2020.02.14 53. Maximum Subarray (0) 2020.02.13