博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 205. Isomorphic Strings(哈希表)
阅读量:4617 次
发布时间:2019-06-09

本文共 777 字,大约阅读时间需要 2 分钟。

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[256]={
0}; int ht[256]={
0}; int ls=s.length(),lt=t.length(); if(ls!=lt) return false; for(int i=0;i

 

转载于:https://www.cnblogs.com/zywscq/p/5429131.html

你可能感兴趣的文章
兼容性
查看>>
自动执行sftp命令的脚本
查看>>
转 Merkle Tree(默克尔树)算法解析
查看>>
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>
strstr and strpos
查看>>
hash算法与拉链法解决冲突
查看>>
如何使用jQuery判断一个元素是否存在
查看>>
HTML5中的Canvas(颜色)【转载】
查看>>
420. Strong Password Checker
查看>>
用字节流添加内容至txt中
查看>>
jquery 1.9 1.8 判断 浏览器(IE11,IE8,IE7,IE6)版本
查看>>
达芬奇的十大经典名画解读
查看>>
case when then else end
查看>>
小程序丨嵌套循环
查看>>
Linux的基本命令+深入一点的网址分享
查看>>
(C#) Encoding.
查看>>