【LeetCode】205. Isomorphic Strings

GitHub:https://github.com/BadWaka/leet-code-waka

思路

新建四个数组
mapA,mapB用来放置字符串中的元素,
arrA,arrB用来记录字符串在map中对应的位置

两次循环分别遍历两个字符串,并进行放置元素到map数组的操作和在arr中记录位置,完事后判断arrA和arrB是不是相等,如果相等,则返回true

测试示例

【LeetCode】205. Isomorphic Strings_第1张图片

【LeetCode】205. Isomorphic Strings_第2张图片
【LeetCode】205. Isomorphic Strings_第3张图片

【LeetCode】205. Isomorphic Strings_第4张图片

代码




    
    205. Isomorphic Strings


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.
Subscribe to see which companies asked this question.

给定两个字符串s和t,判断它们是否是同构的。
如果字符串s可以通过字符替换的方式得到字符串t,则称s和t是同构的。
字符的每一次出现都必须被其对应字符所替换,同时还需要保证原始顺序不发生改变。两个字符不能映射到同一个字符,但是字符可以映射到其本身。
测试样例如题目描述。
可以假设s和t等长。

你可能感兴趣的:(【LeetCode】205. Isomorphic Strings)