![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode 实战
LeetCode 刻意练习
西在路上
这个作者很懒,什么都没留下…
展开
-
Task30.通配符匹配
LeetCode44.通配符匹配题目代码public class Solution { public bool IsMatch(string s, string p) { if (string.IsNullOrEmpty(p)) return string.IsNullOrEmp...原创 2020-03-30 20:25:42 · 111 阅读 · 0 评论 -
Task29.加油站
LeetCode134.加油站题目代码public class Solution { public int CanCompleteCircuit(int[] gas, int[] cost) { int count = gas.Length; int[] cost1...原创 2020-03-26 19:27:52 · 80 阅读 · 0 评论 -
Task28.跳跃游戏
LeetCode55.跳跃游戏题目代码public class Solution { public bool CanJump(int[] nums) { int lastPos = nums.Length - 1; for (int i = nums.Length - 1; i >= 0; i...原创 2020-03-26 16:11:04 · 79 阅读 · 0 评论 -
Task27.分发饼干
LeetCode455.分发饼干题目代码public class Solution { public int FindContentChildren(int[] g, int[] s) { Array.Sort(g); Array.Sort(s); int i = ...原创 2020-03-26 15:52:53 · 115 阅读 · 0 评论 -
Task26.判断子序列
LeetCode392.判断子序列题目代码使用双指针,慢指针控制短的字符串s,快指针控制字符串t,我们可以通过循环来依次比较,用t来依次与s对比,直达t到最后一个字符,返回时如果i移动的次数与s的长度是一致的那么就返回true,否则就返回false。public class Solution { public bool IsSubsequence(string s, s...原创 2020-03-26 14:50:24 · 81 阅读 · 0 评论 -
Task25.买卖股票的最佳时机II
LeetCode122.买卖股票的最佳时机II题目代码public class Solution { public int MaxProfit(int[] prices) { int sum = 0, i = 0; while (i < prices.Length - 1) ...原创 2020-03-25 21:02:29 · 90 阅读 · 0 评论 -
Task24.恢复二叉搜索树
LeetCode99.恢复二叉搜索树题目代码/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * pub...原创 2020-03-24 16:40:47 · 99 阅读 · 0 评论 -
Task23.不同的二叉搜索树II
LeetCode95.不同的二叉搜索树II题目代码/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * p...原创 2020-03-23 22:49:21 · 85 阅读 · 0 评论 -
Task22.二叉树的中序遍历
LeetCode94.二叉树的中序遍历题目代码/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * pub...原创 2020-03-22 21:03:51 · 109 阅读 · 0 评论 -
Task21.二叉树的最大深度
LeetCode104.二叉树的最大深度题目代码一,递归/** * Definition for a binary tree node. * * public class TreeNode { * * public int val; * * public TreeNode left; * * public TreeNode right...原创 2020-03-20 22:06:47 · 86 阅读 · 0 评论 -
Task20.对称二叉树
LeetCode101.对称二叉树题目代码一,递归/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * ...原创 2020-03-20 13:16:32 · 77 阅读 · 0 评论 -
Task19.相同的树
LeetCode100.相同的树题目代码一,递归时间复杂度:O(n)空间复杂度:O(n)/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public Tre...原创 2020-03-19 17:20:01 · 81 阅读 · 0 评论 -
Task18.正则表达式匹配
LeetCode10.正则表达式匹配题目代码public class Solution { public bool IsMatch(string s, string p) { bool[,] sp = new bool[s.Length + 1, p.Length + 1]; sp[s.Leng...原创 2020-03-18 22:10:14 · 109 阅读 · 0 评论 -
Task17.最长回文子串
LeetCode5.最长回文子串题目代码00原创 2020-03-17 19:37:02 · 87 阅读 · 0 评论 -
Task16.无重复字符的最长字串
LeetCode3.无重复字符的最长字串题目代码原创 2020-03-16 21:53:26 · 69 阅读 · 0 评论 -
Task.15有效的括号
LeetCode.20有效的括号题目代码public class Solution { public bool IsValid(string s) { if (s.Length == 0) return true; else if (s.Length...原创 2020-03-15 21:19:29 · 78 阅读 · 0 评论 -
Task14.最长公共前缀
LeetCode14.最长公共前缀题目我们可以将字符串数组的前两个字符串比较后得到新的具有公共前缀的新字符串,然后迭代不断更新公共前缀直到比较到最后一个字符串就得到了最大公共前缀。代码public class Solution { public string LongestCommonPrefix(string[] strs) { ...原创 2020-03-14 14:40:51 · 95 阅读 · 0 评论 -
Task13.罗马数字转整数
题目考虑到有些数字是由2个字符组成的,因此可以用string类提供的Replace方法。将2个字符表示的数值替换成1个字符。代码public class Solution { public int RomanToInt(string s) { s = s.Replace("IV", "A");//4 s = s.Replac...原创 2020-03-13 22:04:15 · 70 阅读 · 0 评论 -
Task12.合并K个排序链表
Task12.合并K个排序链表题目之前在21题我们合并的是两个有序链表,我使用了递归的方法,这道题合并K个有序链表,我想可以调用前面那个题的函数,主要思路就是一次合并,前两个合并后与下一个合并,合并后的再与下一个合并,一次类推。代码在这里插入代码片...原创 2020-03-12 18:11:48 · 82 阅读 · 0 评论 -
Task11.删除链表的倒数第N个节点
LeetCode 删除链表的倒数第N个节点题目代码/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) { val = x;...原创 2020-03-11 19:48:15 · 92 阅读 · 0 评论 -
Task10.两数相加
LeetCode 两数之和题目代码/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) { val = x; } * } */...原创 2020-03-10 14:09:09 · 113 阅读 · 0 评论 -
Task09.环形链表
LeetCode 环形链表题目代码/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ bool hasCycle(struct ListNode *head) { struc...原创 2020-03-09 21:34:08 · 72 阅读 · 0 评论 -
Task08.删除排序链表中的重复元素
LeetCode 删除排序链表中的重复元素题目代码/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* deleteDuplicates(struct ListNode* ...原创 2020-03-08 22:05:10 · 92 阅读 · 0 评论 -
Task07.合并两个有序链表
LeetCode 合并两个有序链表题目示例代码/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergeTwoLists(struct ListNode* l1, s...原创 2020-03-07 16:52:55 · 79 阅读 · 0 评论 -
Task06.买卖股票的最佳时机III
LeetCode 买卖股票的最佳时机III题目示例思路本题试了很多次思路都没能解决这个问题,然后学习了LeetCode的一些解法,最后学习了老马的解题思路,得以完成这个题。代码来源: https://mp.weixin.qq.com/s/0QZM_HXpPEkymeZlopwoSw代码int maxProfit(int* prices, int pricesSize){ ...原创 2020-03-06 21:45:09 · 94 阅读 · 0 评论 -
Task05.最接近的三数之和
Task05.最接近的三数之和题目代码实现int threeSumClosest(int* nums, int numsSize, int target){ int i,j,k,sum = 0; int num = 0,returnNum; int min =abs(target - (nums[0] + nums[1] + nums[2]...原创 2020-03-05 11:48:15 · 86 阅读 · 0 评论 -
Task04.三数之和
Task04.三数之和题目代码实现public class Solution { public IList<IList<int>> ThreeSum(int[] nums) { IList<IList<int>>result = new List<IList<int>>...原创 2020-03-04 22:16:20 · 69 阅读 · 0 评论 -
Task03.移除元素
Task03.移除元素题目代码实现原创 2020-03-03 16:06:26 · 79 阅读 · 0 评论 -
Task02.删除排序数组中的重复项
Task02.删除排序数组中的重复项题目双指针代码实现class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ ...原创 2020-03-02 18:20:49 · 117 阅读 · 0 评论 -
Task 01.两数之和
题目看到这个题,最先想到的一定是暴力法,使用两层循环,找到满足nums[i]+nums[j]==target的两个元素,这样子的时间复杂度就是O(n2),运算是相对很慢的,在Python语言下的运行时间达到了4000ms+甚至超出时间限制。代码实现暴力法是最为简单的一种方法,这种的结果就是运行速度慢,我们还可以采用...原创 2020-03-01 16:19:51 · 124 阅读 · 0 评论