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; } }
  • 相关阅读:
    线程进程之间的关系
    socket网络编程
    Docker在github上的站点
    大型网站架构体系的演变
    centos7 安装SSH
    如何在CentOS 7中禁用IPv6
    在 Docker 上运行一个 RESTful 风格的微服务
    docker 操作命令详解
    玩转Docker镜像
    搭建自己的 Docker 私有仓库服务
  • 原文地址:https://www.cnblogs.com/TonyYPZhang/p/5476191.html
Copyright © 2011-2022 走看看