Find the Difference问题及解法
来源:互联网 发布:centos 桌面图标创建 编辑:程序博客网 时间:2024/05/29 19:34
问题描述:
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
示例:Input:s = "abcd"t = "abcde"Output:eExplanation:'e' is the letter that was added.问题分析:
题目要求出两个字符串之间唯一一个不同的字符。可以用位运算,也可以用hashtable。下面是我用hashtable的解法:
class Solution {public: char findTheDifference(string s, string t) { vector<int> mapping(256,0); char res = ' '; for(int i = 0; i < s.length(); i++) { mapping[s[i]]++;}for(int i = 0; i < t.length(); i++) { if(mapping[t[i]]-- == 0) { res = t[i]; break;}}return res; }};
0 0
- Find the Difference问题及解法
- Find the Duplicate Number问题及解法
- 389. Find the Difference的C++解法
- leetcode之389. Find the Difference(C++解法)
- leetcode[Find the Difference]//待整理多种解法
- Minimum Time Difference问题及解法
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Find the Difference
- 160.Find the Difference
- LeetCode389. Find the Difference
- Find the Difference
- 389. Find the Difference
- Leetcode:Find the Difference
- leetcode_389 Find the Difference
- 389. Find the Difference
- 【敏捷开发每日一贴】自组织敏捷团队的特点
- android_android最简单调用weex编译后的js
- left join+right join +inner join
- mysql索引(三)
- LOAD_TYPE_VERSION_MISMATCH与TYPELOAD_NEW_VERSION错误分析
- Find the Difference问题及解法
- [Matlab]结构体(Struct)
- 【敏捷开发每日一贴】债务与缺陷
- Linux下who命令模仿
- keil如何生成bin文件
- SPOJ 19148 INS14G
- C++继承之子类的构造函数
- 重载计算三种类型的绝对值
- 四大组件之 activity