[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 ...
随机推荐
- Android上传文件到服务器(转)
Android中实现上传文件,其实是很简单的,和在java里面是一样的,基本上都是熟悉操作输出流和输入流!还有一个特别重要的就是需要配置content-type的一些参数!如果这些都弄好了,上传就很简 ...
- Python开发【第十三篇】:jQuery--无内容点击-不进去(一)
Python开发[第十三篇]:jQuery--无内容点击-不进去(一)
- Python之路,Day25-----暂无正在更新中
Python之路,Day25-----暂无正在更新中
- 洛谷 1503 鬼子进村 (set)
/*set加速维护*/ #include<iostream> #include<cstdio> #include<cstring> #include<set& ...
- Java 数据类型转换(转换成字节型)
package com.mystudypro.byteutil; import java.io.UnsupportedEncodingException; public class ConToByte ...
- 让ie8支持foreach
if ( !Array.prototype.forEach ) { Array.prototype.forEach = function forEach( callback, thisArg ) { ...
- (转)mysql 的 find_in_set函数使用方法
举个例子来说: 有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11,12,13等等 现在有篇文章他既是 头条,又是热点,还是图文, type中以 1 ...
- asp.net 读取sql存储过程返回值
关于Exec返回值的问题有很多,在这做个简要的总结. 读查询语句示例: Declare @count int select @Count 要点: ...
- B/S 獲取客戶端Mac地址
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx. ...
- Swift - 22 - 循环结构
//: Playground - noun: a place where people can play import UIKit // for-in for i in -99...99 { i * ...