(LeetCode)Isomorphic Strings --- 同构字符串
来源:互联网 发布:金属期货软件 编辑:程序博客网 时间:2024/05/20 08:25
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
解题分析:
这里的意思和前几天刷的一道题目很像。就是判断字符串的结构,这里可以说判断构成,
举例:
egg 与 add, 这里存储 e 对应着 a, g 对应着 d.然后再判断的时候发现有问题,对应不上,说明就不是同构的。
# -*- coding:utf-8 -*-__author__ = 'jiuzhang'class Solution(object): def isIsomorphic(self, s, t): s_list = list(s) t_list = list(t) if len(s) != len(t): return False sDict, tDict = {}, {} for i, j in zip(s_list, t_list): if i not in sDict: sDict[i] = j if j not in tDict: tDict[j] = i if tDict[j] != i or sDict[i] != j: return False return True
0 0
- (LeetCode)Isomorphic Strings --- 同构字符串
- Leetcode 205 Isomorphic Strings 同构字符串
- [LeetCode-205] Isomorphic Strings(同构字符串)
- LeetCode:Isomorphic Strings(同构字符串)
- [LeetCode]--205. Isomorphic Strings(同构字符串)
- [LeetCode] 205. Isomorphic Strings同构字符串
- Leetcode:205. Isomorphic Strings (同构字符串)
- 同构字符串 Isomorphic Strings
- Isomorphic Strings(同构字符串)
- Isomorphic Strings:同构字符串
- LeetCode205 Isomorphic Strings同构字符串
- LeetCode OJ 之 Isomorphic Strings(同构字符串)
- leetcode系列(17)Isomorphic Strings 同构字符串
- leetcode 205. Isomorphic Strings 同构字符串判断 + HashMap
- 205. Isomorphic Strings (同构字符串判断)
- LeetCode-Isomorphic Strings:判断两个字符串是否同构(hashtable实现)
- 【LeetCode-面试算法经典-Java实现】【205-Isomorphic Strings(同构字符串)】
- LeetCode 205 Isomorphic Strings(同构的字符串)(string、vector、map)(*)
- CoordinatorLayout高级用法-自定义Behavior
- SqlServer索引的原理与应用
- Cocos2d-x 小小的坐标编辑器
- 杭电-5695 Gym Class(拓扑排序)
- webStorage存储
- (LeetCode)Isomorphic Strings --- 同构字符串
- 能源物联网系列研究之一
- 在TFS上,使用tf workspace命令删除其他用户的工作区
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
- 深入剖析PHP输入流 php://input
- Nodejs实现简单爬虫,将爬到的数据以json数据格式保存到MySQL数据库中
- NOI2005 聪聪和可可
- 关于按钮监听器的那些事(笔记)
- zzuli oj 1918 晴天寻宝