【LeetCode】205. 同构字符串 - 数组

这里写自定义目录标题

  • [2023-8-29 16:32:00](#2023-8-29 16:32:00)

205. 同构字符串

2023-8-29 16:32:00

详细通俗的思路分析,多解法

重新了一遍解法二,下次再写这个题目,我要试一试用HashMap

java 复制代码
class Solution {
    public boolean isIsomorphic(String s, String t) {
        // 判断两个字符串翻译过后
        String sStr = heleper(s);
        String tStr = heleper(t);
        return sStr.equals(tStr);
    }

    private String heleper(String str){
        StringBuilder result = new StringBuilder();
        int[] times = new int[128];
        // 遍历字符串
        for(int i = 0; i < str.length(); i ++){
            // 找出字符
            char temp = str.charAt(i);
            // 如果这个字符是第一次出现,我们就把这个附一个新值
            // 如果不是的话,那我们就找到这个字符对应的值
            if(times[temp] == 0){
                times[temp] = i + 1;
            }
            result.append(times[temp]);
        }
        return result.toString();
    }
}
相关推荐
I_belong_to_jesus6 小时前
C++关于分支预测的优化1
开发语言·c++·算法
Code_Solitude13 小时前
C语言动态内存 + 柔性数组 + 数组名退化
c语言·算法·柔性数组
上海潭龙东海科技有限公司13 小时前
客运站管控之动态孪生技术方案(新增一屏管控模块
数据仓库·人工智能·算法·重构·动态规划
文丑颜不良啊14 小时前
LeetCode2821~2840题目解析
java·leetcode
YLCHUP15 小时前
【思维&图论建模】题解:债权(debt)_图论_建模_思路转化_思维题目_C++算法竞赛
c++·笔记·算法·数学建模·贪心算法·深度优先·图论
思麟呀16 小时前
背包DP(01背包+完全背包)
c++·算法
笑容掩饰我的失落17 小时前
区块链从小白到精通(七):Solidity 语法精讲——数据类型、函数、修饰器与事件
算法·区块链·php·智能合约·哈希算法
Pniubi18 小时前
力扣24. 两两交换链表中的节点(递归)
算法·leetcode·链表
꧁细听勿语情꧂19 小时前
直接选择排序,堆排序,冒泡排序,递归快速排序、hoare版本、挖坑法、lomuto前后指针,非递归快速排序
c语言·开发语言·数据结构·算法