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:

解法同LeetCode 290 Word Pattern

 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的更多相关文章

  1. [leetcode]205. Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  2. LeetCode 205. Isomorphic Strings (同构字符串)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  3. Java for LeetCode 205 Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  4. (easy)LeetCode 205.Isomorphic Strings (*)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  5. Java [Leetcode 205]Isomorphic Strings

    题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...

  6. [LeetCode] 205. Isomorphic Strings 解题思路 - Java

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  7. leetcode 205. Isomorphic Strings(哈希表)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)

    翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...

  9. Leetcode 205 Isomorphic Strings 字符串处理

    判断两个字符串是否同构 hs,ht就是每个字符出现的顺序 "egg" 与"add"的数字都是122 "foo"是122, 而"ba ...

随机推荐

  1. 图解TCP-IP协议

    本文通过图来梳理TCP-IP协议相关知识.TCP通信过程包括三个步骤:建立TCP连接通道,传输数据,断开TCP连接通道.如图1所示,给出了TCP通信过程的示意图. 图1 TCP 三次握手四次挥手 图1 ...

  2. Javascript作用域研究(with)

    基本用法参考:http://www.cnblogs.com/silentjesse/p/4024536.html 这里说明以下with的用法: with语句 with语句主要用来临时扩展作用域链,将语 ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. win7 安装好redis 如何安装扩展

    首先我的电脑环境是使用的是wamp集成开发环境,PHP版本5.5.12的 安装要找对应的扩展,不然会出问题 php_redis.dll下载地址:http://windows.php.net/downl ...

  5. JS中SetTimeOut和SetInterval方法的区别?

    1.setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 ...

  6. 【Java】正则表达式

    正则表达式是做什么的? 正则表达式可用在处理字符串,满足查找符合某些复杂规则的字符串的需要.简言之,正则表达式是记录文本规则的代码. 上图~

  7. easyui的datagrid form(表单)提交到后台转对象的时候中文出现乱码

    在web.xml中配置如下代码 <filter> <filter-name>characterEncodingFilter</filter-name> <fi ...

  8. 微信小程序内训笔记

    2016年9月22日凌晨微信官方正式宣布“小程序”开始内测,有“微信之父”之称.腾讯集团高级执行副总裁张小龙在2016年末对外宣布“小程序“应用将于2017年1月9日正式推出 这一次微信还是按照惯例, ...

  9. 数据库mysql 基本命令

    .....= =.... 进入mysql: mysql -uroot ; 创建一个数据库: create database [数据库名字]; (注意最后的分号不能漏) 删除一个数据库:drop dat ...

  10. NFS配置(centos)

    一.简介    NFS(Network File System/网络文件系统):       1).设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务): 2) ...