AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

LeetCode 953. 验证外星语词典    原题链接    (<Difficulty: 简单>,)

作者: 作者的头像   kidforever911 ,  2023-02-02 11:20:06 ,  所有人可见 ,  阅读 48


1


class Solution {
public:
    bool isAlienSorted(vector<string>& words, string order) {
        unordered_map<char, int> record;
        for(int i = 0; i < order.size(); i ++) record[order[i]] = i;
        for(int i = 0; i < words.size() - 1; i ++) {
            string a = words[i], b = words[i + 1];
            int x = 0, y = 0;
            while(x < a.size() && y < b.size()) {
                if(record[a[x]] > record[b[y]]) return false;
                if(record[a[x]] < record[b[y]]) break;
                x ++, y ++;
            }
            if(x < a.size() && y == b.size()) return false;
        }
        return true;
    }
};

1 评论


用户头像
candy.   1个月前         踩      回复

Orz


你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息