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) {
int []m1 = new int[256];
int []m2 = new int[256];
int len = s.length();
for (int i = 0; i < len; ++i) {
int m=s.charAt(i);
int n=t.charAt(i);
if(m1[m]!=m2[n])
return false;
m1[m] = i + 1;
m2[n] = i + 1;
}
return true;
}
}

运行结果:

  

(easy)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

    Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...

  3. LeetCode 205. Isomorphic Strings (同构字符串)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  4. Java for 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. git基本使用

    说明:当前在自己的分支:self:远端开发分支:dev. 1. 基本命令: git status git add . git commit -m 'modify' //从远端dev拉取 git pul ...

  2. IOS开发-UITextField代理常用的方法总结

    1.//当用户全部清空的时候的时候 会调用 -(BOOL)textFieldShouldClear:(UITextField *)textField: 2.//可以得到用户输入的字符 -(BOOL)t ...

  3. HackerRank "Morgan and a String"

    I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution: for _ in range ...

  4. HackerRank "Manasa and Prime game"

    Intuitive one to learn about Grundy basic :) Now every pile becomes a game, so we need to use Spragu ...

  5. Cacti不显示图片(nan)

    1.发现多半是SNMP的配置问题 被监控端安装snmp yum -y install net-snmp net-snmp-devel 被监控端安装配置snmp vim /etc/snmp/snmpd. ...

  6. .net下连接数据库

    可以新建一个按钮,在click事件下,写入一下代码 using( SqlConnection conn=new SqlConnection(Data source=.; Catalog Initial ...

  7. GCC 编译使用动态链接库和静态链接库

    1 库的分类 根据链接时期的不同,库又有静态库和动态库之分. 静态库是在链接阶段被链接的(好像是废话,但事实就是这样),所以生成的可执行文件就不受库的影响了,即使库被删除了,程序依然可以成功运行. 有 ...

  8. 1. Netty解决Tcp粘包拆包

    一. TCP粘包问题 实际发送的消息, 可能会被TCP拆分成很多数据包发送, 也可能把很多消息组合成一个数据包发送 粘包拆包发生的原因 (1) 应用程序一次写的字节大小超过socket发送缓冲区大小 ...

  9. 执行sh文件 进行MongoDB的业务逻辑导入

    将从HDFS中的数据转化为Json格式写入文件后,十个文件的文件名为 文件名_01 ...._02 ....03格式. 编写个简单的sh文件 通过for do循环让i+1 文件名对应上就可以的- -执 ...

  10. Oracle Erp常用网站

    2014-01-01 Created By BaoXinjian