- 博客(20)
- 收藏
- 关注
原创 leetcode1300:转变数组后最接近目标值的数组和
思路如下:先把数组从小到大排序,然后依次遍历数组,当前index为i,前0到i-1个数字的和为s,则剩余的值为target-s,假如当前arr[i]*(len(arr)-i)已经大于target-s了,则说明可以从当前第i个值开始,将所有之后的值均设置为同一个值,来逼近target,如果小于target-s,则说明即使从当前第i个值开始,将所有之后的值都设置为同一个值,也依旧会小于target,不是最优解。当大于target-s,则需要有一个边界判断,mean=target-s/(len(arr)-i),
2020-06-14 23:49:02
168
原创 networkx笔记
初始化及清空import networkx as nxG = nx.Graph() # 创建无向图G = nx.DiGraph() # 创建有向图G = nx.MultiGraph() # 创建多重无向图G = nx.MultiDigraph() # 创建多重有向图G.clear() #清空图加入边或节点G.add_edge('a', 'b') # 'a'和'b'是顶点的名称,可...
2019-09-19 11:41:39
431
原创 shell常用命令
计算命令运行时间timexcy@xcy-SMBIOS(17:18:12):~$ time lsreal 0m0.020s # 实际使用时间user 0m0.000s # 用户态使用时间sys 0m0.004s # 内核态使用时间输入输出重定向stdin(标准输入文件): 0stdout(标准输出文件): 1stderr(标准错误文件): 2command > file ...
2018-11-08 17:37:12
185
原创 Python:cannot import name abc
error安装pymongo之后,在import pymongo时报错, cannot import name abcSolutionsudo pip uninstall bsonsudo pip uninstall pymongosudo pip install pymongo
2018-11-08 15:39:47
1488
原创 python 和 sudo python
问题:在用sudo pip install安装pymongo时,发现会默认安装到python2.6的目录,而当前用的为Python2.7,所以仍然无法使用pymongo问题产生原因:由于当前机器有两个用户,一个为root一个为我经常使用的用户,由于安装pymongo需要sudo权限,而一旦用sudo安装,会默认安装到root用户使用的python目录中,也就是python2.6解决...
2018-11-05 14:35:50
6214
1
原创 error: crosses initialization of ‘const char* path’
源代码:if(a>9) { goto RETURN;}......const char * path = argc >= 4 ? argv[3] : "test";......RETURN:return 0;报错语句:testswitch.cpp: In function ‘int main()’:testswitch.cpp:9: error: ...
2018-09-10 11:09:38
428
原创 函数式编程
函数式编程是编程的一种方式,把运算过程尽量写成一系列的函数调用。函数式编程的特点:每一步都是运算,必须有返回值,把IO操作尽量减少。 函数要保持独立,不改变任何外部变量的值。 函数的运行不依赖外部变量,只要输入参数相同,则返回值相同。...
2018-07-27 18:46:29
122
原创 gtest
GoogleTest在Ubuntu下的安装及编译:安装:sudo apt-get install libgtest-devcd /usr/src/gtestsudo cmake .sudo makesudo mv libg* /usr/lib/编译: 假设源代码为sample.h和sample.cpp,测试代码为test.cppg++ -c sample.cppg++ -c test.c
2018-01-29 11:35:32
650
转载 c++ const
一 const修饰函数参数const只能修饰输入参数,不能修饰输出参数使用const修饰采用指针传入的函数参数,可以防止意外改动该指针,若参数采用值传递,则函数将自动产生临时变量用于复制该参数,无需加const,若参数采用引用传递,为了防止改动,可以加入const二 const修饰函数返回值如果给以“指针传递”方式的函数返回值加const 修饰,那么函数返回值的内容不能被修改,该返回值只能被赋
2018-01-19 12:33:57
148
原创 C++笔记
malloc:头文件:#include <malloc.h> 或 #include <alloc.h>函数原型:extern void *malloc(unsigned int size);函数功能: 向系统申请分配size个字节的内存空间。返回类型是 void* 类型。void* 表示未确定类型的指针。C,C++规定,void* 类型可以强制转换为任何其它类型的指针。参数解释: size:需要
2017-12-13 16:15:49
226
原创 php语法
标记1 xml风格(推荐)<?php echo "hello world" ?>2 脚本风格<script language="php"> echo "hello world"</script>3 简短风格<? echo "hello world">4 ASP风格<% echo "hello world"%>若使用简短风格和ASP风格,需要php.ini中配置,将sh
2017-10-13 23:07:45
156
原创 leetcode147. Insertion Sort List
题目Sort a linked list using insertion sort.解法用插入排序对链表进行排序。遍历链表,每次将当前结点插入到已经排序好的列表。代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(
2017-10-09 20:42:54
167
原创 动态规划
最大子段和给定一个长度为n的一维数组a,请找出此数组的一个子数组,使得此子数组的和sum=a[i]+a[i+1]+……+a[j]最大,其中i>=0 i
2017-10-07 22:43:24
172
原创 leetcode621. Task Scheduler
题目Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could
2017-10-06 21:14:01
398
原创 leetcode395. Longest Substring with At Least K Repeating Characters
题目Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input:s = "aaabb", k = 3Output
2017-10-06 20:20:08
164
原创 leetcode99. Recover Binary Search Tree
题目Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a c
2017-10-06 17:22:52
161
原创 leetcode225.Implement Stack using Queues
题目Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2017-10-06 01:12:02
179
原创 leetcode142.Linked List Cycle II
题目Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space? 解法:题目的意思就是判断
2017-10-06 00:13:08
175
原创 leetcode164.Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.You may
2017-10-05 18:55:58
242
原创 leetcode481.Magical String
A magical string S consists of only ‘1’ and ‘2’ and obeys the following rules:The string S is magical because concatenating the number of contiguous occurrences of characters ‘1’ and ‘2’ generates the
2017-10-05 16:50:46
178
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人