LeetCode 226Isomorphic Strings
来源:互联网 发布:dnf一上线就网络中断 编辑:程序博客网 时间:2024/06/05 04:26
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.
Note:
You may assume both s and t have the same length.
题目要求判断一个字符串中是否可以有另一个字符串中得数字替换而来.
其实就是找映射关系,而且这种映射关系是一一对应的。
C++:
class Solution {public: bool isIsomorphic(string s, string t) { int len1=s.length(); int len2=t.length(); if(len1!=len2) return false; vector<int>v(200,-1); //存放映射关系 bool vis[200]={0}; //检验映射关系的唯一性 int i=0; int j=0; string temp=t; while(j<len1) { if(v[temp[j]]!=-1) temp[j]=v[temp[j]]; else { if(vis[s[j]]==0) { v[temp[j]]=s[j]; temp[j]=s[j]; vis[s[j]]=1; } else break; } j++; } if(temp==s && j==len1) return true; return false; }};
0 0
- LeetCode 226Isomorphic Strings
- LeetCode 205 - Isomorphic Strings
- [LeetCode] Isomorphic Strings
- Isomorphic Strings Leetcode JAVA
- [LeetCode] Isomorphic Strings
- [LeetCode 205]Isomorphic Strings
- LeetCode 205-Isomorphic Strings
- leetcode Isomorphic Strings
- leetcode(c++) Isomorphic Strings
- leetcode--Isomorphic Strings
- [LeetCode]Isomorphic Strings
- LeetCode OJ Isomorphic Strings
- leetcode 205: Isomorphic Strings
- leetcode 205 Isomorphic Strings
- [leetcode] Isomorphic Strings
- 【leetcode】Isomorphic Strings
- [leetcode]Isomorphic Strings
- [LeetCode]Isomorphic Strings
- 电子邮件
- Android学习进阶路线导航线路
- Collection & set
- [leetcode-11]container with most water(C)
- Java面向对象之继承
- LeetCode 226Isomorphic Strings
- 每天一个linux命令(11):nl命令
- 算阶乘
- IOS中关闭滚动条
- Java中接口与多态
- 2015-07-26总结
- 谷歌镜像收集
- eclipse 文件同步插件
- Java 连接数据库(SQL Server)ODBC配置详情