[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 ...
随机推荐
- python之Lambda函数---笔记
<Python3 程序开发指南> Lambda函数,是一个匿名函数,创建语法: lambda parameters:express parameters:可选,如果提供,通常是逗号分隔的变 ...
- 使用python求字符串或文件的MD5
使用python求字符串或文件的MD5 五月 21st, 2008 #以下可在python3000运行. #字符串md5,用你的字符串代替'字符串'中的内容. import hashlib md5=h ...
- IntentFilter
当Intent在组件间传递时,组件如果想告知Android系统自己能够响应和处理哪些Intent,那么就需要用到IntentFilter对象. 顾名思义,IntentFilter对象负责过滤掉组件无法 ...
- css.day03.eg
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ManagementException:WMI异常处理介绍
.NET调用WMI后无论是同步调用还是异步调用,都会产生返回一个int类型的执行结果.如果成功,则返回0.如果不是0,则有对应错误码表示发生了什么错误. 根据咱们这个系列的博文,我总结了关于进程,服务 ...
- android - INSTALL_FAILED_MEDIA_UNAVAILABLE
解决方案是将'AndroidManifest.xml'设置 'installLocation'的属性为'auto'即可.
- sql问题
表中某个指标重复,去掉重复项: select * from #temp where A0107 in (select A0107 from #temp group by A0107having CO ...
- 【C++学习之路】组合类的构造函数
1 #include <iostream> using namespace std; class A { public: A(){ cout << "调用A无参&qu ...
- Qt中绘图坐标QPainter,Viewport与Window的关系
在Qt中常常要自己重载一些paintEvent函数,这个时候往往忽略了两个很关键的API,那就是setViewport和setWindow. Viewport,顾名思义,反应的是物理坐标,就是你实际想 ...
- bootstrap弹出框居中
1.html页面(如果效果出不来,注意修改单引号) <!DOCTYPE html> <html lang="zh-CN"> <head> < ...