Leetcode:205. Isomorphic Strings(JAVA)
来源:互联网 发布:mac无法识别u盘启动盘 编辑:程序博客网 时间:2024/06/16 05:28
【问题描述】
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.
【思路】
保存一个hashmap,保存映射关系
同时维护一个set,保证一个character不能被同时映射到两个字符上。
【code】
public class Solution { public boolean isIsomorphic(String s, String t) {if (s.length() != t.length()) {return false;}HashMap<Character, Character> map = new HashMap<Character, Character>();Set<Character> set = new HashSet<Character>();for (int i = 0; i < s.length(); i++) {char sc = s.charAt(i);char tc = t.charAt(i);if (map.containsKey(sc)) {if (map.get(sc) == tc) {continue;} else {return false;}}else {if (set.contains(tc)) {return false;}else {map.put(sc, tc);set.add(tc);}} }return true; }}
0 0
- Leetcode:205. Isomorphic Strings(JAVA)
- Isomorphic Strings Leetcode JAVA
- leetcode:Isomorphic Strings (java)
- 【leetcode】Isomorphic Strings【java】
- LeetCode|Isomorphic Strings-java
- 【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
- c++ 内存五区理解
- 移动web页面支持弹性滚动的3个方案
- HDOJ 1058Humble Numbers
- redhat6 yum
- 关于JAVA中URL传递中文参数,取值是乱码的解决办法
- Leetcode:205. Isomorphic Strings(JAVA)
- JAVA学习【10】JVM基础知识整理
- Android Studio导出Jar包
- 转载一篇写的不错的java ClassLoader工作机制的文章
- emma中文显示乱码问题解决
- 什么是通用项目周期?它有什么样的特点?对其它项目有什么启示?
- 【版本发布】JEECG 3.6.2 移动能力版发布,快速开发平台
- ubuntu 各种软件安装和使用
- 快速排序 约瑟夫问题 顺序查找 二分查找