378. Kth Smallest Element in a Sorted Matrix
来源:互联网 发布:it luggage 编辑:程序博客网 时间:2024/05/22 10:46
public class Solution { public boolean guess(int g,int[][] matrix, int k, int n){ int sum = 0; for(int i = 0; i < n; i++){ int L = 0; int R = n-1; int ans = -1; while(L <= R){ int mid = (L + R) / 2; if(matrix[i][mid] < g){ ans = mid; L = mid + 1; }else{ R = mid - 1; } } sum += (ans + 1); } return k > sum; } public int kthSmallest(int[][] matrix, int k) { int n = matrix.length; int L = matrix[0][0]; int R = matrix[n-1][n-1]; int ans = 0; while(L <= R){ int mid = (int)(((long)L + R )/2); if(guess(mid,matrix,k,n)){ ans = mid; L = mid + 1; }else{ R = mid - 1; } } return ans; }}
阅读全文
0 0
- Kth Smallest Element in a Sorted Matrix
- Kth Smallest Element in a Sorted Matrix
- Kth Smallest Element in a Sorted Matrix
- Kth Smallest Element in a Sorted Matrix
- Kth Smallest Element in a Sorted Matrix
- Kth Smallest Element in a Sorted Matrix
- 378. Kth Smallest Element in a Sorted Matrix
- 378. Kth Smallest Element in a Sorted Matrix 解题报告
- LeetCode—378. Kth Smallest Element in a Sorted Matrix
- Leetcode 378. Kth Smallest Element in a Sorted Matrix
- [leetcode] 378. Kth Smallest Element in a Sorted Matrix
- LeetCode 378. Kth Smallest Element in a Sorted Matrix
- 【leetcode】378. Kth Smallest Element in a Sorted Matrix
- leecode 378. Kth Smallest Element in a Sorted Matrix java
- 378. Kth Smallest Element in a Sorted Matrix
- 378. Kth Smallest Element in a Sorted Matrix
- 【Leetcode】378. Kth Smallest Element in a Sorted Matrix
- Leetcode-378. Kth Smallest Element in a Sorted Matrix
- L1-017. 到底有多二
- Maven+Spring+SpringMVC+Mybatis的配置文件
- 判断整数溢出
- C# Enum枚举转 Dictionary字典
- JQuery 阻止默认行为
- 378. Kth Smallest Element in a Sorted Matrix
- 小程序与html5开发的差别(连载三)
- H5面试题---介绍js的基本数据类型
- 有趣的if语句
- 使用CXF框架开发一个简单的WebService
- 【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
- JavaScript学习之简单的放大镜
- Android中View的宽高测量结果为0的原因和解决方法
- 阵列,配额与LVM