判断两个字符串是否同构

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. html5 -js判断undefined类型

    js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined所以自作聪明判断 var reVal ...

  2. 用python监控Linux,CPU,内存,硬盘

    #!/usr/local/bin/python3.5 #coding:utf-8 import mailll, linecache, re, socket, os, time hostname = s ...

  3. python的编码问题

    本文简单介绍了各种常用的字符编码的特点,并介绍了在python2.x中如何与编码问题作战 :) 请注意本文关于Python的内容仅适用于2.x,3.x中str和unicode有翻天覆地的变化,请查阅其 ...

  4. 初步认识JUnit

    初步认识JUnit 目前大多数的基于Java的企业应用软件,肯定少不了单元测试,程序员通过编写单元测试来验证自己程序的有效性:管理者通过持续自动的执行单元测试和分析单元测试覆盖率来确保软件本身的质量. ...

  5. 【译】RabbitMQ:"Hello World"

    简介 RabbitMQ是一个消息代理.从本质上讲,它从消息生产者处接收消息,然后传递给消息的消费者.它在消息的生产者和消费者之间根据你指定的规则对消息进行路由.缓存和持久化. RabbitMQ通常使用 ...

  6. iterator 及 迭代器模式(转发)

    Iterator definitions An iterator is any object that, pointing to some element in a range of elements ...

  7. svc6 控制台程序利用SoapToolkit3.0调用WebService

    1. 首先要安装SoapToolkit3.0安装包并安装(我的安装目录为:C:\Program Files\Common Files) 2. 新建vc控制台程序(空项目),项目名称:WinConsol ...

  8. 数据库操作(C#)

    数据库在软件开发中发挥着举足轻重的作用,基本上所有的大项目都会用到数据库.ADO .Net是一组向.Net程序员公开数据访问服务的类,其主要分为数据提供程序(Data Provider)和数据集(Da ...

  9. iOS键盘出现时界面跟着往上推

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UI ...

  10. 如何在 IIS 中设置 HTTPS 服务

    Windows Server2008.IIS7启用CA认证及证书制作完整过程 这篇文章介绍了如何安装证书申请工具: 如何在iis创建证书申请: 如何使用iis申请证书生成的txt文件,在工具中开始申请 ...