- 博客(629)
- 资源 (1)
- 论坛 (23)
- 收藏
- 关注
原创 LeetCode:787. Cheapest Flights Within K Stops
There are n cities connected by m flights. Each flight starts from city u and arrives at v with a price w.Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to d
2021-02-19 09:37:06
6
原创 编译libwepb
1. 下载源码:https://github.com/webmproject/libwebp/2. 编译:./autogen.sh./configure --prefix=/home/charles/install --enable-libwebpmux --enable-libwebpdemux --enable-libwebpdecoder --enable-libwebpext...
2021-01-31 13:16:31
12
转载 Linux 性能分析valgrind(二)之callgrind使用
Callgrind概述和gprof类似的分析工具,但它对程序的运行观察更是入微,能给我们提供更多的信息。和gprof不同,它不需要在编译源代码时附加特殊选项,但加上调试选项是推荐的。Callgrind收集程序运行时的一些数据,建立函数调用关系图,还可以有选择地进行cache模拟。在运行结束时,它会把分析数据写入一个文件。callgrind_annotate可以把这个文件的内容转化成可读的形式。使用callgrind工具生成性能分析数据命令格式如下:valgrind --tool=callg
2021-01-15 11:29:28
42
原创 Leetcode 错误:store to misaligned address
今天遇到了一个 leetcode报的错:Line 48: Char 21: runtime error: store to misaligned address 0x61400000009e for type 'char *', which requires 8 byte alignment [solution.c]0x61400000009e: note: pointer points here61 00 62 00 be be be be be be be be be be be be b...
2021-01-15 11:23:54
57
转载 System Program Problem Detected – How To Fix Or Remove It In Ubuntu?
if you’re an Ubuntu user, probably sometimes or often, you may get an error “System Program Problem detected”. Ubuntu has a built-in utility called Apport, which is used to notify you whenever a program crashes.正在上传…重新上传取消The Apport program will notify
2020-12-30 23:18:20
17
原创 ubuntu 源更新时的签名问题(The following signatures couldn‘t be verified)
W: GPG error: https://cloud.r-project.org//bin/linux/ubuntu xenial/ InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9W: The repository 'https://cloud.r-project.org//bin/linux/u...
2020-12-30 23:03:13
13
转载 A Complete Guide to Create GIF in Linux
This tutorial is the complete collection of everything you need to know for creating a GIF image in Linux.The GIF aka Graphics Interchange Format was introduces on 1987 and became popular in web because of its low size, animation feature and of course po
2020-12-15 08:37:13
38
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]...
2020-10-02 22:50:03
11
原创 内存问题之找不到地址对应的模块。
先看一个内存问题:(gdb) bt full#0 0x080485e1 in main () at test1.c:12 handle = 0x8bcc018 p = 0xb7726014(gdb) p *pCannot access memory at address 0xb7726014(gdb) info proc mappings Mapped address spaces: Start Addr End Addr Size
2020-09-14 00:02:53
57
原创 211. Design Add and Search Words Data Structure
You should design a data structure that supports adding new words and finding if a string matches any previously added string.Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) adds word to the data s...
2020-08-22 00:54:48
74
原创 LeetCode令人费解的报错
208. Implement Trie (Prefix Tree)Implement a trie with insert, search, and startsWith methods.Example:Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns falsetrie.startsWith("app...
2020-08-21 08:58:48
58
原创 求字符串长度
下面的代码看似没问题:bool isSame(char *s1, char *s2){ while(*s1 != '\0' && *s2 != '\0' && *s1++ == *s2++); return *s1 == '\0' && *s2 == '\0';}但是,如果 s1 = "abc", s2 = "abd",这个函数也会返回 true....
2020-08-16 18:53:31
31
原创 一种求全排列方法的代码
void swap(int *nums, int i, int j){ int tmp = nums[i]; nums[i] = nums[j]; nums[j] = tmp;}void FullArray(int *nums, int size, int idx){ if(idx == size-1) { int i; for(i = 0; i < size; ++i) { printf("%d ", nums[i]); } printf("\n"..
2020-08-16 09:39:20
67
原创 初始化数组为同一个值[ C语言】
如果初始值是0的话,可以写为:int myArray[10] = { 0 }; // all elements 0上面也等价于:static int myArray[10]; // all elements 0如果不是0,需要把所有的值显示的(explicitly)赋给数组.否则,忽略的被默认为0int myArray[10] = { 1, 2 }; // initialize to 1,2,0,0,0...C++ 里面如果没指定赋值,默认为0:int myArray[
2020-08-16 09:35:18
182
转载 Github上不去方法
comeForm:https://zhuanlan.zhihu.com/p/107334179第一步:http://ping.chinaz.com/github.comPing检测Github第二步:选择最快节点添加hosts第三步:添加Hosts$ cat /etc/hosts127.0.0.1 localhost127.0.1.1 china.org china140.82.112.4 github.com# The following lines are desirabl
2020-07-12 10:14:33
171
原创 Leetcode: 104. 二叉树的最大深度
给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。说明: 叶子节点是指没有子节点的节点。示例:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回它的最大深度 3 。1. DFS 递归:int maxDepth(struct TreeNode* root){ if(!root) { return 0; } ...
2020-07-10 00:02:13
45
原创 对有两个元素被交换的有序数组排序。
一个有序数组,有两个元素被交换了,找出这两个元素,交换回来,这样数组仍然是有序的void findTwoSwapped(int *arr, int size){ int x = - 1; int y = -1; int i; for(i = 0; i < size -1; ++i) { if( arr[i+1] < arr[i]) { y = i + 1; if( x == -1) { x = i; } else {
2020-07-06 01:24:46
90
原创 返回比当前数字大的最小的素数
int getNextPrime(int a){ if( a == 1 || a == 2 || a == 3) { return a; } for(;;) { int i; for(i = 2; i *i <=a; ++i) { if (a%i == 0) { i = 2; ++a;...
2020-06-29 11:26:20
69
原创 98. 验证二叉搜索树
给定一个二叉树,判断其是否是一个有效的二叉搜索树。假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数。 节点的右子树只包含大于当前节点的数。 所有左子树和右子树自身必须也是二叉搜索树。1:使用中序遍历,然后用一个全局变量记住前一个值,用当前的值和前一个值比较:long long last;bool isValidBST_r(struct TreeNode* root);bool isValidBST(struct TreeNode* ro...
2020-06-26 09:34:01
94
原创 今天发现的两处代码问题
1. 插入排序void insert_sort(int *nums, int s, int e){ int i, j; for(i = s+1; i <= e; ++i) { j = i-1; int k = nums[i]; while( j >= s && nums[j] > nums[i])
2020-06-16 09:17:41
81
原创 Leet code 704. 二分查找
给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。示例 1:输入: nums = [-1,0,3,5,9,12], target = 9输出: 4解释: 9 出现在 nums 中并且下标为 4示例 2:输入: nums = [-1,0,3,5,9,12], target = 2输出: -1解释: 2 不存在 nums 中因此返回 -1提示: ...
2020-06-04 09:10:50
72
原创 嵌入式系统节省内存的一种方法
嵌入式系统内存往往是有限制的(成本考虑),因此需要尽量支持更多的功能,同时尽量减少使用的内存。一种方法是把需要支持的功能做成共享库的形式,需要这个功能的时候加载共享库,不需要的时候卸载共享库,从而把内存释放出来。下面举个例子说明。$ cat 1.c #include <stdio.h>static int g_array[1024 * 1024 * 5];int *g_p = 0;__attribute__((constructor)) void init1(void)
2020-06-02 01:21:48
139
原创 二分法中间值的选择
1)mid 向下取整while( left < right){ int mid = (right - left)/2 + left; if( check(mid) ) { left = mid + 1; } else { right = mid; }}会把 [left, right]分成 [mid +1, right], [left, mid]两个区间。如果 [left,right]只有两个元素,
2020-05-27 22:29:30
279
原创 查找山脉数组的最大值
何为山脉数组?如果数组 A 是一个山脉数组的话,那它满足如下条件:首先,A.length >= 3其次,在 0 < i < A.length - 1 条件下,存在 i 使得: A[0] < A[1] < ... A[i-1] < A[i] A[i] > A[i+1] > ... > A[A.length - 1]方法1: 取中点mid和右边半部分的中点mid1, 如果 mid位置的值大于mid1处的值,mid一定位于最大值的...
2020-05-25 23:09:51
99
原创 ubuntu 16.04上 安装 opencv4.
cmake 命令: cmake -D UILD_opencv_python3=YES -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=/home/dinghtao/install -D OPENCV_EXTRA_MODULES=../opencv_contrib-4.3.0/modules D OPENCV_GENERATE_PKGCONFIG=ON -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPL
2020-05-21 09:02:59
147
转载 LeetCode: 153. 寻找旋转排序数组中的最小值
假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。请找出其中最小的元素。你可以假设数组中不存在重复元素。示例 1:输入: [3,4,5,1,2]输出: 1示例 2:输入: [4,5,6,7,0,1,2]输出: 0这道寻找最小值的题目可以用二分查找法来解决,时间...
2020-05-03 16:57:53
98
原创 Leetcode: 33. 搜索旋转排序数组
假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。你可以假设数组中不存在重复的元素。你的算法时间复杂度必须是 O(log n) 级别。示例 1:输入: nums = [4,5,6,7,0,1,2]...
2020-04-29 00:16:57
83
原创 leetcode 35 搜索插入位置
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。你可以假设数组中无重复元素。示例 1:输入: [1,3,5,6], 5输出: 2示例 2:输入: [1,3,5,6], 2输出: 1示例 3:输入: [1,3,5,6], 7输出: 4示例 4:输入: [1,3,5,6], 0输出: 0...
2020-04-25 00:46:57
86
原创 POJ 2456 Aggressive cows
DescriptionFarmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000).His C...
2020-04-24 00:10:21
68
原创 怎么判断linux库文件在编译的时候与没有用 -g 选项
先写一个简单的文件1.c:$ cat 1.cvoid foo(void){}然后编译两个库,一个不加 -g, 一个加:gcc 1.c -cgdb -shared -fpic -o lib1.so 1.ocp 1.c 2.cgcc -c -g 2.cgcc -shared -fpic -o lib2.so 2.o下面介绍几种判断的方法:1. 使用 ob...
2020-04-17 00:20:22
321
原创 使用 meson编译 EFL库
最近EFL(https://www.enlightenment.org/download) 代码使用meson来编译了。编译方法如下:CFLAGS="-O -g -ffast-math -march=native -ggdb3" meson --prefix=$HOME/install -Dopengl=full . buildninja -C buildsudo ninja -...
2020-04-16 23:56:15
280
原创 牛顿法求平方根
对于给定的输入N,求平方根的公式是 x(k+1) = (xk + N/xk)/2;需要设置一个 N的平方根的初始估计值。取N的值就可以。#include <stdio.h>double newton(double d){ if( d < 0) { return -1; } ...
2020-03-09 11:11:16
119
转载 Finding Square Roots Using Newton’s Method
Let A > 0 be a positive real number. We want to show that there is a real number x with x^2 = A. We already know that for many real numbers, such as A = 2, there is no rational number x with this ...
2020-03-07 11:45:50
122
原创 POJ 1064: Cable master
Cable masterTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 83304 Accepted: 16926 DescriptionInhabitants of the Wonderland have decided to hold a regional programmin...
2020-02-23 10:14:15
101
转载 format specifier floating point values in printf and scanf..
"%f" is the (or at least one) correct format for a double in printf. There is no format for a float, because if you attempt to pass a float to printf, it'll be promoted to double before printf rece...
2020-02-22 19:29:49
121
转载 二分查找算法细节详解
思路我相信对很多读者朋友来说,编写二分查找的算法代码属于玄学编程,虽然看起来很简单,就是会出错,要么会漏个等号,要么少加个 1。不要气馁,因为二分查找其实并不简单。看看 Knuth 大佬(发明 KMP 算法的那位)怎么说的:Although the basic idea of binary search is comparatively straightforward,the det...
2020-02-12 01:08:27
179
3
转载 LeetCode 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and n...
2020-01-29 16:53:03
210
转载 ASLR – Address Space Layout Randomization
The LPIC-3 certification for Linux security wants you to be a master of managing security on a Linux system. The topic is, of course broad but one of the smaller objectives is to know how Linux protec...
2019-12-18 08:30:39
107
原创 LeetCode 28. Implement strStr()
mplement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example ...
2019-12-14 20:30:56
59
原创 KMP算法
KMP算法是在字符串匹配的过程中利用字符串的相同前后缀信息,跳过不必要的比较,从而提高效率。核心是根据模式串构造一个数组,数组的第 i个元素表示长度为i的子串里面相当前后缀的长度。在上图中,输入字符串(模式串)为"ABABACA";数组的第0个元素为0,第一个也为0;第三个元素值为1,表示长度为3的子串"ABA"相同前后缀"A"的长度为1.假定主串为"bacbababaabcbab...
2019-12-11 00:57:17
90
Algorithm (4th), by Robert Sedgewick
2012-04-07
putty 串口不能输入,只能输出打印信息
发表于 2012-12-24 最后回复 2020-01-09
caspiansea的留言板
发表于 2020-01-02 最后回复 2020-01-02
leetcode第三题的疑问
发表于 2019-07-07 最后回复 2019-07-08
QEMU桥接模式导致主机网络不通
发表于 2017-04-30 最后回复 2017-05-06
UDP通信中,fwrite写数据到文件,但是没有写进去。
发表于 2015-03-22 最后回复 2015-03-22
garbage following instruction
发表于 2014-11-07 最后回复 2014-11-07
/sbin/init error while loading shared libraries libm.so.6
发表于 2014-01-17 最后回复 2014-11-07
CSDN博文无法正常发表了
发表于 2013-12-26 最后回复 2014-01-17
升级了 Nvidia 官方驱动后, Mesa代码编译的库使用有问题
发表于 2013-05-19 最后回复 2013-06-25
更新 Nvidia 官方驱动后OpenGL程序出错
发表于 2013-05-17 最后回复 2013-06-25
请推荐学习 linux 文件系统的书籍
发表于 2013-05-25 最后回复 2013-06-24
用递归算法求解数组有没有相同元素的问题
发表于 2013-01-24 最后回复 2013-05-19
怎么查看模块占用的 flash大小
发表于 2013-04-09 最后回复 2013-05-19
wpa_supplicant配置网络
发表于 2013-04-11 最后回复 2013-05-17
Makefile 中 shell 函数的一个问题
发表于 2012-12-05 最后回复 2013-04-09
商业保险
发表于 2012-07-07 最后回复 2013-04-09
求指导图形引擎方面的书籍或者开源代码
发表于 2012-03-29 最后回复 2013-04-09
编译内核 (2.6.39) mkinitrd时,找不到 twofish module
发表于 2011-06-16 最后回复 2012-11-23
无线网卡能连接到 AP, 但是不能上网
发表于 2011-11-06 最后回复 2012-11-23
大家用 Ubuntu都会使用系统更新吗?
发表于 2012-06-03 最后回复 2012-07-09
ubuntu 12.04 可以选择把grub 安装到 MBR或者是 其他分区吗?
发表于 2012-05-05 最后回复 2012-05-05
在单线程下,怎样在后台处理耗时操作
发表于 2011-04-07 最后回复 2011-04-07
awk 引用的问题
发表于 2011-02-27 最后回复 2011-03-01
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人 TA的粉丝