自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(12)
  • 收藏
  • 关注

原创 蓝桥杯 0 1字串

蓝桥杯 0 1字串问题描述对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:0000000001000100001100100请按从小到大的顺序输出这32种01串。做完之后发现基本上都使用了多重循环嵌套的方式,我认为按照10进制转2进制的方法,时间复杂可能会低一些。#include<iostream>using namespace std;#include<string>int main() { int i,len,k;

2021-04-05 14:36:05 281

原创 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 任何数和自身做异或结果为03 异或运算满足交换律和结合律环形链表class Solution {public:bool hasCycle(ListNode head) {if(headnul.

2021-01-22 17:26:24 139

原创 day10 leetcode(121,122,124)

买卖股票的最佳时机class Solution:def maxProfit(self, prices: List[int]) -> int:minprice = float(‘inf’)maxprofit = 0for price in prices:minprice = min(minprice, price)maxprofit = max(maxprofit, price - minprice)return maxprofit买卖股票的最佳时机2class Solution:.

2021-01-21 23:48:55 146

原创 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 102

原创 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 68

原创 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 91 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=0for j in range(len(num2))[::-1]:tmp=int(num1[i])*int(num2[j])+carrycarry,res[i+j+1]=divmod((res[i+j+1]+tmp),.

2021-01-17 20:02:34 54

原创 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-&gt.

2021-01-16 19:37:13 114

原创 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-1while l<r:cur_s=nums[i]+nums[l]+nums[r]cur_dif=cur_s-targetif abs(cur_dif)<abs(clo

2021-01-15 22:31:11 61

原创 day3 leetcode(11,14,15)

盛最多水的容器class Solution:def maxArea(self, height: List[int]) -> int:res,l,r=0,0,len(height)-1while True:if l>r:breakres=max(res,min(height[l],height[r])*(r-l))if height[l]<height[r]:l+=1else:r-=1return res最的相同前缀class Solution {public

2021-01-13 23:40:13 63

原创 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 56

原创 day1 leetcode(2,4,5)

善始善终这里写目录标题一级目录二级目录三级目录新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入一级目录二级目录三级目录你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markd

2021-01-11 23:27:53 150

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除