dt&leetcode
文章平均质量分 69
<苦作舟>
这个作者很懒,什么都没留下…
展开
-
day11 leetcode(36,141,142)
只出现一次的数字 class Solution { public: int singleNumber(vector& nums) { int ret=0; for(auto e:nums) ret^=e; return ret; } }; 异或运算三个性质 1 任何数和0做异或结果还是原来的数 2 任何数和自身做异或结果为0 3 异或运算满足交换律和结合律 环形链表 class Solution { public: bool hasCycle(ListNode head) { if(headnul.原创 2021-01-22 17:26:24 · 146 阅读 · 0 评论 -
day10 leetcode(121,122,124)
买卖股票的最佳时机 class Solution: def maxProfit(self, prices: List[int]) -> int: minprice = float(‘inf’) maxprofit = 0 for price in prices: minprice = min(minprice, price) maxprofit = max(maxprofit, price - minprice) return maxprofit 买卖股票的最佳时机2 class Solution:.原创 2021-01-21 23:48:55 · 156 阅读 · 0 评论 -
day9 leetcode(88,89,104)
合并两个有序数组 class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { if(m == 0) { swap(nums1,nums2); return; } int a = m - 1; //指向数组nums1未排序元素末尾 int b = n - 1; //指向数组nums2末尾 int c = m + n - 1; //指向数组num.原创 2021-01-21 00:13:41 · 108 阅读 · 0 评论 -
day8 leetcode(62,70,78)
不同路径 class Solution { public: int uniquePaths(int m, int n) { vector dp(n); for(int i=0;i<n;i++) dp[i]=1; for(int j=1;j<m;j++){ for(int i=1;i<n;i++){ dp[i]+=dp[i-1]; } } return dp[n-1]; } }; 爬楼梯 class Solution { public: int climbStairs(int n) { v.原创 2021-01-19 23:38:13 · 72 阅读 · 0 评论 -
day7 leetcode(54.59,61)
螺旋矩阵 class Solution { public: vector spiralOrder(vector<vector>& matrix) { if(matrix.empty()) return {}; vector ans; int top=0; int bottom=matrix.size()-1; int left=0; int right=matrix[0].size()-1; while(true){ for(int i=left;i<=right;i++){ .原创 2021-01-19 00:03:03 · 97 阅读 · 2 评论 -
day7 leetcode(43,46,53)
字符串相乘 class Solution: def multiply(self, num1: str, num2: str) -> str: res=[0]*(len(num1)+len(num2)) for i in range(len(num1))[::-1]: carry=0 for j in range(len(num2))[::-1]: tmp=int(num1[i])*int(num2[j])+carry carry,res[i+j+1]=divmod((res[i+j+1]+tmp),.原创 2021-01-17 20:02:34 · 62 阅读 · 0 评论 -
day6 leetcode(23,26,33)
合并k个升序链表 类似昨天的合并两个升序链表,只需加以改进。将合并两个链表的作为另一个函数。将合并k个链表看作合并多个2个链表。 class Solution { public: ListNode * merge2(ListNode * l1,ListNode l2){ if(!l1||!l2) return l1?l1:l2; ListNode p,head; p=&head; while(l1&&l2){ if(l1->val>l2->val){ p->.原创 2021-01-16 19:37:13 · 122 阅读 · 0 评论 -
day5 leetcode(16,20,21)
三数之和 class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: nums.sort() n=len(nums) closest=float(‘inf’) for i in range(n): l,r=i+1,n-1 while l<r: cur_s=nums[i]+nums[l]+nums[r] cur_dif=cur_s-target if abs(cur_dif)<abs(clo原创 2021-01-15 22:31:11 · 66 阅读 · 0 评论 -
day3 leetcode(11,14,15)
盛最多水的容器 class Solution: def maxArea(self, height: List[int]) -> int: res,l,r=0,0,len(height)-1 while True: if l>r: break res=max(res,min(height[l],height[r])*(r-l)) if height[l]<height[r]: l+=1 else: r-=1 return res 最的相同前缀 class Solution { public原创 2021-01-13 23:40:13 · 69 阅读 · 0 评论 -
day 2 leetcode(7,8,9)
整数反转 字符串转换整数 回文数 整数反转 class Solution { public: int reverse(int x) { int sum=0; int pop=0; while(x!=0){ if(x<=pow(-2,31)||(x>=(pow(2,31)-1))) return 0; pop=x%10; x=x/10; if(sum>INT_MAX/10 || sumINT_MAX/10&&pop>7) return 0; if(sum.原创 2021-01-13 00:37:39 · 64 阅读 · 0 评论 -
day1 leetcode(2,4,5)
善始善终 这里写目录标题一级目录二级目录三级目录新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 一级目录 二级目录 三级目录 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markd原创 2021-01-11 23:27:53 · 159 阅读 · 0 评论