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. Java集合框架List,Map,Set等全面介绍

    Java集合框架的基本接口/类层次结构: java.util.Collection [I]+--java.util.List [I]   +--java.util.ArrayList [C]   +- ...

  2. C#获取本地IP地址[常用代码段]

    获得当前机器的IP代码,假设本地主机为单网卡 string strHostName = Dns.GetHostName(); //得到本机的主机名 IPHostEntry ipEntry = Dns. ...

  3. Twisted随笔

    学习了socket后决定尝试使用框架,目标锁定了Twisted. 什么是Twisted? twisted是一个用python语言写的事件驱动的网络框架,他支持很多种协议,包括UDP,TCP,TLS和其 ...

  4. window.hostory(浏览器的历史记录)

    浏览器会对同一个窗口(选项卡)中访问的网页进行记录,不管我们是通过以下哪种方式改变网页,浏览器都会把改变后的网页记录下来,以便通过浏览器的前进和后退按钮,能够快速的切换到已经访问过的网页:  1)直接 ...

  5. javadoc

    Oracle官方javadoc说明 Generates HTML pages of API documentation from Java source files. http://docs.orac ...

  6. Python 【第十章】 Django路由

    路由可以简单理解就是 URL -> 函数名 例如: /login1/ -> 函数名 urls.py文件中 urlpatterns = [ # url(r'^admin/', admin.s ...

  7. Windows API Hooking in Python

    catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...

  8. Data Binding使用技巧

    Data Binding 根据变量,自动赋值到各widget. How 1.编写layout文件,这里的layout为: act_data_bind_demo.xml 这里需要先准备变量 在具体的wi ...

  9. 将上传图片转成base64(转)

    效果如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"><titl ...

  10. Believe Me , I Can !

    Believe Me , I Can ! ---DF 第一阶段:(年底1-27之前) 1.  熟练使用JavaScript/CSS/HTML,熟悉HTML5 / CSS3: 2.  熟悉JavaScr ...