博客园:https://www.cnblogs.com/grandyang/p/4465932.html GitHub:https://github.com/grandyang/leetcode/issues/4 个人网页:https://grandyang.com/leetcode/4/ 科技 计算机技术 Grandyang LeetCode 算法讲解 评论0 请先登录后发表评论 (・ω・) 发布 正在加载... ...
This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.
when I > k, sum[I] = sum[I - 1] + (sum[I - 1] - sum[I - k - 1]) 2.for problems that want you give a answer true or false, most of them can be solved by using dp. we can use sequence dp method. create a array, each item can[I] means whether Ith element can mee...
1classSolution {2publicdoublefindMedianSortedArrays(int[] nums1,int[] nums2) {3intlenA =nums1.length;4intlenB =nums2.length;5//make sure the first array is shorter6if(lenA >lenB) {7returnfindMedianSortedArrays(nums2, nums1);8}910//如果一个数组为空,直接计算另一个数组的中位数11if(l...
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) { int flag1 = 0; int flag2 = 0; int flag3 = 0; int *nums3 = (int *)malloc(sizeof(int )*(nums1Size + nums2Size)); while(flag1 < nums1Size && flag2 < nums2Size) { if(nums1[flag1...
Parts of the problems don't provide C interface for solution, so I accomplished them with C++ Language. CompileCfiles using command: CompileC++files using command: g++ -std=c++11 -Wall src/bar.cpp -o bar OR You can build all the files usingmake(Use MinGW GCC and GNU Make on Windows)....
Task: Given an array of integersnumswhich is sorted in ascending order, and an integertarget, write a function to searchtargetinnums. Iftargetexists, then return its index. Otherwise, return-1. Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 ...
下面的思路借鉴自讨论区(https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/discuss/91049/Java-O(n%29-solution-using-bit-manipulation-and-HashMap)的一个解法。现在 Medium 的题目居然也需要看解答了,叹气。 代码语言:javascript 代码运行次数:0 运行 复制 class Solution { public int...
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day) Example: 代码语言:javascript 代码运行次数:0 运行 复制 prices = [1, 2, 3, 0, 2]...
[438. 找到字符串中所有字母异位词](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) 【方法1】暴力解法 【方法2】滑动窗口 [538. 把二叉搜索树转换为累加树](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) 【方法1】反序中序遍历 [647. 回文子串](https://lee...