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 ...
随机推荐
- Python matplotlib笔记
可视化的工具有很多,如Tableau,各种JS框架,我个人感觉应该是学JS最好,因为JS不需要环境,每个电脑都有浏览器,而像matplotlib需要Python这样的开发环境,还是比较麻烦的,但是毕竟 ...
- Socket编程实践(3) 多连接服务器实现与简单P2P聊天程序例程
SO_REUSEADDR选项 在上一篇文章的最后我们贴出了一个简单的C/S通信的例程.在该例程序中,使用"Ctrl+c"结束通信后,服务器是无法立即重启的,如果尝试重启服务器,将被 ...
- cocos2d-x屏幕分辨率,窗口大小总结
这个东西很烦人,相信很多人都不理解 今天来总结一下,首先有很多概念都要事先弄得清楚明白 1.屏幕分辨率 所谓屏幕分辨率相信很多人都知道他的概念,不就是1280pxX720PX吗?不就是这种形式吗?有什 ...
- C#面向对象设计模式纵横谈——3.Abstract Factory 抽象工厂(创建型模式)
动机(Motivation) 在软件系统中经常面临着“一系列相互依赖的对象”的创建工作,同时,由于需求变化,往往存在更多系列对象的创建工作.如何应对这种变化?如何绕过常规对象的创建,提供一种“封装机制 ...
- BZOJ 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 2012 Solved: 896[Submit][St ...
- dataTables添加序号和行选中框
<table id="mytable" class="table table-striped table-bordered" width="10 ...
- Non-blocking read on a subprocess.PIPE in python
import sys from subprocess import PIPE, Popen from threading import Thread try: from Queue import Qu ...
- css随笔1
1.简单清除浏览器样式 *{ padding: 0px; margin: 0px; } 2.得到屏幕范围的div html,body{ width: 1 ...
- CsvHelper支持List<T>
/// <summary> /// Csv帮助类 /// </summary> public class CsvHelper { /// <summary> / ...
- Windows10配置NFS服务端和客户端
环境:Windows10企业版x64 安装服务端 安装hane win nfs server,版本1169(官方最新版1223经试验不成功). 设置如下: 以管理员身份重启服务(注:软件界面上&quo ...