![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
Leonardo711
这个作者很懒,什么都没留下…
展开
-
[Array] 560Subarray sum Equal k
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1: Input:nums = [1,1,1], k = 2 Output: 2Solution方法1:暴力解法for (int i原创 2017-05-05 17:50:56 · 389 阅读 · 0 评论 -
[Array]495.Teemo Attacking
Example 1:Input: [1,4], 2Output: 4Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately. This poisoned status will last 2 seconds until the end of time poi原创 2017-05-05 18:53:00 · 851 阅读 · 0 评论 -
[DP] 576Out of boundary path
题意不再赘述,大致解法是用动态规划。 N等于来自于4个方向N-1的解的和Solution方案:class Solution {public: int findPaths(int m, int n, int N, int i, int j) { int dp[51][50][50]; for(int Ni=1;Ni<=N;Ni++){原创 2017-05-08 00:16:08 · 406 阅读 · 0 评论 -
[LeetCode]378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not th原创 2017-04-25 18:01:38 · 305 阅读 · 0 评论 -
[leetcode.Tree]563. Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree nod原创 2017-04-26 11:25:25 · 499 阅读 · 0 评论 -
[Leetcode.Array]561. Array Partition I Add to List
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-04-26 11:53:15 · 547 阅读 · 0 评论 -
[leetcode]629. K Inverse Pairs Array
这道题可以根据题意,构造递归式,根据排列的最后一位是第几大的数可以得出递归式: d[n,k] = d[n-1,k]+d[n-1,k-1]+d[n-1,k-2]+… 区别n和k的大小,保证不越界,即可。另外注意结果要mod(1e9+7),一定要注意读题啊。 solution:class Solution {public: int kInversePairs(int n, int k)原创 2017-07-06 13:56:48 · 462 阅读 · 0 评论 -
c++单元测试框架Catch
Catch是一个不错的单元测试框架,帮助刷Leetcodegithub在此 使用也比较简单,最简单的方式就是直接下载Catch.hpp,做好引用。#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file#include "catch.hpp"#incl原创 2017-04-25 22:18:56 · 4200 阅读 · 1 评论