【leetcode】【205】Isomorphic Strings
来源:互联网 发布:淘宝卖家新手教程 编辑:程序博客网 时间:2024/06/05 11:23
一、问题描述
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.
二、问题分析
显然是一种map的关系,可以使用HashMap来处理,比较简单。
三、Java AC代码
public boolean isIsomorphic(String s, String t) { HashMap<Character, Character> map = new HashMap<Character, Character>();if (s.length()!=t.length()) {return false;}char chs;char cht;for(int i=0;i<s.length();i++){chs = s.charAt(i);cht = t.charAt(i);if (!map.containsKey(chs)) {if (map.values().contains(cht)) {return false;}map.put(chs, cht);}else {if (map.get(chs).equals(cht)) {continue;}else {return false;}}}return true; }
0 0
- LeetCode 205 - Isomorphic Strings
- [LeetCode 205]Isomorphic Strings
- LeetCode 205-Isomorphic Strings
- leetcode 205: Isomorphic Strings
- leetcode 205 Isomorphic Strings
- LeetCode 205:Isomorphic Strings
- leetcode-205 Isomorphic Strings
- Isomorphic Strings - LeetCode 205
- Isomorphic Strings leetcode 205
- leetcode 205:Isomorphic Strings
- leetcode-205 Isomorphic Strings
- Isomorphic Strings(leetcode 205)
- leetcode[205]:Isomorphic Strings
- leetcode-205-Isomorphic Strings
- leetcode 205: Isomorphic Strings
- leetcode: (205) Isomorphic Strings
- [LeetCode 205] Isomorphic Strings
- Leetcode----205Isomorphic Strings
- # iOS_Search Path $(SRCROOT)和$(PROJECT_DIR)
- RecyclerView快速通用适配Adapter
- 工作大神重构代码
- atof and atoi
- sakai创建工具的过程,以roster2为例
- 【leetcode】【205】Isomorphic Strings
- CSS样式
- 跟着廖雪峰的git教程学习(2)时光机穿梭(二)工作区和暂存区
- ♥codeforces 627A-XOR Equation【数学】
- POJ 1106 扫描与OnLeft函数的使用
- Chrome 跨域访问
- STL中vector、list、deque和map的区别
- easyui reload方法报Cannot read property 'options' of undefined
- Android进程通信之一:两种序列化方式