leetcode---Isomorphic Strings
来源:互联网 发布:广东外语外贸大学知乎 编辑:程序博客网 时间:2024/06/03 18:53
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.
class Solution {public: string trans(string &s, int n) { char m[128] = {0}; char tmp = '0'; for(int i=0; i<n; i++) { if(m[s[i]] == 0) m[s[i]] = tmp++; s[i] = m[s[i]]; } return s; } bool isIsomorphic(string s, string t) { int n1 = s.length(); int n2 = t.length(); if(n1 != n2) return false; if(trans(s, n1) != trans(t, n1)) return false; return true; }};
0 0
- 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
- leetcode--Isomorphic Strings
- Spring4+Junit4单元测试及bug解决
- cocos2d-lua整合到ios工程
- Java经常出现的面试题
- Spring mvc+hibernate+freemarker(开源项目)
- Selector的用法
- leetcode---Isomorphic Strings
- php支持连接sqlserver数据库
- Java常用英语汇总
- java多线程(一)
- 牛顿迭代法求根
- Jenkins(二)---jenkins之Git+maven+jdk+tomcat
- 浅谈Java中的equals和==
- 拜山头
- python 读取 matalb .mat 文件