判断两个字符串是否同构

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. thymeleaf 中文乱码问题

    使用thymeleaf后,即使使用org.springframework.web.filter.CharacterEncodingFilter也不能解决中文乱码问题了, 后来发现在org.thymel ...

  2. 卸载Oracle步骤

    卸载Oracle步骤:1.停止所有与ORACLE相关的服务.2. 使用OUI(Oracle Universal Installer)卸载Oracle软件.   “开始”->“程序”->“O ...

  3. 从php脚本到浏览器,编码方式浅析

    今天简单看了一下php,服务器,浏览器如何设定编码 1.php 在php配置文件php.ini中,可以设置字符编码 ; PHP's default character set is set to em ...

  4. Centos7 安装MPlayer过程详解

    使用自带的totem基本上都无法播放视频,各种格式都不支持,令人无语.想到了MPlayer,为了看片,决定编译安装,过程真的是折腾.如图是自带的Totem播放提示,安装了解码还是无法播放,反正要找其他 ...

  5. vb.net下载代码

    '后台 Partial Public Class Download2 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender ...

  6. 关于iphone、安卓手机VPN全面解析

    现在智能手机功能越来越强大,网络APP层出不穷,社交大佬facebook.twitter等纷纷推出了自己的社交APP应用,大部分手机已经内置了很多社交应用,包括facebook等:android.io ...

  7. B. Factory Repairs--cf627B(线段树)

    http://codeforces.com/problemset/problem/627/B 题目大意:  n代表天数 ,k代表每一次维修持续的天数,a代表维修过后每天能生产a件产品,b代表维修之前每 ...

  8. css标签选择器的优先级

    1.行内样式>嵌入式>外部样式(就近原者) 当外部样式在嵌入式的前面时就是外部样式为主 2.重复样式p{color:red}p{color:green}<p>是green< ...

  9. Pyhton开发堡垒机之paramiko模块

    堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: + ...

  10. 0001-Weekly Meeting on 13th and 20th March, 2015

    13th March, 2015 (1) Nearest Neighbors Using Compact Sparse Coding  ->appearing in ICML2014       ...