题解 | #农场智能分类系统#

农场智能分类系统

https://www.nowcoder.com/practice/a2c9a3fce4f141a3956fe67cd00cc3e2

题目考察的知识点:字符串

题目解答方法的文字分析:用map一个字符对应一个字符,判断是否相同;用s映射t,再用t映射s,都true,即返回yes。

本题解析所用的编程语言:c++

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @param t string字符串 
     * @return string字符串
     */
    bool _isIsomorphic(string& s, string& t)
    {
        if (s.size() != t.size())
            return "false";
        map<char, char> map;
        for (int i = 0; i < s.size(); ++i)
        {
            auto it = map.find(s[i]);
            if (it == map.end())
                map.insert(pair(s[i], t[i]));
            else  
                if (it->second != t[i])
                    return false;
        }
        return true;
    }
    string isIsomorphic(string s, string t)
    {
        // write code here
        if (_isIsomorphic(s, t) && _isIsomorphic(t, s))
            return "YES";
        return "NO";
    }
};

全部评论

相关推荐

湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务