## Educational Codeforces Round 3 D – Gadgets for dollars and pounds

public class Solution extends VersionControl { public int firstBadVersion(int n) { int i = 1; int j = n; while(i<=j) { int m = i + (j-i) / 2; if(isBadVersion(m)) j = m – 1; else i = m + 1; } return i; } }

## H-Index II

public class Solution { public int hIndex(int[] citations) { int l = 0; int r = citations.length – 1; while(l<=r) { int m = l + (r-l) / 2; if(citations[m] < citations.length – m) l=m+1; else r=m-1; } return citations.length – l; } }

## [LintCode] Copy Books

public int copyBooks(int[] pages, int k) { // write your code here int l = 0; int r = 9999999; while( l <= r){ int mid = l + (r – l) / 2; if(search(mid,pages,k)) r = mid-1; else l = mid+1; } return l; } public boolean search(int total, int[] page, int k) { […]

## [LintCode] Search a 2D Matrix

public boolean searchMatrix(int[][] matrix, int target) { // write your code here if(matrix == null || matrix.length == 0) return false; int i = 0; int j = matrix[0].length-1; while(i < matrix.length && j >=0) { if(target == matrix[i][j]) return true; else if(target < matrix[i][j]) j–; else i++; } return false; }