Title LCP 1, guessing

I, entitled 1

Here Insert Picture Description

Second, the idea

Third, the code

public class LCP_1 {

    public static void main(String[] args) {

        //实例1 输出结果为3
//        int[] guess = {1,2,3};
//        int[] answer = {1,2,3};
//        System.out.println( game( guess, answer ));

        //实例2 输出结果为1
        int[] guess = {2,2,3};
        int[] answer = {3,2,1};
        System.out.println( game( guess, answer ));

    }

    public static int game(int[] guess, int[] answer) {

        int result = 0;

        for( int i = 0; i < guess.length; i++ ){
            if( guess[i] == answer[i] )
                result++;
        }

        return result;
    }
}

  1. : Power button (LeetCode)
    link: https: //leetcode-cn.com/problems/guess-numbers
    copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source. ↩︎

Published 48 original articles · won praise 1 · views 869

Guess you like

Origin blog.csdn.net/weixin_45980031/article/details/104117723