自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(43)
  • 资源 (1)
  • 收藏
  • 关注

原创 用牛顿法求算术平方根python

用牛顿法求算术平方根要求不用数学库函数sqrt()函数求一个数的平方根解法采用牛顿迭代法也就是牛顿法求解通过迭代公式来求得f(x)=0的解xn+1=xn−f(xn)f′(xn)x_{n+1}=x_n- \frac{f(x_n)} {f'(x_n)}xn+1​=xn​−f′(xn​)f(xn​)​这个公式源于泰勒展开式f(x)=f(x0)+f′(x0)(x−x0)+12f′′(x...

2020-04-03 14:07:29 2703 1

原创 ArtiPub搭建

ArtiPub搭建前言今天花了很久的时间搭建开源的一文多发平台,这个开源工具主要是可以帮助文章作者将编写好的文章自动发布到多个技术媒体平台,如知乎、CSDN、微信公众号等,获取最大的曝光度。不用一直在多个平台进行复制粘贴。期间安装过程有很多坑踩着,很是费神,特此记录一番。资源地址源码地址: https://github.com/crawlab-team/artipub安装方式...

2020-03-04 23:56:18 416

原创 pytorch Mnist手写数字实现

import torchimport torch.nn as nnimport torch.nn.functional as Fimport torch.optim as optimfrom torchvision import datasets, transformsimport torchvisionfrom torch.autograd import Variablefrom...

2019-12-06 21:44:18 242

原创 LeetCode 15. 三数之和 python

class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ #转化为两数之和,采用取出一个数,再用0减除这个数,记为target,再查找列表是否存在target...

2019-09-30 22:38:45 168

原创 LeetCode 14. 最长公共前缀 python

class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ # 暴力解法,先找出字符串中长度最短的那个,找到位置s,以及长度 res = "" ...

2019-09-26 21:58:37 124

原创 LeetCode 13. 罗马数字转整数 python

class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ #首先建立一个HashMap来映射符号和值,然后对字符串从左到右来, # 如果当前字符代表的值不小于其右边,就加上该值;否则就减去...

2019-09-26 21:26:18 131

原创 LeetCode 12. 整数转罗马数字 python

class Solution(object): def intToRoman(self, num): A=["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"] #设立两个列表 B=[1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500,...

2019-09-25 21:50:17 134

原创 LeetCode 11. 盛最多水的容器 python

class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ left=0 #设立左右指针 right=len(height)-1 maxs=min...

2019-09-24 22:48:12 142

原创 LeetCode 9. 回文数 python

class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x<0: return False x=str(x) #转化为字符串处理 ...

2019-09-24 22:12:00 148

原创 LeetCode 8. 字符串转换整数 (atoi) python

class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ str = str.lstrip() # 去除左空格 if len(str) == 0: return...

2019-09-19 22:52:34 93

原创 LeetCode 7. 整数反转 python

测试代码如下class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ if x==0: return 0 str_x=str(x) #转化为字符串 ...

2019-09-19 22:06:30 133 1

原创 Leetcode 6. Z 字形变换 python

python测试代码:class Solution: def convert(self, s, numRows): result = ['']*min(numRows,len(s)) #用字符串的个数模拟行数,假如是三行,则设定三个字符串,一个表示一行,如['', '', ''] #print(result) current_row...

2019-09-17 22:38:43 109

原创 LeetCode 61. 旋转链表 c++

这题做了很久,有个地方卡了很久大致的想法是先把链表连成环,同时记录链表的长度count,再进行平移,这里设置了两个指针,一个在前,一个在后,也就是快慢指针,一开始慢指针在原链表的末尾,快指针在头,对快指针进行平移,慢指针紧跟其后,平移count-k个单位(关于这个平移还有一些疑问,想通后进行补充),再令慢指针的next为NULL/** * Definition for sin...

2019-05-15 21:23:45 181

原创 LeetCode 25. k个一组翻转链表 c++

每次处理k个结点中的三个结点中的中间结点,提到k个结点的第一个位置,一直到第k-1的位置/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} *...

2019-05-15 20:21:43 142

原创 LeetCode 24. 两两交换链表中的节点 c++

思路还是比较清晰的/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ...

2019-05-15 16:58:52 132

原创 LeetCode 23. 合并K个排序链表 c++

分治大法/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: //合...

2019-05-15 16:40:37 220

原创 LeetCode 21. 合并两个有序链表 c++

设置一个临时头结点,方便使用/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {pu...

2019-05-15 16:25:36 186

原创 LeetCode 19. 删除链表的倒数第N个节点 c++

快慢指针可以一遍遍历解决/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:...

2019-05-15 16:15:22 171

原创 LeetCode 2. 两数相加 c++ python

提交代码:class Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: temp=ListNode(0) #创建一个新链表 l3=temp #将temp头部赋予l3 a=0 while l1!=No...

2019-05-15 15:53:02 137

原创 LeetCode 17. 电话号码的字母组合 C++ python

特别注意输入为空的时候class Solution {public: vector<string> letterCombinations(string digits) { vector<string> res; if(digits.empty()) return res; map&l...

2019-05-13 20:46:31 148

原创 位图法实现海量数据查找

举个简单例子,在C++中一个int类型的数有32位,而这32只表示一个数太过浪费,于是就考虑让这32位可以表示32个数,每一位表示该数是否存在如给定表示文件中整数集合的位图数据结构,则可以分三个阶段来编写程序第一阶段:将所有的位都置为0,从而将集合初始化为空。第二阶段:通过读入文件中的每个整数来建立集合,将每个对应的位置都置为1。第三阶段:检验每一位,如果该为为1,就输出对应的整数...

2019-04-25 21:41:25 748

原创 剑指Offer(三):从尾到头打印链表

利用栈struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };class Solution {public: vector<int> printListFromTailToHead(ListNode* head) {...

2019-04-22 11:38:31 77

原创 LeetCode 41. 缺失的第一个正数 c++

总结版题目:给定一个未排序的整数数组,找出其中没有出现的最小的正整数示例1:输入: [1,2,0]输出: 3示例2:输入: [3,4,-1,1]输出: 2示例3:输入: [7,8,9,11,12]输出: 1你的算法的时间复杂度应为O(n),并且只能使用常数级别的空间。当使用额外空间时,使用set可以很快解出class Solu...

2019-04-21 11:22:26 235

转载 剑指Offer(一):二维数组中的查找

在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数首先选取数组中右上角的数字。如果该数字等于要查找的数字,查找过程结束;如果该数字大于要查找的数组,剔除这个数字所在的列;如果该数字小于要查找的数字,剔除这个数字所在的行。也就是说如果要查找的数字不在数组的右上角,则每一次都在数组的查...

2019-04-21 11:06:41 81

原创 LeetCode 53. 最大子序和 c++ python

class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ sum = nums[0] maxsum = nums[0] for i in rang...

2019-04-11 11:31:13 98

原创 LeetCode 122. 买卖股票的最佳时机 II python

比如[1,3,5,2,6,1,3]profit=(3-1)+(5-3)+(6-2)+(3-1)=3-1+5-3+(6-2)+(3-1)=(5-1)+(6-2)+(3-1)class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :...

2019-04-10 19:33:05 151

原创 LeetCode 121. 买卖股票的最佳时机 python

1.始终保存最小的买入价格2.始终保存最大的利润比如数据2,7,1,3首先找到最小买入是2,然后做差7-2=5,保存利润,然后到最小买入变成1,此时利润还是5,然后到3,注意,这里就是核心了。如果1后面出现的数字足够大,大到和1做差的值大于5,那么最大利润值就改变,否则,最大利润还是5.这里暗含的逻辑是,后面的数如果减1的差肯定比减2的差来的大。class Solution(o...

2019-04-10 19:21:25 417

原创 LeetCode88. 合并两个有序数组 python

不借助额外的数组class Solution: def merge(self, nums1, m, nums2, n): while m>0 and n >0: if nums1[m-1] >= nums2[n-1]: nums1[m+n-1] = nums1[m-1] ...

2019-04-10 19:08:53 469

原创 LeetCode 3. 无重复字符的最长子串 python

运行代码如下:class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ n=0 if len(s) == 0: # 字符串长度为0,返回0 ...

2019-04-10 10:24:05 122

原创 LeetCode 40. 组合总和 II c++

class Solution {public: vector<vector<int>> combinationSum2(vector<int>& candidates, int target) { vector<vector<int>> res; if (candidates.size() == 0 || ta...

2019-04-10 10:07:41 151

原创 LeetCode 39. 组合总和 c++

采用回溯法class Solution {public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { vector<vector<int>> res; if (candidates.size() == 0 ||...

2019-04-10 09:50:38 220

原创 LeetCode 34.在排序数组中查找元素的第一个和最后一个位置 c++

#include <iostream>#include <vector>using namespace std;class Solution {public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> res(2, -1...

2019-04-08 11:05:10 314

原创 leetCode 35.搜索插入位置 c++

#include <iostream>#include <vector>using namespace std;class Solution {public: int searchInsert(vector<int>& nums, int target) { int low = 0; int hight = nums.size() -...

2019-04-08 11:03:33 162

原创 LeetCode c++ 33. 搜索旋转排序数组

0  1  2  4  5  6  77  0  1  2  4  5  66  7  0  1  2  4  55  6  7  0  1  2  44  5  6  7  0  1  22  4  5  6  7  0  11  2  4  5  6  7  0二分搜索法的关键在于获得了中间数后,判断下面要搜索左半段还是右半段,我们观察上面加粗的数字都是升序...

2019-04-07 16:29:33 126

原创 机器学习入门

机器学习算法:监督学习和无监督学习监督学习:每个样本都有相应的“正确答案”,分类,回归分析无监督学习:回归:均方误差:离散数据、连续数据分类:错误率、精度:离散数据、连续数据...

2019-04-04 10:42:18 104

原创 LeetCode 31 C++ 下一个排列

【1 3 5 4 2】 --->【14 5 32】 --->【142 3 5】综合以上,找某序列的下一个排列算法为:1、找到右边“”最长“”的降序子序列,如【5,4,2】,此时pos定位到“3”的位置2、从右到左遍历降序子序列【5,4,2】,找到第一个大于3的元素,并交换(如上图红色值)3、将第二步得到的子序列翻转即可得到下一...

2019-04-03 19:59:13 231

原创 LeetCode c++ 27. 移除元素

使用vector特别注意erase函数,使用迭代器时,删除之后会自动指向下一个元素当使用erase删除时,这才是删除的正确方法class Solution {public: int removeElement(vector<int>& nums, int val) { for(vector<int>::iterator iter=...

2019-04-01 20:39:39 128

原创 LeetCode 26 c++ 删除排序数组中的重复项

由于数组本身就是有序的,直接调用unique函数即可class Solution {public: int removeDuplicates(vector<int>& nums) { nums.erase(unique(nums.begin(), nums.end()), nums.end()); r...

2019-04-01 20:37:00 153

原创 LeetCode 18 c++ 四数之和

#include <iostream>#include <algorithm>#include <cmath>#include <set>#include <vector>using namespace std;class Solution {public: vector<vector<int>>...

2019-04-01 20:04:25 202

原创 LeetCode 16 C++ 最接近的三数之和

类似第15题#include <iostream>#include <algorithm>#include <cmath>#include <vector>using namespace std;class Solution{public: int threeSumClosest(vector<int>& n...

2019-04-01 17:18:36 276

2019.12.2江苏省人工智能大会:小样本.rar

2019.12.2江苏省人工智能大会:小样本。这个主要是小样本专题下的一些内容,其中包括ppt,以及三位老师的分享。主要以深度学习为主,其次就是一些我听后总结的关键词

2019-12-08

空空如也

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

TA关注的人

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