LeetCode 205 Isomorphic Strings
Problem:
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg", "add", return true.
Given "foo", "bar", return false.
Given "paper", "title", return true.
Note:
You may assume both s and t have the same length.
Summary:
判断所给出的两个字符串是否为相同格式。
Solution:
class Solution {
public:
bool isIsomorphic(string s, string t) {
int len = s.size();
unordered_map<char, char> m;
for (int i = ; i < len; i++) {
if (m.find(s[i]) == m.end()) {
m[s[i]] = t[i];
}
else if (m[s[i]] != t[i]){
return false;
}
}
for (unordered_map<char, char>::iterator i = m.begin(); i != m.end(); i++) {
for (unordered_map<char, char>::iterator j = m.begin(); j != m.end(); j++) {
if (i->first != j->first && i->second == j->second) {
return false;
}
}
}
return true;
}
};
LeetCode 205 Isomorphic Strings的更多相关文章
- [leetcode]205. Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode 205. Isomorphic Strings (同构字符串)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Java for LeetCode 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- (easy)LeetCode 205.Isomorphic Strings (*)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Java [Leetcode 205]Isomorphic Strings
题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...
- [LeetCode] 205. Isomorphic Strings 解题思路 - Java
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- leetcode 205. Isomorphic Strings(哈希表)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)
翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...
- Leetcode 205 Isomorphic Strings 字符串处理
判断两个字符串是否同构 hs,ht就是每个字符出现的顺序 "egg" 与"add"的数字都是122 "foo"是122, 而"ba ...
随机推荐
- iframe 跨域相互操作
我们在开发后台管理系统时可能会经常要跟 iframe 打交道,因为现在大部分后台管理系统都是页面内嵌iframe,所以有时候两者之间就难免要互相通信,但浏览器为了安全的原因,所以就禁止了不同域的访问, ...
- git的基本介绍和使用
前言:从事iOS开发一年多以来,一直使用svn管理源代码.对svn的特点和弊端已经深有体会.前些天双十二前后,项目工期紧张到爆,起早贪黑的加班,可谓披星戴月,这还不止,回到家中还要疯狂的敲代码.那么问 ...
- 文本文件关键字替换(Java)
代码实现如下: import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class File ...
- Git,non-fast-forward
当把coding好的code,push到Git时会出现这个错误:master[rejected non-fast-forward] 问题(Non-fast-forward)的出现原因在于:git仓库 ...
- js时间戳与日期格式之间的转换
转换方法: var date = new Date(时间戳); //获取一个时间对象 注意:如果是uinx时间戳记得乘于1000. 比如php函数time()获得的时间戳就要乘于1000 //获取时 ...
- ThinkPhp 3.2 常见问题与注意事项
1 命名空间声明必须写在脚本的最前面 如果运行PHP脚本后出现如下错误: Namespace declaration statement has to be the very first statem ...
- nodeJS 简单的模块。
nodeJS是的模块流程: 第一步:创建模块,如:student.js 第二步:导出模块,如:exports.add = function(){} 第三步:加载模块,如:var student = r ...
- Windows下安装Oracle拖慢开机速度的解决方法
环境:win7 + oracle R2 方法:将安装Oracle后自动开机启动的服务改为手动启动 步骤如下: 1.修改服务项 Ctrl + R,输入services.msc,打开服务列表,找到Orac ...
- yii2 开源插件与系统
yii2干货集:https://github.com/forecho/awesome-yii2 商城 samdark/yii2-shop composer global require "f ...
- SQL拼接自己需要的字符串
SQL行转列有多种写法,如果想把多行数据拼接成为新的一行,比如: 首先,将查询转为XML 替换XML的标签 将第一个字符,去掉试用 STUFF函数 sql STUFF用法 1.作用 删除指定长度的字符 ...