1 """ 2 Given a binary tree, find its maximum depth. 3 The maximum depth is the number of nodes along the longest path from the root node down to the ...
分类:
其他好文 时间:
2020-02-02 23:16:12
阅读次数:
93
分析: 完整代码: // 最长公共子序列 #include <stdio.h> #include <algorithm> using namespace std; const int N = 100; char A[N], B[N]; int dp[N][N]; int main() { freop ...
分类:
其他好文 时间:
2020-02-01 14:15:10
阅读次数:
61
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath betwee ...
分类:
其他好文 时间:
2020-02-01 11:02:57
阅读次数:
105
1. 字符串的声明是使用 package main import "fmt" func main() { /* Go中的字符串是一个字节的切片。 可以通过将其内容封装在“”中来创建字符串。Go中的字符串是Unicode兼容的,并且是UTF-8编码的。 字符串是一些字节的集合。 理解为一个字符的序列。 ...
分类:
其他好文 时间:
2020-02-01 10:31:14
阅读次数:
86
Python3,双指针,注意K为0的情况。 class Solution: def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int: if k == 0: return 0 charMap = {} result = 0 ...
分类:
其他好文 时间:
2020-01-31 15:49:02
阅读次数:
57
要注意边和节点数是不一样的 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None cl ...
分类:
其他好文 时间:
2020-01-31 10:21:14
阅读次数:
76
Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s. ...
分类:
其他好文 时间:
2020-01-31 00:59:06
阅读次数:
67
转自 https://leetcode-cn.com/problems/longest-palindromic-substring/solution/zhong-xin-kuo-san-dong-tai-gui-hua-by-liweiwei1419/ ...
分类:
其他好文 时间:
2020-01-30 20:58:05
阅读次数:
71
题目链接 题目描述 设G为有n个顶点的有向无环图,G中各顶点的编号为1到n,且当为G中的一条边时有i < j。设w(i,j)为边的长度,请设计算法,计算图G中<1,n>间的最长路径。 输入格式 输入文件longest.in的第一行有两个整数n和m,表示有n个顶点和m条边,接下来m行中每行输入3个整数 ...
分类:
其他好文 时间:
2020-01-30 20:50:28
阅读次数:
88
1. Two sum 因为只有一个solution(pair),所以一旦发现解返回即可。使用unordered_map或者unordered_set存当前数字,找complement. 2. Add two number 双指针,使用dummy作为返回链表。 3. Longest substring ...
分类:
其他好文 时间:
2020-01-30 09:17:40
阅读次数:
68