美文网首页
leetcode刷题-1

leetcode刷题-1

作者: foolgry | 来源:发表于2019-11-04 21:46 被阅读0次

小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一个猜。他们一共进行三次这个游戏,请返回 小A 猜对了几次?

输入的guess数组为 小A 每次的猜测,answer数组为 小B 每次的选择。guess和answer的长度都等于3。

示例 1:

输入:guess = [1,2,3], answer = [1,2,3]
输出:3
解释:小A 每次都猜对了。

示例 2:

输入:guess = [2,2,3], answer = [3,2,1]
输出:1
解释:小A 只猜对了第二次。

限制:

guess的长度 = 3
answer的长度 = 3
guess的元素取值为 {1, 2, 3} 之一。
answer的元素取值为 {1, 2, 3} 之一。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/guess-numbers
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

代码:

public int uniqueMorseRepresentations(String[] words) {
        String[] dict = new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        Set<String> set = new HashSet<>();
        for (String word : words) {
            StringBuilder sb = new StringBuilder();
            for (char s : word.toCharArray()) {
                sb.append(dict[s-'a']);
            }
            set.add(sb.toString());
        }
        return set.size();
    }
        ```
> 本文由博客一文多发平台 [OpenWrite](https://openwrite.cn?from=article_bottom) 发布!  

相关文章

  • leetcode刷题-1

    小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一...

  • leetcode刷题1

    用go语言做算法题 两数之和给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的...

  • 程序猿刷题网站你知道吗?

    Coderbyte 刷题网LeetCode 刷题网Stack Overflow 刷题网

  • 学习的书

    重来1 ,重来2 刷题 https://leetcode-cn.com/[https://leetcode-cn....

  • LeetCode刷题

    LeetCode刷题

  • 算法题之Median of Two Sorted Arrays

    重刷leetcode,刷到此题。描述: There are two sorted arrays nums1 and...

  • LeetCode刷题系列(1)

    突发奇想,感觉自己应该提升一下算法的能力,怎么办呢,来刷LeetCode吧! Leet Code OJ 1. Tw...

  • 8.30 leetcode刷题(1)

    栈和队列:20 有效的括号 思路:利用栈去做匹配,定义好哪种情况入栈,哪种情况出栈。最后还要判断一下栈是否为空 b...

  • LeetCode 刷题总结(1)

    1.两数之和 AC代码 思路 刚开始就是用双层for循环写,然后秉承着谦虚的态度看了题解,发现真的有O(N)的算法...

  • 每日一题之二叉树的深度

    Leetcode 第104题 好久没有刷题了,晋升挂了考虑换个工作了,开始刷题之路。 leetcode国内题库链接...

网友评论

      本文标题:leetcode刷题-1

      本文链接:https://www.haomeiwen.com/subject/qqdjbctx.html