zoukankan      html  css  js  c++  java
  • [LeetCode] 205. 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.

    问题:给定两个字符串,判断他们是否同构。

    当字符串 s 中的字符可以被替换得到另一个字符串 t , 则表示字符串 s 和 t 是同构。

    import static java.lang.System.out;
    
    import java.util.Hashtable;
    
    public class Solution {
        public boolean isIsomorphic(String s, String t) {
    Hashtable
    <Character, Character> s_t = new Hashtable<Character, Character>(); Hashtable<Character, Character> t_s = new Hashtable<Character, Character>(); int length = s.length(); for(int i = 0; i < length; i++){
    Character ss
    = s.charAt(i); Character tt = t.charAt(i); if(s_t.containsKey(ss) || t_s.containsKey(tt)){ if(s_t.get(ss) == tt && t_s.get(tt) == ss){ continue; }else{ return false; } }else{ s_t.put(ss, tt); t_s.put(tt, ss); } } return true; } }
  • 相关阅读:
    Zepto跨域请求
    C语言中浮点数的比较
    IOS开源项目Telegram初试
    Java NIO初试
    ios8.0之后注册通知中心
    spring AOP的配置
    IOS学习日记-2014年10月25日
    struct框架中实体类中属性的类型错误问题
    Oracle存储过程使用DML语句问题
    跳出类似framset 嵌入式框架
  • 原文地址:https://www.cnblogs.com/TonyYPZhang/p/5476191.html
Copyright © 2011-2022 走看看