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. 【20161203-20161208】清华集训2016滚粗记&&酱油记&&游记

    先挖坑(这个blog怎么变成游记专用了--) 已更完 #include <cstdio> using namespace std; int main(){ puts("转载请注明 ...

  2. dwarf tower

    dwarf tower(dwarf.cpp/c/pas)[问题描述]Vasya在玩一个叫做"Dwarf Tower"的游戏,这个游戏中有n个不同的物品,它们的编号为1到n.现在Va ...

  3. php中trait(性状)与generator(生成器)

    PHP中trait(性状)与generator(生成器) 一.trait (性状) 最近在看Josh Lockhat的<Modern PHP>,这本书很薄.但是其中给出了一个很重要的学习方 ...

  4. js事件(Event)知识整理

    事件(Event)知识整理,本文由网上资料整理而来,需要的朋友可以参考下   鼠标事件 鼠标移动到目标元素上的那一刻,首先触发mouseover 之后如果光标继续在元素上移动,则不断触发mousemo ...

  5. Access-Control-Allow-Origin与跨域问题

    在某域名下使用Ajax向另一个域名下的页面请求数据,会遇到跨域问题.另一个域名必须在response中添加 Access-Control-Allow-Origin 的header,才能让前者成功拿到数 ...

  6. sql server 字符串转成日期格式

    在SQL Server数据库中,SQL Server日期时间格式转换字符串可以改变SQL Server日期和时间的格式,是每个SQL数据库用户都应该掌握的.本文我们主要就介绍一下SQL Server日 ...

  7. tomcat server.xml中文版

    原文:http://www.blogjava.net/baoyaer/articles/107278.html Tomcat Server的结构图 该文件描述了如何启动Tomcat Server &l ...

  8. 导出excel报错

    System.ComponentModel.Win32Exception: 拒绝访问 1.问题现象: foreach (System.Diagnostics.Process thispro in Sy ...

  9. 常用Linux命令收集

    关闭 php-fpm: ps -ef | grep php-fpm  或    ps aux | grep php-fpm kill -USR2 32253  (对应的进程PID) kill -9 进 ...

  10. 【Android Studio】android Internal HTTP server disabled 解决

    报错:Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operate ...