在行列都排好序的矩阵中找指定的数

时间O(M*N) 空间O(1)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.nextInt();
        in.nextInt();
        int k = in.nextInt();
        while (in.hasNextInt()) {
            int a = in.nextInt();
            if(a==k) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}