摘要:
We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, 阅读全文
摘要:
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A[i] and B[i]. Note that both elements are in the s 阅读全文
摘要:
Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get. 阅读全文
摘要:
假设数组是从小到大排序,数值可能为负数、0、正数。 思路一 可以一次性遍历一遍,找出绝对值最小值,此时时间复杂度为O(N),缺点是没有利用数组是有序的这一特点。 思路二 数组有序,可以利用二分查找的特性。中间的数是正数,往后找;中间的数是负数,往前找。 问题的本质是找到正数的最小值,或负数的最大值, 阅读全文