Leetcode-205. Isomorphic Strings
来源:互联网 发布:netstat 监听端口 编辑:程序博客网 时间:2024/05/21 16:21
前言:为了后续的实习面试,开始疯狂刷题,非常欢迎志同道合的朋友一起交流。因为时间比较紧张,目前的规划是先过一遍,写出能想到的最优算法,第二遍再考虑最优或者较优的方法。如有错误欢迎指正。博主首发CSDN,mcf171专栏。
博客链接:mcf171的博客
——————————————————————————————
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.
public class Solution { public boolean isIsomorphic(String s, String t) { String patternS = getPattern(s); String patternT = getPattern(t); return patternS.equals(patternT); } public String getPattern(String s){ int number = 1; StringBuffer sb = new StringBuffer(""); Map<Character,Integer> str2number = new HashMap<Character,Integer>(); for(int i = 0; i < s.length(); i ++){ if(!str2number.containsKey(s.charAt(i))){ str2number.put(s.charAt(i),number); sb.append(number); number ++; }else{ sb.append(str2number.get(s.charAt(i))); } } return sb.toString(); }}
0 0
- 【LeetCode】205.Isomorphic Strings
- [leetcode] 205.Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- 205. Isomorphic Strings LeetCode
- 【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
- leetcode 205. Isomorphic Strings
- [leetcode] 205. Isomorphic Strings
- 205.[Leetcode]Isomorphic Strings
- leetcode 205. Isomorphic Strings
- 【leetcode】205. Isomorphic Strings
- [Leetcode]205. Isomorphic Strings
- LeetCode - 205. Isomorphic Strings
- 表单的内容如何存入数据库中
- 求教Android蓝牙串口开发OutputStream发送数据失败的问题。
- iOS用 afnetworking post给服务器,php获取到的中文是乱码
- 为什么我的网站谷歌和360浏览器打开乱码啊
- 改变继承UIButton的两个子类状态
- Leetcode-205. Isomorphic Strings
- Android版本的问题
- Delphi XE5 开发android环境配置
- 200分 android-vlc播放视频
- 如何在不同的手机上获得软键盘的高度
- GridView刷新问题
- nsxmlparser解析xml出错
- Leetcode-206. Reverse Linked List
- gradle上传maven私服时,遇到”Fail to resolve “错误