设为首页 加入收藏

TOP

LeetCode OJ Isomorphic Strings
2015-11-21 01:03:30 来源: 作者: 【 】 浏览:2
Tags:LeetCode 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.

?

bool isIsomorphic(char* s, char* t) {
	int letter1[256] = { 0 };
	for (int i = 0; s[i] != '\0'; i++) {
		if (!letter1[s[i]]) letter1[s[i]] = t[i];
		else if (letter1[s[i]] != t[i]) return false;
	}
	int letter2[256] = { 0 };
	for (int i = 0; t[i] != '\0'; i++) {
		if (!letter2[t[i]]) letter2[t[i]] = s[i];
		else if (letter2[t[i]] != s[i]) return false;
	}
	return true;
}

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 2955 Brackets 区间dp 下一篇CPP 1373 Easy as A+B(冒泡排序)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: