[LeetCode] 205. Isomorphic Strings 解题思路 - Java
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.
问题:给定两个字符串,判断他们是否同构。
当字符串 s 中的字符可以被替换得到另一个字符串 t , 则表示字符串 s 和 t 是同构。
import static java.lang.System.out;
import java.util.Hashtable;
public class Solution {
public boolean isIsomorphic(String s, String t) {
Hashtable<Character, Character> s_t = new Hashtable<Character, Character>();
Hashtable<Character, Character> t_s = new Hashtable<Character, Character>();
int length = s.length();
for(int i = ; i < length; i++){
Character ss = s.charAt(i);
Character tt = t.charAt(i);
if(s_t.containsKey(ss) || t_s.containsKey(tt)){
if(s_t.get(ss) == tt && t_s.get(tt) == ss){
continue;
}else{
return false;
}
}else{
s_t.put(ss, tt);
t_s.put(tt, ss);
}
}
return true;
}
}
[LeetCode] 205. Isomorphic Strings 解题思路 - Java的更多相关文章
- Java for 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 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- 【LeetCode】205. Isomorphic Strings 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典保存位置 字典保存映射 日期 题目地址:http ...
- 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
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
- LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)
翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...
- (easy)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 ...
随机推荐
- Android群英传》读书笔记 (1) 第一章 Android体系与系统架构 + 第二章 Android开发工具新接触
第一章 Android体系与系统架构 1.Dalvik 和 ARTDalvik好比是一辆可折叠的自行车,平时是折叠的,只有骑的时候,才需要组装起来用.ART好比是一辆组装好了的自行车,装好就可以骑了. ...
- Apache POI解析excel文件
这里需要用到poi.jar和poi-ooxml.jar 没有的可以去http://mvnrepository.com/下载 import org.apache.poi.POIXMLDocument; ...
- 移动页面缩放方法之(二)控制HTML
<!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta http-equiv="Con ...
- Linux基本权限
首先需要我们了解的是,权限(rwx)对于文件和目录的作用是不一样的 . 权限对文件的作用 r : 读取文件内容(cat , more , head , tail) w: 编辑.新增.修改文件内容(vi ...
- Xcode7设置生成DSYM出现大量警告
看图,设置成这样就会出现大量的警告,解决方法如下: 将debug information format 更改为:DWARF即可
- Notepad++中查找替换回车符
用Nodepad++打开文件 View->Show Symbol->Show End of Line "End of Line"行结束符,由"CR" ...
- WebService笔记-Schema约束
Schema约束 俗话说得好 好记性不如烂笔头. 看了下WebService视频,觉得还是得下笔记. 观看的视频地址:http://edu.51cto.com/ ...
- MySQL Server 5.6 解压版安装配置
MySQL解压版下载地址为: http://dev.mysql.com/downloads/mysql/5.6.html#downloads 安装及配置步骤: ①将MySQL的zip包解压到路径C:\ ...
- Vim中安装delimitMate,auto-pairs插件不能输入中文问题
在安装了delimitMate插件之后发现不能正常使用中文输入了,输入法系统是ibus. 解决办法是在ibus的设置中的“在应用程序中使用内嵌编辑模式”这一项去除就可以正常输入中文了,看来可能是ibu ...
- IOC-控制反转(Inversion of Control),也成依赖倒置(Dependency Inversion Principle)
基本简介 IoC 亦称为 “依赖倒置原理”("Dependency Inversion Principle").差不多所有框架都使用了“倒置注入(Fowler 2004)技巧,这可 ...