Leetcode 205 Isomorphic Strings 字符串处理
判断两个字符串是否同构
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 字符串处理的更多相关文章
- [leetcode]205. Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode 205. Isomorphic Strings (同构字符串)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)
翻译 给定两个字符串s和t,决定它们是否是同构的. 假设s中的元素被替换能够得到t,那么称这两个字符串是同构的. 在用一个字符串的元素替换还有一个字符串的元素的过程中.所有字符的顺序必须保留. 没有两 ...
- [leetcode]205. Isomorphic Strings同构字符串
哈希表可以用ASCII码数组来实现,可以更快 public boolean isIsomorphic(String s, String t) { /* 思路是记录下每个字符出现的位置,当有重复时,检查 ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
- [LeetCode] 205. Isomorphic Strings 解题思路 - Java
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Java for LeetCode 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- (easy)LeetCode 205.Isomorphic Strings (*)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Java [Leetcode 205]Isomorphic Strings
题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...
随机推荐
- 项目评价及第五周PSP的发布
5TH 各组作品ALPHA发布体会 1:俄罗斯方块组做了主要功能,这个项目我自己原来拿c语言做过一部分,感觉此游戏细节特别多,逻辑思维需要组织,以为我的水准来说,感觉做的挺好的. ...
- H5-杂七杂八的标签
1.overflow:设置当内容超出父级的宽高尺寸设置时的处理方式 a.hidden:隐藏超出部分的内容 b.auto:如果内容没有超出,就正常显示,如果超出,就隐藏内容并提供滚动条,可以滚动显示超出 ...
- protocol buffers的使用示例[z]
[http://blog.csdn.net/zhu_xun/article/details/19397081] protocol buffers的使用示例 如果不了解protocol buffers, ...
- c++垃圾回收代码练习 引用计数
学习实践垃圾回收的一个小代码 采用引用计数 每次多一个指针指向这个分配内存的地址时候 则引用计数加1 当计数为0 则释放内存 他的难点在于指针之间的复制 所有权交换 计数的变化 #include &l ...
- linux eclipse epic perl padwalker
1, 在Eclipse中安装EPIC:Help->Install New Software->Add:name:EPICLocation:http://e-p-i-c.sourceforg ...
- nop 添加字段
一.Libraries 1.core 层------------实体字段 2.data-Map----------映射到数据库 二.Admin 1.Models --------admin界面模型 ...
- linux 管道命令 竖线 ‘ | ’
管道符号,是unix功能强大的一个地方,符号是一条竖线:"|", 用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为comm ...
- SQL基础语法等
--1.while循环 declare @sum int declare @i int ) begin set @sum =@sum+@i ) print @i end print @sum --2. ...
- c#winform如何通过控件名查找控件
//根据控件名称查找控件 //作用根据控件的配置项目, Control[] myfindcs = this.Controls.Find("button4", true); if ( ...
- jquery_easyui 相关问题
1. datagrid点击title,无法进行客户端排序. 增加属性 data-options="singleSelect:true,collapsible:true,url:'/ViewS ...