05 2019 档案
摘要:题面 给定数组,将红-0、白-1、蓝-2,原地排序,要求相同颜色在一起。 样例 算法(初级/垃圾) 遍历数组,统计0、1、2个数,在重新写入数组中。 O(n) 源码
阅读全文
摘要:用种子填充法实现了区域标记,最终用彩色图展示标记结果。进而我们可以做一下图片中的大米计数。 编译环境 OpenCV 4.0.1(v15) + VS2017 源码 1 #include <iostream> 2 #include <stack> 3 #include <map> 4 #include
阅读全文
摘要:题面 找出二叉树的最小深度(从根节点到某个叶子节点路径上的节点个数最小)。 算法 算法参照二叉树的最大深度,这里需要注意的是当某节点的左右孩子都存在时,就返回左右子树的最小深度;如果不都存在,就需要返回左右子树的最大深度(因为子节点不存在的话,通向该子树的路径就走不同,就不存在深度,也无法比较。只能
阅读全文
摘要:题面 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). 层序遍历二叉树,要求从上到下,从左到右,输出结果为二维ve
阅读全文
摘要:easy 题就不详细叙述题面和样例了,见谅。 题面 统计二叉树的最大深度。 算法 递归搜索二叉树,返回左右子树的最大深度。 源码
阅读全文
摘要:题面 判断给定二叉树是否对称。 Note : empty tree is valid. 算法 1. 根节点判空,若空,则返回true;(空树对称) 2. 根节点不空,递归判断左右子树。如果左右孩子都空,说明到了叶子,返回true;不都空而且一空一不空,返回false;都不空,且值不等,返回false
阅读全文
摘要:偶然看到群里老哥问道这个问题 什么?char 还可以赋值字符串的?单引号还可以容纳如此多的字符? 结果 输出 . 就是点 换成其他的如:1.23,输出3 我找汇编看了一下 再结合一下汇编中的大端存大值来看的确是这样。 在内存中,上面字符串中1.28 实际上 8是在低地址端,用byte去取的时候先取到
阅读全文
摘要:题面 对比两棵二叉树是否相同,返回结果。 思路 1. 递归解决DFS 首先判断根节点,如果都空,返回true; 如果一空一不空,返回false; 如果都不空,判断两节点值是否相同,若不同,返回false,若相同,递归左子树、右子树 源码 2. 层序遍历解决: 队列 1. 首先判断根节点,如果都空,返
阅读全文
摘要:题面 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组。 样例 算法 时间复杂度:O(n+m) 与合并有序链表类似。 1. 如果m为0,直接返回就可以了。如果n为0,则需要把nums2中前n个元素都搬到nums1中,返回。 2
阅读全文
摘要:题面 合并两个排序链表。 算法 创建结果链表头*res,*p指向头,当两个链表节点都不为空时,比较节点值,值小的挂在p后面,二者(p和小者)顺次后移。知道某条链表空,跳出while循环。接着,直接将不空的链表挂在p后即可。 Note: 注意返回值 res->next; 源码
阅读全文
摘要:题面 原题挺长的,还是英文,就不抄了,😄。 给定字符串,可能由若干个空格开头,之后可能会跟一串数组,数字可能由-/+开头,之后会跟有若干其他字母,找出并计算该数字并返回。 Note: 超出INT_MAX 和 INT_MIN 返回它俩。(所以考虑用更大类型来暂存中间结果。) 样例 Example 1
阅读全文
摘要:题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at an
阅读全文
摘要:题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at an
阅读全文
摘要:题面 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its pat
阅读全文
摘要:在项目 *.pro中添加即可。
阅读全文
摘要:题面 给定x, n, 求pow(x, n)。 样例 Example 1: Example 2: Example 3: Note: -100.0 < x < 100.0 n is a 32-bit signed integer, within the range [−231, 231 − 1] 要小心
阅读全文
摘要:题面 Given a linked list, swap every two adjacent nodes and return its head. You may not modify the values in the list's nodes, only nodes itself may be
阅读全文
摘要:题面 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses 给定int n,代表n组括号,编码生成所有有效的括号组合(即符合括号嵌套规则) 样例 g
阅读全文
摘要:题面 删除倒数第n个节点,可以保证给定的n有效。 样例 Note: Given n will always be valid. 思路 这个题,挺经典的题目。我们使用快慢指针解决,即:一个指针先行n, 之后另一个指针跟它一起走,直到后面的指针到链表尾部,结束,返回结果。 分析样例 n = 2 算法 1
阅读全文
摘要:图象腐蚀与形态学操作 opencv 1. 通过调用库函数实现图像的腐蚀、膨胀; 2. 通过设置结构元素、元素大小、形态学操作类型实现对图象的形态学操作。 源码(VS2017+OpenCV 4.0) 效果图 1. 图像腐蚀、膨胀 2. 形态学操作 其他组合操作,自己去探索吧,挺有趣的! 更多openc
阅读全文
摘要:OpenCV 使用 createtrackerbar()报错问题 Error Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file c:\build\master_winpack-build-win64
阅读全文
摘要:题面 Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the
阅读全文
摘要:题面 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to
阅读全文
摘要:题面 Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b+ c + d = target? Find all unique
阅读全文
摘要:题面 Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives th
阅读全文
摘要:手工实现灰度及RGB直方图 !库 1. 灰度图像直方图 算法 1. 图片灰度化; 2. 遍历Mat,统计各灰度级的像素个数; 3. 根据opencv画点线函数,绘制坐标轴及像素分布图 源码(编译环境:VS2017+OpenCV) 补充:三通道直方图(即RGB彩色图象直方图在后面) 效果图 直方图hi
阅读全文
摘要:OpenCV实现图象翻转、滤波、锐化 注:以下代码,使用opencv库函数实现了对图片的翻转、灰度图转换、各种滤波、各种锐化。 库函数相关参数及说明参阅:OpenCV中文站=》opencv教程(cn)
阅读全文
摘要:6. ZigZag Conversion 题面 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this
阅读全文
摘要:题面 用一个栈实现另外一个栈的顶到底降序排序 要求:不能使用额外的数据结构,但可以使用新的变量。 思路(给定栈s, 辅助栈help) 1. 遍历给定栈(出栈),栈顶出栈cur,与help栈顶比较,如果大于辅助栈顶元素值,那么辅助栈栈顶元素出栈至s栈,直到help栈顶元素值<=cur 2. help压
阅读全文
摘要:11. Container With Most Water 题面 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines
阅读全文
摘要:5. Longest Palindromic Substring 题面 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000
阅读全文
摘要:3. Longest Substring Without Repeating Characters 题面 Given a string, find the length of the longest substring without repeating characters. 给定字符串,找到最长
阅读全文
摘要:题面 实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中的最小元素的操作。 要求 pop(), push(), getMin()时间复杂度都是O(1) 思路 1.准备两个栈,数据栈+最小元素栈 2.压入元素时,先压入数据栈,然后与最小元素栈顶比较;若小,则压入,若大,不做处理(1)/压入当
阅读全文

浙公网安备 33010602011771号