
算法
wayne0074
不务正业的程序猿
展开
-
算法的复杂度计算
如何计算算法复杂度算法的效率虽然计算机能快速的完成运算处理,但实际上,它也需要根据输入数据的大小和算法效率来消耗一定的处理器资源。要想编写出能高效运行的程序,我们就需要考虑到算法的效率。 算法的效率主要由以下两个复杂度来评估: 时间复杂度:评估执行程序所需的时间。可以估算出程序对处理器的使用程度。 空间复杂度:评估执行程序所需的存储空间。可以估算出程序对计算机内存的使用程度...转载 2018-08-09 22:26:04 · 547 阅读 · 0 评论 -
[LeetCode] Remove Nth Node From End of List
问题描述 Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the seco...转载 2018-08-14 15:30:36 · 119 阅读 · 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.分析 新建一个链表,然后比较两个链表中的元素值,把较小的那个链到新链表中,由于两个...转载 2018-08-14 15:47:32 · 146 阅读 · 0 评论 -
位操作使用技巧
原文写的很好,我就不献丑了 原文链接: https://blog.youkuaiyun.com/zheng0518/article/details/71250642原创 2018-08-14 15:50:59 · 234 阅读 · 0 评论 -
递归方法实现全排列
全排列的C++实现中心思想: 设R={r1,r2,…,rn}是要进行排列的n个元素,Ri=R-{ri}. Perm(X)表示在全排列Perm(X)的每一个排列前加上前缀ri得到的排列。 (1)当n=1时,Perm(R)=(r),其中r是集合R中唯一的元素; (2)当n>1时,Perm(R)可由(r1)+Perm(R1),(r2)+Perm(R2),…,(rn)+Perm(...转载 2018-08-13 15:38:56 · 264 阅读 · 0 评论 -
[LeetCode] Two Sum 两数之和
问题描述 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not us...转载 2018-08-13 16:37:47 · 134 阅读 · 0 评论 -
[LeetCode] Add Two Numbers 两个数字相加
问题描述 You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it ...转载 2018-08-13 19:23:02 · 208 阅读 · 0 评论 -
[LeetCode]longest substring without repeating characters
问题描述 Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the answ...转载 2018-08-13 20:05:42 · 115 阅读 · 0 评论 -
图像处理的基本算法
常用的图像处理算法灰度化处理灰度化处理是将彩色图像(R,G,B三个分量)的像素点转化为灰度图像(0-255表示的灰度值)像素点的过程灰度化的三种算法:最大值法:转化后的灰度值是彩色图像中RGB值中的最大的一个R=G=B=max(R,G,B)import cv2.cv as cvimage = cv.LoadImage('11.jpg')grayimg= cv.CreateIma...原创 2019-03-23 16:13:16 · 994 阅读 · 0 评论 -
图像梯度
图像的梯度An image gradient is a directional change in the intensity or color in an image.梯度是图像中亮度或颜色的方向变化At each image point, the gradient vector points in the direction of largest possible intensity i...原创 2019-03-23 16:13:49 · 327 阅读 · 0 评论 -
[LeetCode] Reverse Integer 翻转整数
题目描述 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321分析本题的难点在于对处理数据反转后可能出现的溢出情况与正负号的处理,但实际上正负号并不影响计算,方法如代码所示#class Solution {public: ...转载 2018-08-14 13:39:25 · 111 阅读 · 0 评论 -
计数排序
计数排序排序思想计数排序的基本思想是对于给定的输入序列中的每一个元素x,确定该序列中值小于x的元素的个数(此处并非比较各元素的大小,而是通过对元素值的计数和计数值的累加来确定)。一旦有了这个信息,就可以将x直接存放到最终的输出序列的正确位置上例子假设要排序的数组为 A = {1,0,3,1,0,1,1}这里最大值为3,最小值为0,那么我们创建一个数组C,长度为4。然后一趟扫...转载 2018-08-10 19:34:32 · 223 阅读 · 0 评论 -
棋盘覆盖
棋盘覆盖问题问题描述棋盘覆盖问题。有一个2k∗2k的方格棋盘,恰有一个方格是黑色的,其他为白色。你的任务是用包含3个方格的L型牌覆盖所有白色方格。黑色方格不能被覆盖,且任意一个白色方格不能同时被两个或更多牌覆盖。如图所示为L型牌的4种旋转方式。输入输出输入:给定k(1<=k<=10),表示棋盘大小为 2^k×2^k ,在给出特殊方格坐标x,y(0&...转载 2018-08-10 17:57:46 · 406 阅读 · 0 评论 -
Path sum
Path Sum路径和问题描述Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.测试用例For example: Given t...转载 2018-08-10 17:58:55 · 96 阅读 · 0 评论 -
同时查找最大值最小值优化算法
同时查找最大值最小值优化算法本算法并不是直接拿数组中的元素来和最大值和最小值比较的,而是先比较数组中两个数组,然后那其中小的和最小值对比,其中大的和最大值对比,那么算法就可以由原来需要对比2n次,降到只需要对比3n/2次了。//Calculate minimum and maximum at the same time to optimize the algorithm #incl...转载 2018-08-10 17:59:34 · 4317 阅读 · 0 评论 -
Sum Root to Leaf Numbers
Sum Root to Leaf NumbersDescriptionGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1-&gt;2-&gt;3 which ...转载 2018-08-10 18:01:19 · 104 阅读 · 0 评论 -
Swap node in Pairs
Swap node in PairsSwap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4-&...转载 2018-08-10 18:16:48 · 242 阅读 · 0 评论 -
在O(n)时间复杂度内查找前三
在O(n)时间复杂度内查找前三查找前三个最大或者前三个最小的数,相当于查找冠亚季前三名的算法了,应该如何做呢?当然可以用堆做,时间效率很高,下面是个简易的方法。查找前三个最大数算法: 1) 初始化三个数为INT_MIN 2) 循环 a) 如果当前元素大于第一名,更新第一名,且第三名=第二名; 第二名=第一名; b) 如果当前元素大于第二名,而且不等于第一名,那么更新...转载 2018-08-10 18:17:20 · 474 阅读 · 0 评论 -
Subset求数组的所有子集
Subset求数组的所有子集DescriptionGiven a set of distinct integers, S , return all possible subsets.Note: Elements in a subset must be in non-descending order. The solution set must not contain dup...转载 2018-08-10 18:17:52 · 361 阅读 · 0 评论 -
如何构建测试用例
如何构建测试用例白盒测试逻辑覆盖程序内部的逻辑覆盖程度,当程序中有循环时,覆盖每条路径是不可能的,要设计使覆盖程度较高的或覆盖最有代表性的路径的测试用例。下面根据图7-1所示的程序,分别讨论几种常用的覆盖技术语句覆盖为了提高发现错误的可能性,在测试时应该执行到程序中的每一个语句。语句覆盖是指设计足够的测试用例,使被测试程序中每个语句至少执行一次。判定覆盖...原创 2018-08-10 18:18:34 · 1194 阅读 · 0 评论 -
scoket编程
客户端1.创建套接字 SOCKETsockClient = socket(AF_INET, SOCK_STREAM, 0) ;2.向服务器发出连接请求 SOCKADDR_INaddrSrv ; addrSrv.sin_addr.S_un.S_addr =inet_addr(“192.168.0.1”) ; addrSrv.sin_family = AF_...转载 2018-08-10 19:32:10 · 190 阅读 · 0 评论 -
图像的阈值
图像的阈值学习目标简单阈值分割(Simple thresholding),自适应阈值分割(Adaptive thresholding),最大类间方差法。学习函数:cv2.threshold, cv2.adaptiveThreshold简单阈值分割(Simple thresholding)简单的阈值分割即设置一个阈值,如果图像的像素点大于该阈值就将其置为0或255(黑或白)。Open...原创 2019-03-23 16:14:24 · 638 阅读 · 0 评论