492. Construct the Rectangle
class Solution(object):
def constructRectangle(self, area):
"""
:type area: int
:rtype: List[int]
"""
mid = int(math.sqrt(area))
while mid > 0:
if area % mid == 0:
return [int(area / mid), int(mid)]
mid -= 1521. Longest Uncommon Subsequence I
class Solution(object):
def findLUSlength(self, a, b):
"""
:type a: str
:type b: str
:rtype: int
"""
if a == b:
return -1
return max(len(a), len(b))530. Minimum Absolute Difference in BSTpublic class Solution {
int min = Integer.MAX_VALUE;
Integer prev = null;
public int getMinimumDifference(TreeNode root) {
if (root == null) return min;
getMinimumDifference(root.left);
if (prev != null) {
min = Math.min(min, root.val - prev);
}
prev = root.val;
getMinimumDifference(root.right);
return min;
}
}
本文介绍了解决两个经典算法问题的方法:构造面积给定的最小差值矩形和寻找两字符串间的最长不同子序列。对于矩形构造问题,通过寻找接近平方根的因数来获得最佳长宽比;而不同子序列问题,则直接比较两个字符串并返回最长的一个。

被折叠的 条评论
为什么被折叠?



