zoukankan      html  css  js  c++  java
  • 【leetcode】最短完整词

    char * shortestCompletingWord(char * licensePlate, char ** words, int wordsSize){
        char* s = (char *)calloc(strlen(licensePlate),sizeof(char));
        int i,j;
        int n=0;
        int pst = -1;
        int len = 16;
        int flag = true;
        for (i=0; i<strlen(licensePlate); i++)
        {
            if (licensePlate[i]>='a' && licensePlate[i]<='z') s[n++] = licensePlate[i];
            else if(licensePlate[i]>='A' && licensePlate[i]<='Z') s[n++] = licensePlate[i] + 32;
        }
        for (i=0; i<wordsSize; i++)
        {
            if (strlen(words[i]) >= len) continue;
            int* hash = (int *)calloc(26,sizeof(int));
            for (j=0; j<strlen(words[i]); j++)
            {
                hash[words[i][j] - 97]++;
            }
            for (j=0; j<n; j++)
            {
                hash[s[j]-97]--;
                if (hash[s[j]-97]<0) 
                {
                    flag = false;
                    break;
                }
            }
            if(flag)
            {
                pst = i;
                len = strlen(words[i]);
            }
            flag = true;
        }
        return words[pst];
    }
  • 相关阅读:
    fastlane
    OSI 模型
    iOS面试—0、技术点
    Git 提交规范
    iOS Aggregate 合并静态库
    iOS 应用分发平台
    json 转swift的工具
    敏捷开发
    mac 打包dmg
    iOS 获取素材
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13621022.html
Copyright © 2011-2022 走看看