Strings Homomorphism
来源:互联网 发布:李涛疯狂淘宝上市 编辑:程序博客网 时间:2024/05/29 21:17
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.
注意事项
You may assume both s and t have the same length
.
样例
Given s = "egg"
, t = "add"
, return true
.
Given s = "foo"
, t = "bar"
, return false
.
Given s = "paper"
, t = "title"
, return true
.
解题思路:用两个map进行记录,若每个map的值对应全部相等则返回true,否则false。
解题代码:
class Solution {public: /** * @param s a string * @param t a string * @return true if the characters in s * can be replaced to get t or false */ bool isIsomorphic(string& s, string& t) { // Write your code here if(s.size()!=t.size())return false; map<char,int>test,comp; for(int i=0;i<=s.size();i++)test[s[i]]++,comp[t[i]]++; int flag=0; for(int i=0;i<=s.size();i++){ if(flag)break; if(test[s[i]]!=comp[t[i]])flag=1; } if(flag)return false; return true; }};
阅读全文
0 0
- Strings Homomorphism
- Strings Homomorphism
- Strings Homomorphism
- Strings Homomorphism
- lintcode(638)Strings Homomorphism
- LintCode之Strings Homomorphism
- LintCode python 小白-简单题-638-Strings Homomorphism
- Lie group homomorphism
- Strings
- Strings
- strings
- Strings
- Strings
- Strings
- strings
- Strings
- 图同构(graph isomorphism)和图同态(graph homomorphism)
- Foundation - strings
- 排序--冒泡排序
- vb.net 教程 5-7 Bitmap类 2
- JAVA——IO流 之 节点流和处理流以及流的关闭顺序(5)
- Java中字符串截取使用
- 服务器测试包含的主要测试
- Strings Homomorphism
- xml文件的生成和解析
- 高精度计算之基础
- 全码倍数搜索
- CIFAR-10数据集可视化二进制版本
- Android Studio项目用Git上传至码云(OSChina)
- POJ225 Dungeon Master BFS
- HTML5中的canvas
- 输入一个数num,编程输出有几对质数的和等于num,