1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int longestPalindrome(string s) 12 { 13 vector<int> vi(256,0); 14 for(char c:s) 15 vi[c]++; 16 int count=0; 17 int sub=0; 18 for(int i:vi) 19 { 20 if(i%2==0) 21 count+=i; 22 else 23 { 24 if(i>2) 25 count+=(i-1); 26 sub=1; 27 } 28 } 29 30 return count+sub; 31 } 32 };
vector处理字符串,老司机,你值得拥有