
LeetCode
Dynamic Programming
守着麦田的稻草人
这个作者很懒,什么都没留下…
展开
-
LeetCode 83. 删除排序链表中的重复元素
版本一class Solution {public: ListNode* deleteDuplicates(ListNode* head) { if(head==NULL)return head; ListNode * L=new ListNode(-1); L->next=head; while(head->next!=NULL){ ListNode* node=head->next;.原创 2021-07-12 16:16:57 · 85 阅读 · 0 评论 -
Leetcode 24. 两两交换链表中的节点
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。示例 1:输入:head = [1,2,3,4]输出:[2,1,4,3]class Solution {public: ListNode* swapPairs(ListNode* head) { //递归 //结束条件 head==null||head->next==null // 本层递归 i原创 2021-07-12 14:56:21 · 83 阅读 · 0 评论 -
力扣897. 递增顺序搜索树
class Solution {public: void dfs(TreeNode* root,vector<int>& v){ if(root==nullptr)return ; dfs(root->left,v); v.push_back(root->val); dfs(root->right,v); } TreeNode* increasingBST(TreeNode* r.原创 2021-05-13 20:07:16 · 80 阅读 · 0 评论 -
力扣 104 二叉树的最大深度
class Solution {public: int maxDepth(TreeNode* root) { if(root==nullptr)return 0; queue<TreeNode*>q; q.push(root); int ans=0; while(!q.empty()){ int t=q.size();//每层的节点数 while(t--){ .原创 2021-05-13 20:02:58 · 119 阅读 · 0 评论 -
LeetCode 63. Unique Paths II(DP)
第一次提交class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int dp[100][100]; int m=obstacleGrid.size(); int n=obstacleGrid[0].size(); if(obstacleGrid[0][0]==原创 2021-05-07 21:17:26 · 108 阅读 · 0 评论 -
LeetCode 121. Best Time to Buy and Sell Stock
You are given an array prices where prices[i] is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.Return the maximum profit原创 2021-04-25 19:17:26 · 109 阅读 · 0 评论 -
Leetcode 213. House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses原创 2021-04-24 20:59:25 · 131 阅读 · 0 评论 -
Leetcode 120. Triangle
Given a triangle array, return the minimum path sum from top to bottom.For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next r原创 2021-04-23 17:22:38 · 100 阅读 · 0 评论 -
Leetcode 198. House Robber(DP)
198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and原创 2021-04-22 21:04:52 · 85 阅读 · 0 评论