(easy)LeetCode 205.Isomorphic Strings (*)
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 (*)的更多相关文章
- [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 (同构字符串)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- 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 解题思路 - Java
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 ...
- LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)
翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...
- Leetcode 205 Isomorphic Strings 字符串处理
判断两个字符串是否同构 hs,ht就是每个字符出现的顺序 "egg" 与"add"的数字都是122 "foo"是122, 而"ba ...
随机推荐
- ASP.NET 4.0的ClientIDMode属性
时光流逝,我们心爱的ASP.NET也步入了4.0的时代,微软在ASP.NET 4.0中对很多特性做了修改.比如我将要讨论的控件ID机制就是其中之一. 在ASP.NET 4.0之前我们总是要为控件的Cl ...
- Flex相关案例及资源搜集
Flex一些例子: http://blog.minidx.com/ 上千个Flex例子,对于学习者来说是一个庞大的资源宝库. http://fleksray.org/Flex_skin.html ht ...
- 【spring】non-compatible bean definition of same name and class
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected excep tion parsing XML do ...
- mysql frm的恢复,data里只有frm文件的恢复
mysql frm的恢复,data里只有frm文件的恢复 mysql frm的恢复,data里只有frm文件的恢复,换了系统,装了windows2003,重装最新5.4版的mysql,把原来的一个数据 ...
- Hibernate3回顾-1-部署
web备份版本,详见doc版本. 一.背景(部署简单回顾) 我们知道,一个Hibernate快速上手的简单流程是这样. 1引入对应jar包. 中间涉及log4的jar包和配置,略. 2 实体类 pac ...
- IOS开发小项目—找色块游戏
1.项目代码: @interface NextViewController () { int r ;//色块层数的全局变量 int m;//后面用于tag值的变化 UIView *view;//色块 ...
- 剑指offer系列42---二叉树深度
[题目]输入一棵二叉树,求该树的深度. * 从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. package com.exe9.offer; /** * [题 ...
- 浅析:setsockopt()改善socket网络程序的健壮性
1. 如果在已经处于 ESTABLISHED状态下的socket(一般由端口号和标志符区分)调用closesocket(一般不会立即关闭而经历TIME_WAIT的过程)后想继续重用该socket:BO ...
- SecureCRT上传、下载文件 使用sz与rz命令
首先安装:apt-get install lrzsz SecureCRT这款SSH客户端软件同时具备了终端仿真器和文件传输功能.比ftp命令方便多了,而且服务器不用再开FTP服务了.rz,sz是便是L ...
- 3D视觉差---原生js+css
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...