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.

	 public static boolean isIsomorphic(String s, String t) {
if(s==null && t==null) return true;
else if(s.length()!=t.length()) return false;
Map<Character,Character> hm=new HashMap<Character,Character>();
for(int i=0;i<s.length();i++) {
if(hm.containsKey(s.charAt(i))) {
if(hm.get(s.charAt(i))!=t.charAt(i))
return false;
}
else if(hm.containsValue(t.charAt(i)))
return false; //开始的时候忘了这个条件,要注意一下
else
hm.put(s.charAt(i), t.charAt(i));
}
return true;
}

  

(String) 205.Isomorphic Strings的更多相关文章

  1. 205. Isomorphic Strings - LeetCode

    Question 205. Isomorphic Strings Solution 题目大意:判断两个字符串是否具有相同的结构 思路:构造一个map,存储每个字符的差,遍历字符串,判断两个两个字符串中 ...

  2. [leetcode]205. Isomorphic Strings 同构字符串

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

  3. 【刷题-LeetCode】205. Isomorphic Strings

    Isomorphic Strings Given two strings *s* and *t*, determine if they are isomorphic. Two strings are ...

  4. *205. Isomorphic Strings (string & map idea)

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

  5. LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)

    翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...

  6. LeetCode 205 Isomorphic Strings

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

  7. Java for LeetCode 205 Isomorphic Strings

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

  8. 205 Isomorphic Strings

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

  9. (easy)LeetCode 205.Isomorphic Strings (*)

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

随机推荐

  1. 1095: [ZJOI2007]Hide 捉迷藏

    题意:给定一棵树,每个节点可以变成黑白两色.一开始所有节点都是黑色,操作可将点颜色改变,询问当前情况下距离最远的两个黑点的距离. 动态树分治.一开始想的是对于每个节点维护主大和次大,后来发现这实在是太 ...

  2. awakeFromNib与viewDidLoad的区别

    当一个nib文件对应两个类,File's Owner的class为XXXViewController,Objects下的View对应的为XXXView时: awakeFromNib:在XXXView. ...

  3. 关于DButils的简单介绍

    android中的orm框架,一行代码就可以进行增删改查:支持事务,默认关闭:可通过注解自定义表名,列名,外键,唯一性约束,NOT NULL约束,CHECK约束等(需要混淆的时候请注解表名和列名)等等 ...

  4. C语言基础--函数

    函数概念: 1. C语言程序是由函数组成 2. 什么是函数? 函数就是一段具备特定功能的程序段 定义函数的目的: 定义函数的目的: 将一个功能封装以来方便复用 不使用函数的弊端: 1.重复代码太多, ...

  5. 链式编程中的next()和end()

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. window2008 r2 负载均衡

    两台服务器win2008 r2  ,iis7.5  ip地址192.168.5.16,  192.168.5.18  虚拟ip 192.168.5.30 设置过程: 1.在两台服务器上安装负载均衡模块 ...

  7. 安装生物信息学软件-MetaPhlAn2

    上周20161021-20161028的任务还没有搞完,所以今天来填坑(微笑脸) ××××××××××××××××××××我是萌萌哒分割线××××××××××××××××××××××××××××××× ...

  8. no package 'webkit-1.0' found

    linux安装程序的时候 ./configure 提示 no package 'webkit-1.0' found 解决方法: 安装 libwebkitgrk-dev包 1. sudo apt-get ...

  9. Python OpenCV —— bitwise

    关于图像的位操作,目的是为了将一个logo覆盖到另一个图片上. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 20: ...

  10. jQuery 中 offset()方法与用position()的区别

    jq中offset().left和offset().top获取的是相对于整个文档左上角的偏移. 而用$(selector).position().left和.top 取到的则是相对于selector父 ...