Leetcode 389 Find the Difference
2017-09-24 18:11
375 查看
Leetcode 389 Find the Difference
#include <vector> #include <string> using namespace std; class Solution { public: char findTheDifference(string s, string t) { vector<int> lettercount(26,0); for(int i = 0;i < s.length();i ++) { lettercount[s[i] - 'a'] ++; } for(int i = 0; i < t.length();i ++) { lettercount[t[i] - 'a'] --; if(lettercount[t[i] - 'a'] < 0) return t[i]; } } char findTheDifference1(string s, string t) { char c = 0; for(int i = 0;i < s.length();i ++) { c ^= s[i]; } for(int i = 0; i < t.length();i ++) { c ^= t[i]; } return c; } char findTheDifference2(string s, string t) //to learn { char c = 0; for (auto ch : s) c ^= ch; for (auto ch : t) c ^= ch; return c; } };
相关文章推荐
- LeetCode 389: Find the Difference 题解
- 【python】【leetcode】【算法题目389—Find the Difference】
- LeetCode 389. Find the Difference
- 【LeetCode】389. Find the Difference
- leetcode389[easy]---Find the Difference
- LeetCode 389. Find the Difference
- [leetcode] 389. Find the Difference 解题报告
- Leetcode 389 Find the Difference
- LeetCode-136. Single Number 389. Find the Difference
- LeetCode笔记:389. Find the Difference
- LeetCode 389. Find the Difference
- leetcode(87).389. Find the Difference
- LeetCode之389. Find the Difference
- LeetCode 389. Find the Difference
- LeetCode - 389. Find the Difference
- 【leetcode】389. Find the Difference
- [LeetCode] 389 Find the Difference 解题思路 字符查找
- 小白笔记------------------------------------leetcode(389. Find the Difference )
- [leetcode]: 389. Find the Difference
- 【LeetCode】 389. Find the Difference