lc-day11 发表于 2021-11-23 859. 亲密字符串 这个简单题写了一个多小时,纯纯恶心人的题,浪费时间 1234567891011121314151617181920212223242526class Solution {public: bool buddyStrings(string s, string goal) { if(s.size() != goal.size()) return false; vector<int> s1(26); vector<int> goal1(26); for(int i = 0; i < s.size(); i++){ s1[s[i] - 'a']++; goal1[goal[i] - 'a']++; } int cnt = 0, flag = 0; for(int i = 0; i < s.size(); i++){ if(s[i] != goal[i]) cnt++; } for(int i = 0; i < 26; i++) if(s1[i] > 1) flag = 1; if(s == goal && flag == 1) return true; if(s1 != goal1) return false; else{ if(cnt == 2) return true; } return false; }};