上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 25 下一页
思路1 卡塔兰数 代码 class Solution { public: int numTrees(int n) { long C = 1; for (int i = 0;i<n;++i) { C = C*2*(2*i+1)/(i+2); } return int(C); } }; Read More
posted @ 2021-09-26 15:41 A-inspire Views(16) Comments(0) Diggs(0) Edit
思路: l1 或 l2若有一者为空则返回非空链表若都非空,则判断 l1 和 l2 的val,val小的将其 next 递归添加到结果的节点递归终止条件:l1 或 l2 有一为空 代码: /** * Definition for singly-linked list. * struct ListNod Read More
posted @ 2021-09-26 15:39 A-inspire Views(19) Comments(0) Diggs(0) Edit
思路:递归求解某一棵树的左右节点,返回 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : v Read More
posted @ 2021-09-26 15:37 A-inspire Views(16) Comments(0) Diggs(0) Edit
思路 递归 用一个函数辅助判断左右子树是否完全对称,对根节点进行输入递归判断结果。 # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # sel Read More
posted @ 2021-09-26 15:36 A-inspire Views(22) Comments(0) Diggs(0) Edit
#思路 # 思路:定义一个当前节点,赋值为head,定义一个pre作为反转后的第一个节点,定义一个临时node 存放当前节点的下一个节点 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNod Read More
posted @ 2021-09-26 15:33 A-inspire Views(20) Comments(0) Diggs(0) Edit
思路:递归得到左右子树,交换左右子树,返回根节点 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x Read More
posted @ 2021-09-26 15:26 A-inspire Views(19) Comments(0) Diggs(0) Edit
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r Read More
posted @ 2021-09-26 15:25 A-inspire Views(20) Comments(0) Diggs(0) Edit
股票问题的方法就是 动态规划,因为它包含了重叠子问题,即买卖股票的最佳时机是由之前买或不买的状态决定的,而之前买或不买又由更早的状态决定的... 思路(官方题解方法二:一次遍历) 遍历一遍数组,计算每次 到当天为止 的最小股票价格和最大利润。定义一个变量保存最大利润,同时定义一个变量保存最小的股票价 Read More
posted @ 2021-09-26 15:24 A-inspire Views(15) Comments(0) Diggs(0) Edit
思路1 1.暴力解法,两重循环,从某一个下标开始,计算连续的和,求最大 代码 class Solution { public: int maxSubArray(vector<int> &nums) { //类似寻找最大最小值的题目,初始值一定要定义成理论上的最小最大值 int max = INT_M Read More
posted @ 2021-09-26 15:22 A-inspire Views(22) Comments(0) Diggs(0) Edit
代码: class Solution { public: vector<int> dailyTemperatures(vector<int>& T) { int length = int(T.size()); vector<int>result(length,0); //需要指定长度 stack<i Read More
posted @ 2021-09-26 15:16 A-inspire Views(16) Comments(0) Diggs(0) Edit
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 25 下一页