判断两个字符串是否同构

hs,ht就是每个字符出现的顺序

"egg" 与"add"的数字都是122

"foo"是122, 而"bar"是123

 class Solution {
public:
bool isIsomorphic(string s, string t) {
int hs[] = {};
int ht[] = {};
if (s.size() != t.size()) return false;
int o = ;
for (int i =;i<s.size(); ++i)
{
if(hs[s[i]] == ) hs[s[i]] = ++o;
}
o = ;
for (int i =;i<t.size(); ++i)
{
if(ht[t[i]] == ) ht[t[i]] = ++o;
}
for (int i = ;i<s.size(); ++i){
if(hs[s[i]] != ht[t[i]]) return false;
}
return true;
}
};

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 (同构字符串)

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

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

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

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

    哈希表可以用ASCII码数组来实现,可以更快 public boolean isIsomorphic(String s, String t) { /* 思路是记录下每个字符出现的位置,当有重复时,检查 ...

  5. LeetCode 205 Isomorphic Strings

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

  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. 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. (easy)LeetCode 205.Isomorphic Strings (*)

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

  9. Java [Leetcode 205]Isomorphic Strings

    题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...

随机推荐

  1. java.net.MalformedURLException: Illegal character in URL

    在进行接口测试时,意外发现返回结果报java.net.MalformedURLException: Illegal character in URL,意思是“在URL中的非法字符”,我的参数是经过ba ...

  2. springMVC配置(XML配置详解)

    原文出自:http://www.newasp.net/tech/71609.html web.xml配置: servlet> <servlet-name>dispatcher< ...

  3. HDU 1540 Tunnel Warfare(线段树+区间合并)

    http://acm.hdu.edu.cn/showproblem.php?pid=1540 题目大意:抗日战争期间进行地道战,存在n个村庄用地道连接,输入D表示破坏某个村庄(摧毁与其相连的地道, 包 ...

  4. java核心知识点学习----并发和并行的区别,进程和线程的区别,如何创建线程和线程的四种状态,什么是线程计时器

    多线程并发就像是内功,框架都像是外功,内功不足,外功也难得精要. 1.进程和线程的区别 一个程序至少有一个进程,一个进程至少有一个线程. 用工厂来比喻就是,一个工厂可以生产不同种类的产品,操作系统就是 ...

  5. SEO站长必备的十大常用搜索引擎高级指令

    作为一个seo人员,不懂得必要的搜索引擎高级指令,不是一个合格的seo.网站优化技术配合一些搜索引擎高级指令将使得优化工作变得简单.今日就和大家聊聊SEO站长必备的十大常用搜索引擎高级指令的那些事儿. ...

  6. JAVA基础之两种核心机制

    突然之间需要学习Java,学校里学的东西早就忘记了,得用最短的时间把Java知识理顺,重点还是J2EE,毕竟所有的ava项目中95%都是J2EE,还是先从基础的J2SE学起吧....... 首先是了解 ...

  7. Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型

    在项目上点击右键,找到构建路径.然后选择配置配置路径.按如下步骤来配置: 1 点击库选项 2把系统库扩展开来 3点击访问规则 4点击右边的添加按钮 5添加访问规则 6 分辨率设为可访问 7规则模式设为 ...

  8. PAT

    PAT将每个全局IP地址的可用端口号分为3个部分0~511,512~1023,1023~65535.当PAT从地址池中获取地址时,首先维持源端口不变.如果不可能,它再从池中起始部分搜索可用的端口,如果 ...

  9. Count and Say leetcode

    题目链接 The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 11 ...

  10. background-position的百分比

    看到了几篇文章,总结下先: 1. background-position是依赖于no-repeat的,在repeat的状态下和默认的状态下(默认即为repeat),background-positio ...