一、题目内容

image.png

二、题解

解法1:

思路

行维度倒叙剪枝

代码

  1. public class Solution {
  2. public int[] findElement(int[][] mat, int n, int m, int x) {
  3. // write code here
  4. int[] ans = new int[2];
  5. for(int i = n-1;i>=0;i--){
  6. if(mat[i][0]>x){
  7. continue;
  8. }
  9. for(int j = 0;j<m;j++){
  10. if(mat[i][j] == x){
  11. ans[0] = i;
  12. ans[1] = j;
  13. }
  14. }
  15. }
  16. return ans;
  17. }
  18. }