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. 1kkk

    代码: # !usr/bin/python3.4 # -*- coding:utf-8 -*- import requests import os import time import re from ...

  2. Oracle 支持正则表达式的函数

    内容提要 oracle 10g 增加的正则表达式函数有以下四种: regexp_like() --返回满足条件的字段 regexp_instr() --返回满足条件的字符或字符串的位置 regexp_ ...

  3. $_SERVER 相关变量

    PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用. $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root ...

  4. 【Log4j】 log4j.properties 使用

    一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session丢失 INFO 为一般要显示的信息,比如 ...

  5. 黄聪:360浏览器如何使用插件实现解除网页禁用右键复制的限制(Enable Copy)

    使用Enable Copy插件即可. 插件下载:Enable-Copy_v1.15.rar

  6. Java的安全性和可移植性

        Java的这两个特性,关键在于Java编译器的输出并不是可执行的代码,而是字节码 bytecode.      字节码是一套设计用来在Java运行时系统下执行的高度优化的指令集,该Java运行 ...

  7. unity客户端与c++服务器之间的简单通讯_1

    // 服务器 # pragma once using namespace std; # include <iostream> # include <string> # incl ...

  8. CE_现金的利息设定和计算(案例)

    2014-07-15 Created By BaoXinjian 一.摘要 存款利率指客户按照约定条件存入银行帐户的货币,一定时间内利息额同贷出金额即本金的利率.有活期利率和定期利率之分,有年/月/日 ...

  9. phpmyadmin数据库导入出错

    SQL 查询: -- phpMyAdmin SQL Dump-- version 3.5.1-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: ...

  10. [实变函数]5.5 Riemann 积分和 Lebesgue 积分

    1 记号: 一元函数 $f$ 在 $[a,b]$ 上的 (1)Riemann 积分: $\dps{(R)\int_a^b f(x)\rd x}$; (2)Lebesgue 积分: $\dps{(L)\ ...