LeetCode:Isomorphic Strings
2016-01-12 11:06
513 查看
Isomorphic Strings
Total Accepted: 41849 TotalSubmissions: 150148 Difficulty: Easy
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
Hide Tags
Hash Table
code:
class Solution { public: bool isIsomorphic(string s, string t) { int str1[256]={0},str2[256]={0}; int n = s.size(); int m = t.size(); if(n != m) return false; for(int i=0;i<n;i++) { if(str1[s[i]] != str2[t[i]]) return false; str1[s[i]] = i+1; str2[t[i]] = i+1; } return true; } };
相关文章推荐
- Ubuntu下MySql配置
- [Leetcode] Distinct Subsequences 解题报告
- [LeetCode] Divide Two Integers 解题报告
- [LeetCode] Edit Distance 解题报告
- [LeetCode] First Missing Positive 解题报告
- [LeetCode] Flatten Binary Tree to Linked List 解题报告
- [LeetCode] Generate Parentheses 解题报告
- [LeetCode] Gray Code 解题报告
- [LeetCode] Implement strStr() 解题报告
- [LeetCode] Insert Interval 解题报告
- [LeetCode] Integer to Roman 解题报告
- [LeetCode] Interleaving String 解题报告
- [LeetCode] Jump Game 解题报告
- [LeetCode] Jump Game II 解题报告
- [LeetCode] Largest Rectangle in Histogram 解题报告
- [Leetcode] Length of Last Word 解题报告
- [LeetCode] Letter Combinations of a Phone Number 解题报告
- [LeetCode] Longest Common Prefix 解题报告
- [LeetCode] Longest Palindromic Substring 解题报告
- [LeetCode] Longest Substring Without Repeating Characters 解题报告