输入一个整型数组,数组里有正数也有负数。数组中的一个或连续多个整数组成一个子数组。求所有子数组的和的最大值。 要求时间复杂度为O(n)。 很简单的一道题, 但是犯了不少错误,主要在于ret和curmax的初值。每一步都要和ret比较一下。 1 class Solution { 2 public: 3 ...
分类:
其他好文 时间:
2020-07-18 11:26:32
阅读次数:
59
链接:https://leetcode-cn.com/problems/unique-binary-search-trees/ 代码 class Solution { public: int numTrees(int n) { vector<int> f(n + 1); f[0] = 1; for ...
分类:
其他好文 时间:
2020-07-18 11:25:21
阅读次数:
56
链接:https://leetcode-cn.com/problems/interleaving-string/ 代码 class Solution { public: bool isInterleave(string s1, string s2, string s3) { int n = s1.s ...
分类:
其他好文 时间:
2020-07-18 11:21:07
阅读次数:
43
1 class Solution { 2 public int searchInsert(int[] nums, int target) { 3 int length = nums.length; 4 int left = 0, right = length - 1, ans = 0; 5 whil ...
分类:
其他好文 时间:
2020-07-18 00:57:17
阅读次数:
92
判断S2是否是S1的扰乱字符串。根据题目的定义,S1如果经过若干次对于部分子串的翻转操作能够得到S2,则S2是S1的扰乱字符串。 首先,如果S2是S1的扰乱字符串,那么S1中每个字符的出现次数必然和S2中每个字符的出现次数一致,也就是说,我们用两个字符串S3、S4备份一下S1和S2, 对S3和S4排 ...
分类:
其他好文 时间:
2020-07-18 00:42:29
阅读次数:
62
思路 二分查找,注意如果target不在数组中时,需要判断一下下标 代码 class Solution { public int searchInsert(int[] nums, int target) { //二分查找 int left = 0; int right = nums.length - ...
分类:
其他好文 时间:
2020-07-18 00:42:00
阅读次数:
64
XProtect installer may fail with the error "Category does not exist" or "Cannot load Counter Name data because an invalid index" When running the XPro ...
分类:
其他好文 时间:
2020-07-17 19:49:17
阅读次数:
124
题目链接 题目传送门 简要题意 有一个长度为 \(k\) 的数组 \(a\),每次可以选择一个 $1\le i\le k$,让 \(a_i\) 加上 \(k-1\),并对于所有的 \(j\ne i\) 让 \(a_j\) 减掉 $1$,任何时候必须保证 \(a\) 数组非负。 求通过任意多次(可以为 ...
分类:
其他好文 时间:
2020-07-17 19:47:56
阅读次数:
80
1前言 昨天武小栈把typecho从正式版升级到开发版就遇到了Database Query Error错误,详情是SQLSTATE[HY000]: General error: 1 no such table: typecho_metas,经过查看数据库后发现是升级的时候metas表被程序删掉了,顺 ...
分类:
数据库 时间:
2020-07-17 16:01:49
阅读次数:
92
题目描述: 第一次提交:通过76/78 留坑 class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: dic = {} l = [] for i in range(len(graph)): if graph[i] ...
分类:
其他好文 时间:
2020-07-17 14:14:05
阅读次数:
61