IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    2020 第16周 LeetCode 记录

    Yiran\'s Blog发表于 2020-04-18 05:34:09
    love 0
    1408. String Matching in an Array 链接到标题 先按照单词长度进行排序,然后遍历判断当前单词是否被其他单词包含,要注意最终结果应该是去重之后的。 Golang 中可以直接使用 strings.Contains 判断。 type ByLen []string func (a ByLen) Len() int { return len(a) } func (a ByLen) Less(i, j int) bool { return len(a[i]) < len(a[j]) } func (a ByLen) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func stringMatching(words []string) []string { sort.Sort(ByLen(words)) res := []string{} for i := range words { for j := i + 1; j < len(words); j++ { if strings.


沪ICP备19023445号-2号
友情链接