Triplet Sum Close to Target (medium) Triplets with Smaller Sum (medium) Subarrays with Product Less than a Target (medium) Dutch National Flag Problem (medium) 3. Pattern: Fast & Slow pointers, 快慢指针类型 这种模式,有一个非常出门的名字,叫龟兔赛跑。咱们肯定都知道龟兔赛跑啦。但还是再解释一...
982.Triples-with-Bitwise-AND-Equal-To-Zero (M+) (TBD) 1074.Number-of-Submatrices-That-Sum-to-Target (M+) 1487.Making-File-Names-Unique (M+) 1573.Number-of-Ways-to-Split-a-String (M) 2131.Longest-Palindrome-by-Concatenating-Two-Letter-Words (M) 2198.Number-of-Single-Divisor-Triplets...
Target Sum 45.7%Medium 538 Convert BST to Greater Tree 52.1%Easy 543 Diameter of Binary Tree 47.3%Easy 560 Subarray Sum Equals K 42.8%Medium 581 Shortest Unsorted Continuous Subarray 30.4%Easy 617 Merge Two Binary Trees 71.0%Easy 621
class Solution { public boolean canPartition(int[] nums) { int sum = 0; int max = nums[0]; for (int i : nums) { sum += i; max = Math.max(max, i); } if (sum % 2 == 1 || max > sum / 2) { return false; } int target = sum / 2; boolean[][] dp = new boolean...
Find out how many ways to assign symbols to make sum of integers equal to target S. Input: nums is [1, 1, 1, 1, 1], S is 3. Output: 5 Explanation: -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 ...
整个数组的和(sum)是可以很容易得到的,那么分成两个部分,每个部分的和(sum/2)也就可以很容易得到了。于是这道题就变成了,能不能从数组中找出一些数,使之和为 sum/2?搜索求解即可。 求解期间做一点小优化,创建一个<index, <target, partitionable>> 这样的结构,表示源数组的下标 index 开始往后到底的这一段...
1155 Number of Dice Rolls With Target Sum 47.70% Medium 1154 Day of the Year 50.10% Easy 1153 String Transforms Into Another String $ 35.60% Hard 1152 Analyze User Website Visit Pattern $ 43.20% Medium 1151 Minimum Swaps to Group All 1's Together $ 51.90% Medium 1150 Check If a Number...
publicclassSolution {publicString addBinary(String a, String b) {intcarry =0;String s ="";inti, j;for(i = a.length() -1, j = b.length() -1; i >=0&& j >=0; i--, j--) {intsum = carry + a.charAt(i) -'0'+ b.charAt(j) -'0';if(sum ==0) {s ='0'+ s;carr...
0325 Maximum Size Subarray Sum Equals k 46.8% Medium 0326 Power of Three Go 42.1% Easy 0327 Count of Range Sum Go 35.1% Hard 0328 Odd Even Linked List Go 55.7% Medium 0329 Longest Increasing Path in a Matrix Go 43.4% Hard 0330 Patching Array 34.5% Hard 0331 Verify Preorder Se...
0560 Subarray Sum Equals K 43.8% Medium 0561 Array Partition I Go 72.0% Easy 0562 Longest Line of Consecutive One in Matrix 45.8% Medium 0563 Binary Tree Tilt Go 48.7% Easy 0564 Find the Closest Palindrome 19.7% Hard 0565 Array Nesting 55.5% Medium 0566 Reshape the Matrix Go 60.5...