We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
205. 同构字符串
给定两个字符串 s 和 t,判断它们是否是同构的。
如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的。
所有出现的字符都必须用另一个字符替换,同时保留字符的顺序。两个字符不能映射到同一个字符上,但字符可以映射自己本身。
示例 1:
输入: s = "egg", t = "add" 输出: true
示例 2:
输入: s = "foo", t = "bar" 输出: false
示例 3:
输入: s = "paper", t = "title" 输出: true
说明:
你可以假设 s 和 t 具有相同的长度。
The text was updated successfully, but these errors were encountered:
/** * @param {string} s * @param {string} t * @return {boolean} */ var isIsomorphic = function(s, t) { let mapS = {}, mapT = {}; for (let i = 0; i < s.length; i++) { if (!mapS[s[i]]) mapS[s[i]] = t[i]; if (!mapT[t[i]]) mapT[t[i]] = s[i]; if (mapS[s[i]] != t[i] || mapT[t[i]] != s[i]) return false; } return true; };
Sorry, something went wrong.
/** * @param {string} s * @param {string} t * @return {boolean} */ var isIsomorphic = function(s, t) { const mapS = new Map(); const mapT = new Map(); for (let i = 0; i < s.length; i++) { if (!mapS.has(s[i])) mapS.set(s[i], t[i]); if (!mapT.has(t[i])) mapT.set(t[i], s[i]); if (mapS.get(s[i]) !== t[i] || mapT.get(t[i]) !== s[i]) return false; } return true; };
No branches or pull requests
205. 同构字符串
给定两个字符串 s 和 t,判断它们是否是同构的。
如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的。
所有出现的字符都必须用另一个字符替换,同时保留字符的顺序。两个字符不能映射到同一个字符上,但字符可以映射自己本身。
示例 1:
示例 2:
示例 3:
说明:
The text was updated successfully, but these errors were encountered: