leetcode 205. Isomorphic Strings(哈希表)
2024-08-26 08:06:52
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;
}
};
最新文章
- Nopcommerce 二次开发1 基础
- 3.1 ARM汇编编程概述
- CentOS下搭建SVN
- MongoDB:实体对象(javabean)转DBObject
- jquery中奖实例代码
- SCCM客户端推送/卸载
- 3529: [Sdoi2014]数表 - BZOJ
- djano-cms学习笔计(一)
- python高级编程:有用的设计模式3
- 重拾python
- React之ref详细用法
- Ubuntu 16.04 设置MySQL远程访问权限
- Oracle创建新undo表空间最佳实践(包含段检查)
- Linux系统上面使用python切割nginx日志
- Python RabbitMQ RPC实现
- Mac安装使用MongoDB
- Flume 在有赞大数据的实践
- vue前后分离动态路由和权限管理方案
- kali Rolling 安装QQ和虚拟机
- net-snmp 的配置
热门文章
- staitic_cast原理与使用
- java工程中当前目录在html中的设置
- 【CodeM初赛A轮】D 分解质因数+暴力
- android菜鸟学习笔记22----ContentProvider(二)ContentObserver的简单使用
- JVM虚拟机参数
- centos下安装pip时失败:
- MyEclipse2014新增bug,尝鲜的朋友需注意NotFoundException: org.springframework.web.context.ContextLoaderListener
- ubuntu vim退出时出错
- 说说JavaScript 中的new吧
- springboot5