LeetCode中的Isomorphic Strings 的java实现
来源:互联网 发布:在线报名系统 php 编辑:程序博客网 时间:2024/06/02 10:38
题目是全英文的,不过都是简单的英文,一般都可以完全看懂,题目如下:
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
public class Solution {
public boolean isIsomorphic(String s, String t) {
HashMap<Character, Character> ht = new HashMap<Character,Character>();
HashMap<Character, Character> hs = new HashMap<Character,Character>();
char[] sArray = s.toCharArray();
char[] tArray = t.toCharArray();
for(int i=0;i<s.length();i++)
{
for(char s1: ht.keySet())
{
if(sArray[i]==s1&&ht.get(s1)!=tArray[i])
{
return false;
}
}
ht.put(sArray[i], tArray[i]);
}
for(int i=0;i<t.length();i++)
{
for(char t1:hs.keySet())
{
if(tArray[i]==t1&&hs.get(t1)!=sArray[i])
{
return false;
}
}
hs.put(tArray[i], sArray[i]);
}
return true;
}
}
- LeetCode中的Isomorphic Strings 的java实现
- Isomorphic Strings Leetcode JAVA
- leetcode:Isomorphic Strings (java)
- 【leetcode】Isomorphic Strings【java】
- LeetCode|Isomorphic Strings-java
- [leetcode-205]Isomorphic Strings(java)
- Leetcode:205. Isomorphic Strings(JAVA)
- 【LeetCode】205 Isomorphic Strings (c++实现)
- LeetCode 205 - Isomorphic Strings
- [LeetCode] Isomorphic Strings
- [LeetCode] Isomorphic Strings
- [LeetCode 205]Isomorphic Strings
- LeetCode 205-Isomorphic Strings
- leetcode Isomorphic Strings
- leetcode(c++) Isomorphic Strings
- leetcode--Isomorphic Strings
- [LeetCode]Isomorphic Strings
- LeetCode OJ Isomorphic Strings
- 第三章第39题
- PDF文本转换成Word有什么好方法
- 点击添加,jsp页面表格自动添加一行
- shouldOverrideUrlLoading()重定向,无法返回跳出WebView的问题
- elasticsearch获取geo的点点之间的距离(distance)
- LeetCode中的Isomorphic Strings 的java实现
- MFC——ComBox用法大全
- 阿里巴巴Dubbo实现的源码分析
- c++学习(1)--explicit
- tar 基本操作
- Count and Say
- JVM -XX: 参数介绍
- 对人脸检测训练样本如何生成正样本描述文件和负样本集合文件
- FileStream类