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.

题解:显然是哈希查找,但是其实没必要用map,一共就255个字符,每次只记录它现在的位置就好(因为之前的位置都比较过了)。

class Solution {
public:
bool isIsomorphic(string s, string t) {
int hs[]={};
int ht[]={};
int ls=s.length(),lt=t.length();
if(ls!=lt) return false;
for(int i=;i<ls;i++){
if(hs[s[i]]!=ht[t[i]]){
return false;
}
hs[s[i]]=i+;
ht[t[i]]=i+;
}
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同构字符串

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

  3. LeetCode 205 Isomorphic Strings

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

  4. LeetCode 205. Isomorphic Strings (同构字符串)

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

  5. Java for LeetCode 205 Isomorphic Strings

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

  6. (easy)LeetCode 205.Isomorphic Strings (*)

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

  7. Java [Leetcode 205]Isomorphic Strings

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

  8. [LeetCode] 205. Isomorphic Strings 解题思路 - Java

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

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

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

随机推荐

  1. selenium 遇到chrome 弹出是否保存密码框

    --待验证(以下是java脚本) ChromeOptions options = new ChromeOptions(); options.addArguments("--start-max ...

  2. 托管程序调用非托管dll问题总结

    托管程序Visual Basic.net, 非托管DLL标准C++程序(使用VC++编译) 函数调用定义 第一种写法: <DllImportAttribute("XXX.dll&quo ...

  3. web安全之SQL注入---第四章 如何进行SQL注入攻击

    第四章 如何进行SQL注入攻击1.数字注入2.字符串注入    '#    '--

  4. urllib.urlencode() 无法encode中文, UnicodeEncodeError

    urllib.urlencode() 无法encode中文, UnicodeEncodeError, 具体错误内容如下:File "/System/Library/Frameworks/Py ...

  5. P1009 阶乘之和

    P1009 阶乘之和 题目提供者洛谷OnlineJudge 标签数论(数学相关)高精1998NOIp提高组NOIp普及组 难度普及- 通过/提交1139/3791 提交该题 讨论 题解 记录 题目描述 ...

  6. LINQ分页工具

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Co ...

  7. Eight(经典题,八数码)

    Eight Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. ubuntu问题: 同时只能有一个软件管理工具在运行

    或者是: 只能同时运行一个更新管理器 打开终端输入命令:sudo dpkg –configure -a 运行,系统问题就解决了

  9. 【python】-- Socket接收大数据

    Socket接收大数据 上一篇博客中的简单ssh实例,就是说当服务器发送至客户端的数据,大于客户端设置的数据,则就会把数据服务端发过来的数据剩余数据存在IO缓冲区中,这样就会造成我们想要获取数据的完整 ...

  10. 如何使用Django实现用户登录验证

    最初开始搞用户登录验证的时候感觉没什么难的,不就是增删改查中的查询数据库么,但是还是遇到许多小问题,而且感觉在查询数据库的时候,要把前端的数据一条一条的进行比对,会导致我的代码很丑,而且方式很不智,所 ...