栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Leetcode题库面试题2085. 统计出现过一次的公共字符串(python实现)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Leetcode题库面试题2085. 统计出现过一次的公共字符串(python实现)

文章目录
  • 思路
  • 代码
  • 题目变形:统计出现过一次的公共字符数量(c实现)

思路

有手就行 doge

代码
class Solution:
    def countWords(self, words1: List[str], words2: List[str]) -> int:
        ret=0
        for i in words1:
            if words1.count(i)==1 and words2.count(i)==1:
                ret+=1
        return ret
题目变形:统计出现过一次的公共字符数量(c实现)
void WordsStati(char ** words, int wordsSize, int* alpha){
    char *s;
    int flag=0,length=0;
    for(int i=0;i
        length+=strlen(words[i]);
    }
    s=(char*)malloc(sizeof(char)*length);
    for(int i=0;i
        for(int j=0;j
            s[flag++]=words[i][j];
        }
    }
    for(int i=0;i<26;i++){
        alpha[i]=0;
    }
    for(int i=0;i
        alpha[s[i]-'a']+=1;
    }
}

int countWords(char ** words1, int words1Size, char ** words2, int words2Size){
    int alpha_1[26],alpha_2[26];
    int ret,Length,i;
    ret=0;
    WordsStati(words1, words1Size,alpha_1);
    WordsStati(words2, words2Size,alpha_2);
    }
    for(i=0;i<26;i++){
        if(alpha_1[i]==1 && alpha_2[i]==1) ret++;
    }
    return ret;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/892915.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号