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. SourceInsight支持Python代码阅读

    这个话题,很简单,主要是要有一个插件Python.CLF,这个文件可以从我的GitHub上下载.然后,参照下面的图片显示的步骤,就很快搞定! 具体的步骤,看下面的三张图片,顺序编号了,从1到9,对照着 ...

  2. 【转】调试Release发布版程序的Crash错误

    http://www.cppblog.com/Walker/archive/2012/11/08/146153.html http://blog.sina.com.cn/s/blog_48f93b53 ...

  3. ubuntu 安装 VISUAL STUDIO CODE

    1.下载VISUAL STUDIO CODE .DEB/.RPM 2. # For .deb sudo dpkg -i <file>.deb # For .rpm (Fedora and ...

  4. MySQL中order by中关于NULL值的排序问题

    MySQL中order by 排序遇到NULL值的问题 MySQL数据库,在order by排序的时候,如果存在NULL值,那么NULL是最小的,ASC正序排序的话,NULL值是在最前面的. 如果我们 ...

  5. DDD学习笔记二

    参考:感谢博主的分享... http://www.cnblogs.com/netfocus/archive/2012/02/12/2347938.html DDD ==> 领域驱动设计(Doma ...

  6. (ORA-12899) 10g数据库导入到11g数据库时报错

    问题: 10g数据库导入到11g数据库时,部分表的字段会出现ORA-12899的报错,如下: IMP-00019: 由于 ORACLE 错误 12899 而拒绝行       IMP-00003: 遇 ...

  7. 103. Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  8. VisualStudio 调试不提示调试错误

    尝试办法: 1.工具->选项->调试->启用异常助手;2.调试->异常; 解决办法: 把2.调试->异常; 下地全部钩上异常就弹出来了

  9. JavaScript权威指南 第二章 词法结构

    这章主要把保留字说一下 JavaScript 把一些标识符拿出来用做自己的关键字.因此,就不能再在程序中把这些关键字用做标识符了: break delete function return typeo ...

  10. 欧洲用户放弃Android转投iOS原因大起底

    据报道,近期在欧洲,有32.4%的新ios设备iPhone用户之前使用的是Android设备.那么为什么欧洲会有这么多Android用户会纷纷抛弃原有操作系统平台而转投iPhone呢? ios设备的同 ...