
算法
文章平均质量分 73
slbyzdgz
这个作者很懒,什么都没留下…
展开
-
选择排序
选择排序的基本原理:对于给定的一组记录,经过第一轮比较后得到最小的记录,然后将该记录与第一个记录进行交换;接着对不包括第一个记录以外的其他记录进行第二轮比较,得到最小的记录并与第二个记录位置交换;重复该过程,直到进行比较的记录只有一个为止。def select_sort(lists): count = len(lists) for i in range(0,count): ...原创 2019-02-22 10:35:08 · 112 阅读 · 0 评论 -
LeetCode---Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2019-05-31 21:47:33 · 138 阅读 · 0 评论 -
LeetCode---Pow(x, n)
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...原创 2019-06-20 16:04:10 · 142 阅读 · 0 评论 -
LeetCode---Valid Sudoku
Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must conta...原创 2019-06-17 19:39:17 · 101 阅读 · 0 评论 -
七月在线机器学习笔试题错题记录1
解析:随机事件 X 所包含的信息量与其发生的概率有关。发生的概率越小,其信息量就越大;反之,必定发生的事件(如太阳东升西落),其信息量为 0。信息量公式:I(X) = −logp(X) ,其中 I 是 information 的缩写。信息量公式的单位:log 以2为底,记作lb,单位比特(bit)log 以e为底,记作ln,单位奈特(nat)log 以10为底,记作lg,单位哈...原创 2019-06-21 20:46:43 · 568 阅读 · 0 评论 -
LeetCode---Plus One
Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element...原创 2019-06-21 21:24:47 · 133 阅读 · 0 评论 -
LeetCode---Merge Sorted Array
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume tha...原创 2019-06-21 21:48:05 · 118 阅读 · 0 评论 -
LeetCode---Contains Duplicate
217.Contains DuplicateGiven an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return...原创 2019-06-25 19:21:38 · 168 阅读 · 0 评论 -
LeetCode---Rotate Array、Missing Number
189.Rotate ArrayGiven an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps...原创 2019-06-25 19:55:57 · 186 阅读 · 0 评论 -
机器学习--准确率、精确率、召回率、F1、ROC、AUC
准确率就是所有预测正确的占总的比重,即(TP+TN)/(TP+FP+FN+TN)精确率(Precition)是指在所有系统判定“真”的样本中,确实是真的占比,即TP/(TP+FP)召回率(Recall)是指在所有确实为真的样本中,被判定为“真的”占比,即TP/(TP+FN)TPR的定义和召回率是一样的FPR就是指所有确实为“假”的样本中,被误判为真的样本,即TP/(TP+TN)...转载 2019-06-26 16:55:42 · 794 阅读 · 0 评论 -
LeetCode---Pascal's Triangle
Given a non-negative integernumRows, generate the firstnumRowsof Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:...原创 2019-06-23 21:43:19 · 167 阅读 · 0 评论 -
LeetCode---Pascal's Triangle II
Given a non-negativeindexkwherek≤33, return thekthindex row of the Pascal's triangle.Note that the row index starts from0.In Pascal's triangle, each number is the sum of the two numbers ...原创 2019-06-23 21:59:27 · 149 阅读 · 0 评论 -
LeetCode---Move Zeroes、Third Maximum Number、Find All Duplicates in an Array、Find All Numbers Disappe
283.Move ZeroesGiven an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,...原创 2019-06-26 21:50:47 · 141 阅读 · 0 评论 -
LeetCode---Max Consecutive Ones、 Fibonacci Number、Array Partition I、Reshape the Matrix
485.Max Consecutive OnesGiven a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last thr...原创 2019-07-02 21:42:11 · 172 阅读 · 0 评论 -
LeetCode---Best Time to Buy and Sell Stock I和II
121.Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy...原创 2019-06-24 20:43:17 · 138 阅读 · 0 评论 -
LeetCode---Majority Element
169.Majority ElementGiven an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and th...原创 2019-06-24 21:33:33 · 135 阅读 · 0 评论 -
LeetCode---Longest Continuous Increasing Subsequence、1-bit and 2-bit Characters、 Find Pivot Inde
674.Longest Continuous Increasing SubsequenceGiven an unsorted array of integers, find the length of longestcontinuousincreasing subsequence (subarray).Example 1:Input: [1,3,5,4,7]Output: 3...原创 2019-07-08 21:33:44 · 261 阅读 · 0 评论 -
LeetCode---Can Place Flowers、Shortest Unsorted Continuous Subarray、Maximum Product of Three Numbers
605.Can Place FlowersSuppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water a...原创 2019-07-04 22:46:59 · 124 阅读 · 0 评论 -
LeetCode---Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-05-31 21:22:59 · 167 阅读 · 0 评论 -
LeetCode---Integer to Roman
Example 1:Input: 3Output: "III"Example 2:Input: 4Output: "IV"Example 3:Input: 9Output: "IX"Example 4:Input: 58Output: "LVIII"Explanation: L = 50, V = 5, III = 3.Example 5:...原创 2019-05-28 21:12:13 · 148 阅读 · 0 评论 -
插入排序---直接插入排序、折半插入排序、希尔排序
直接插入排序基本原理:对于给定的一组记录,初始时假设第一个记录自成一个有序序列,其余的记录为无序序列;接着从第二个记录开始,按照记录的大小依次将当前处理的记录插入到其之前的有序的序列中,直至最后一个记录插入到有序序列中为止。def insert_sort(lists): for i in range(1,len(lists)): key=lists[i] ...原创 2019-02-22 11:02:17 · 202 阅读 · 0 评论 -
冒泡排序
冒泡排序顾名思义就是整个过程像气泡一样往上升,单向冒泡排序的基本思想是(假设由小到大排序):对于给定的n个记录,从第一个记录开始依次对相邻的两个记录进行比较,当前面的记录大于后面的记录时时,交换其位置,进行第一轮比较和换位后,n个记录中的最大记录将位于第n位;然后对前(n-1)个记录进行第二轮比较;重复该过程直到进行比较的记录只剩下一个时为止。def bubble_sort(lists):...原创 2019-02-22 14:10:49 · 121 阅读 · 0 评论 -
归并排序
归并排序算法的原理如下:对于给定的一组记录(假设共有n个记录),首先将每两个相邻的长度为1的子序列进行归并,得到n/2(向上取整)个长度为2或1的有序子序列,再将其两两归并,反复执行此过程,直到得到一个有序序列为止。def merge(left,right): i,j = 0,0 result=[] while i<len(left) and j<len(...原创 2019-02-22 15:59:53 · 155 阅读 · 0 评论 -
快速排序
快速排序是一种非常高效的排序算法,它采用“分而治之”的思想,把大的拆分成小的,小的再拆分为更小的。其原理是:对于一组给定的记录,通过一趟排序后,将原序列分为两部分,其中前部分的所有记录均比后部分的所有记录小,然后再依次对前后两部分的记录进行快速排序,递归该过程,直到序列中的所有记录均有序为止。def quick_sort(lists,left,right): if left>=...原创 2019-02-22 16:25:23 · 229 阅读 · 0 评论 -
python编程练习
实现列表的逆序def reverse(list): for i in range(0,len(list)//2): temp = list[i] list[i] = list[-i-1] list[-i-1] = templ= [2,6,8,9,13,7]reverse(l)print(l)[7, 13, 9, 8, 6,...原创 2019-02-28 16:58:42 · 246 阅读 · 0 评论 -
基本数字运算---如何判断一个自然数是否是某个数的平方
如何判断一个自然数是否是某个数的平方:设计一个算法,判断给定的一个数n是否是某个数的平方,不能使用开方运算1 直接计算法def ispower(n): if n<=0: print(n+'不是自然数') return False i = 1 while i<n: m = i*i if m=...原创 2019-03-04 22:13:04 · 1449 阅读 · 0 评论 -
如何实现栈
实现一个栈的数据结构,使其具有以下方法:压栈、弹栈、取栈顶元素、判断栈是否为空以及获取栈中数据元素。数组实现在采用数组来实现栈的时候,栈空间是一段连续的空间。class MyStack: # 模拟栈 def __init__(self): self.items = [] # 判断栈是否为空 def isEmpty(self): ...原创 2019-03-07 21:58:10 · 224 阅读 · 0 评论 -
LeetCode---Two Sum、Two Sum II - Input array is sorted
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-05-05 20:13:48 · 123 阅读 · 0 评论 -
LeetCode---Reverse Integer
7.Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:A...原创 2019-05-24 20:24:00 · 162 阅读 · 0 评论 -
LeetCode---Palindrome Number
Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward.确定整数是否是回文。当一个整数向后读取与向前读取相同的内容时,它就是一个回文。Example 1:Input: 121Output: trueExa...原创 2019-05-24 21:25:00 · 170 阅读 · 0 评论 -
LeetCode---Remove Duplicates from Sorted Array
Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bymodifyi...原创 2019-05-25 20:02:08 · 112 阅读 · 0 评论 -
LeetCode---Remove Element
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input arra...原创 2019-05-25 20:57:29 · 151 阅读 · 0 评论 -
LeetCode---Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array....原创 2019-05-25 21:26:29 · 131 阅读 · 0 评论 -
LeetCode---Implement strStr()
ImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example ...原创 2019-05-26 21:07:50 · 116 阅读 · 0 评论 -
HMM前向计算示例
原创 2019-05-22 20:07:26 · 396 阅读 · 0 评论 -
LeetCode---Longest Substring Without Repeating Characters
Given a string, find the length of thelongest substringwithout repeating characters.给定一个字符串,在不重复字符的情况下找出最长子字符串的长度Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with ...原创 2019-05-22 21:31:58 · 276 阅读 · 0 评论 -
机器学习---L1和L2正则化的区别
L1正则化和L2正则化可以看成是损失函数的惩罚项,“惩罚”就是对损失函数中的某些参数做一些限制。对于线性回归模型,使用L1正则化的模型建叫做Lasso回归,使用L2正则化的模型叫做Ridge回归(岭回归)。L1正则化和L2正则化说明如下:L1正则化是指权值向量w中各个元素的绝对值之和,通常表示为|w|1 L2正则化是指权值向量w中各个元素的平方和然后再求平方根,通常表示为|w|2...原创 2019-05-23 20:40:36 · 2042 阅读 · 0 评论 -
LeetCode--- Non-decreasing Array
665.Non-decreasing ArrayGiven an array withnintegers, your task is to check if it could become non-decreasing by modifyingat most1element.We define an array is non-decreasing ifarray[i] <...原创 2019-07-05 22:07:49 · 118 阅读 · 0 评论