LeetCode 378. Kth Smallest Element in a Sorted Matrix
题目连结 http://tinyurl.com/y8sc949p
Given a n x n matrix where each of the rows and columns are sorted in
ascending order, find the kth smallest element in the matrix.
Note that it is the kth smallest element in the sorted order, not the kth
distinct element.
Example:
matrix = [[ 1, 5, 9],
[10,11,13],
[12,13,15]]
k = 8
return 13
目前正在研究用binary search解这题 http://tinyurl.com/ybqw4ubd
YUANGAO1023提到的Solution 2: Binary Search
大致的结构我都看懂了
但是不懂的是为什么是在while循环的最后
是else hi = mid; 而不是 else hi = mid - 1;
我有自己代数字实际跑一遍, else hi = mid; 是正确的,但是却不知道为什么这是正确
也不懂为什么 hi = mid - 1就不行
谢谢