判断两个字符串是否同构

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. C#中TreeView与数据库绑定

    protected void CreateTreeView() { TreeNode rootNode = new TreeNode(); rootNode.Text = "全部" ...

  2. AngularJS学习--- 事件处理(Event Handlers) ng-click操作 step 10

    本文主要通过介绍ng-click方法来对angularjs中的事件处理方法做个了解. 1.切换目录 git checkout step- npm start 2.效果 点击右边的小图片,那么左边框中将 ...

  3. linux中的开机和关机命令

    与关机.重新启动相关的命令 * 将数据同步写入硬盘中的命令  sync * 惯用的关机命令  shutdown * 重新启动.关机  reboot halt poweroff sync 强制将内存中的 ...

  4. hdu 5748(LIS) Bellovin

    hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...

  5. Nodejs Buffer

    javascript中的字符串本身就是以字符来存储,而非字节,下面的例子可以说明: console.log("0123456789".length); console.log(&q ...

  6. UICollectionView进阶练习

    上一篇中的干货看完,不觉感觉还是有点虚,今天我们来点实的,做了两个小DEMO,源码已放GitHub,主要是针对UICollectionView做了联系.第一个DEMO是针对UICollectionVi ...

  7. sqlite query用法

    本文转自http://blog.csdn.net/double2hao/article/details/50281273,在此感谢作者 query(table, columns, selection, ...

  8. AT91-PWM应用

    步骤1: make menuconfig配置内核, 开启PWM输出功能. Device Drivers ---> Misc devices  ---> <*>Atmel AT3 ...

  9. 1531: [POI2005]Bank notes二进制优化(c++)

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  10. noip2014-day2-t2

    题意:在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点连通. 2 .在满足条件1 ...