Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. 这道题是之前那道Permutations 全排列的延伸,由于输入数组有可能出现重复数字,如果按照之前的算法运算,会有…
import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://oj.leetcode.com/problems/combination-sum/ * * Created by lverpeng on 2017/7/14. * * Given a set of candidate numbers (C) and a target number (T), find…
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the r…
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Hint: Expected runtime complexity is in O(log n) and the input is sorted. 这题是之前那道H-Index 求H指数的拓展,输入数组是有序的,让我们在O(log n)的时间内完成计算,看到这个时间复…
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,If S = [1,2,2], a solution is:…
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 这道题是之前那道N-Queens N皇后问题 的延伸,说是延伸其实我觉得两者顺序应该颠倒一样,上一道题比这道题还要稍稍复杂一些,两者本质上没有啥区别,都是要用回溯法Backtracking来解,如果理解了之前那道题的思路,此题只要做很小的改动即可,不…
原题链接在这里:https://leetcode.com/problems/h-index-ii/ 题目: Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? 题解: 与H-Index类似.已经排好序,直接二分法查找即可. Time Complexity: O(logn). Space: O(1). AC Java:…