自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(313)
  • 收藏
  • 关注

原创 golang 计算几个自然月的某一天

比如说2021-01-30 之后5个月 变为 2021-06-292021-01-30 之后1个月 变为 2021-02-282020-12-01之后1个月 变为 2020-12-31package mainimport ( "strconv" "time")const ( minYear = 1678 maxYear = 2262)func isLeapYear(yeartime int64) bool { if (yeartime % 4 == 0 ...

2021-01-06 14:26:03 527 2

原创 python脚本 文件夹内文件名转为拼音名

首先需要运行 sudo pip install xpinyin然后把这个脚本放在 需要转的文件 同级目录下,命名为 run.pypython run.py运行脚本# coding: utf-8from xpinyin import Pinyinimport osimport sysresume_rootdir = '.' reload(sys)sys.setd...

2019-04-09 20:16:54 850

原创 leetcode 715. Range Module

A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.addRange(int left, int right) Adds the half-open

2018-04-10 10:23:26 658

原创 leetcode 235|236. Lowest Common Ancestor of a Tree

235. Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA

2018-04-09 10:17:12 250

原创 leetcode 587. Erect the Fence 凸包问题

问题如下:  leetcode 587在一个二维的花园中,有一些用 (x,y) 坐标表示的树。由于安装费用十分昂贵,你的任务是先用最短的绳子围起所有的树。只有当所有的树都被绳子包围时,花园才能围好栅栏。你需要找到正好位于栅栏边界上的树的坐标。解法一:暴力解法我们知道凸包的性质,凸包一定是【最外围】的那些点圈成,所以假设有n个点,那么最多可以构造出n(n−1)2条边,算法如下: 1. 选定一条边,遍...

2018-04-03 14:34:46 1294

原创 网易2018实习生笔试编程题

牛牛的闹钟时间限制:1秒空间限制:32768K牛牛总是睡过头,所以他定了很多闹钟,只有在闹钟响的时候他才会醒过来并且决定起不起床。从他起床算起他需要X分钟到达教室,上课时间为当天的A时B分,请问他最晚可以什么时间起床 输入描述:每个输入包含一个测试用例。每个测试用例的第一行包含一个正整数,表示闹钟的数量N(N<=100)。接下来的N行每行包含两个整数,表示这个闹钟响起的时间为Hi(0&l...

2018-03-28 16:42:10 1069

原创 带父节点的二叉树的后序遍历 不使用递归和stack

#include #include #include #include using namespace std;class ListNode{public: ListNode(int k):val(k){ left = NULL; right = NULL; father = NULL; } ListNode*

2018-03-26 19:55:03 411

原创 美团2018暑期实习生笔试编程题

第一题:#include#include#includeusing namespace std;int num[20];int main(){ int num_a = 0, num_b = 0; string s, t; cin>>s; cin>>t; //滑动窗的思路 //1、先预处理,把 0-len

2018-03-23 10:06:51 1540

原创 leetcode 386. Lexicographical Numbers

Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input si

2018-03-21 13:36:47 162

原创 C++ STL中set/map 与 priority_queue 中greater、less 的用法区别

2018.3.4更新:在自定义类的操作符重载的编写的时候,都写'<'符号,在使用STL的set(map)中体现出小的在前面;在使用priority_queue却提现出大的在前面。代码如下:#include <iostream>#include <vector>#include <set>#include <map>#include &l...

2018-02-07 11:34:51 3202

原创 C++算法 求数组中最小的K个数

输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4。 解法一:排序后,取出前k个数。O(nlogn)。代码略。 解法二:建立n个元素的最小堆,每次去除堆顶的最小值,然后弹出堆顶,重新构成最小堆。O(klogn)  class Solution {public: vector<i...

2018-02-07 11:16:07 2683

原创 leetcode 297. Serialize and Deserialize Binary Tree

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be

2018-02-06 16:47:45 176

原创 leetcode 763. Partition Labels

763. Partition LabelsA string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a l

2018-01-25 19:15:43 321

原创 C++ Vector 内存分配

vector会预先分配比当前数据大的一个空间,如果有新的元素进来填满了这个空间,就又会继续分配。分配策略一般是1,2,4,8,16...直接上代码:#include #include #include #include #include #include #include #include #include using namespace std;cla

2018-01-22 15:58:49 787

原创 牛客 求1+2+3+...+n

题目描述求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。解答:使用短路原理。如果 ans = 0 那后面的递归就不会运行。class Solution {public: int Sum_Solution(int n) { int ans

2018-01-19 14:48:13 230

原创 leetcode 147. Insertion Sort List

147. Insertion Sort ListSort a linked list using insertion sort./*Sort a linked list using insertion sort. 链表的插入排序, 插入算法把要排序的数组分成两部分:第一部分包含了已经排序元素,而第二部分是未排序元素。将未排序元素 的第一个挨个和排序的比较,然后

2018-01-16 15:46:19 159

原创 546. Remove Boxes

546. Remove BoxesGiven several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time

2018-01-16 11:22:23 376

原创 leetcode 576. Out of Boundary Paths

576. Out of Boundary PathsThere is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directi

2018-01-16 10:26:57 228

原创 leetcode 679. 24 Game

679. 24 GameYou have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, )to get the value of 24.Example 1:Input: [4,

2018-01-15 20:22:43 410

原创 leetcode 753. Cracking the Safe

753. Cracking the SafeThere is a box protected by a password. The password is n digits, where each letter can be one of the first k digits 0, 1, ..., k-1.You can keep inputting the pas

2018-01-15 14:29:27 798

原创 leetcode 733. Flood Fill

733. Flood FillAn image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate (sr, sc) representing the

2018-01-15 10:43:10 572

原创 leetcode 695. Max Area of Island

695. Max Area of IslandGiven a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume al

2018-01-15 10:21:22 195

原创 leetcode 675. Cut Off Trees for Golf Event

675. Cut Off Trees for Golf EventYou are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:0 represents the obstacle can'

2018-01-14 17:56:25 297

原创 leetcode 752. Open the Lock

752. Open the LockYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap aro

2018-01-14 15:34:15 308

原创 leetcode 743. Network Delay Time

743. Network Delay TimeThere are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the tar

2018-01-14 15:06:41 284

原创 C++ Stack 常见用法全解(代码版)

使用deque和list都可以实现stack的底部结构。void stack_test(){ stack stk; for (int i = 0; i < 10; i++) stk.push(i); cout<<stk.size()<<endl; while (!stk.empty()) { cout<<stk

2018-01-12 16:48:53 275

原创 C++ Set/Multiset 常见用法全解(代码版)

set的特性是所有元素会根据元素的键值自动被排序。set不允许有两个元素有相同的键值。set由红黑树作为底层结构。set代码实例:class struc{public: struc(int a, int b): x(a), y(b){} int x; int y;};bool operator<(const struc& a, const str

2018-01-12 16:46:58 401

原创 C++ Map/Multimap 常见用法全解(代码版)

c++map容器提供一个键值对(key/value)容器,map与multimap差别仅仅在于multimap允许一个键对应多个值。对于迭代器来说,可以修改实值,而不能修改key。map会根据key自动排序。map底层是使用红黑树。Map代码实例:class sst{public: int x; int y; sst(int a, int b):x(a), y(b

2018-01-12 16:42:55 1960

原创 C++ Deque 常见用法全解(代码版)

vector是单向开头的连续线性空间,而deque是双向开口的连续线性空间。支持随机访问(就如d[2]这样)和快速插入和删除。其余的类似vector操作方法的使用.void bianli(deque& dq){ //遍历-1 deque可以随机读取 for (int i = 0; i < dq.size(); i++) cout<<dq[i]<<"

2018-01-12 16:40:03 991

原创 C++ priority_queue 常见用法全解(代码版)

priority_queue的用法和queue基本一样,难点在于自定义类型的自动排序。一共有三种写法。默认是vector作为底层结构。代码实例1:class struc{public: int x; int y; struc(int a, int b): x(a), y(b){} bool operator<(const struc& b)

2018-01-12 16:38:38 1006

原创 C++ Queue 常见用法全解(代码版)

使用deque和list都可以实现queue的底部结构。void queue_test() //queue不能随机访问。只能访问第一个和最后一个{ //创建 queue que; //插入 for (int i = 0; i < 10; i++) que.push(i); //获取 cout<<que.fro

2018-01-12 16:36:04 835

原创 C++ List 常见用法全解(代码版)

C++ list 常见用法:void bianli(list& vt) //list是不能直接访问数组索引的。底层实现是链表。{ //遍历1 c++11的新特性 for (auto it : vt) cout<<it<<" "; cout<<endl; //遍历2 正向迭代器访问 for (auto

2018-01-11 16:54:03 319

原创 C++ Vector 常见用法全解(代码版)

C++ vector 用法:#include #include using namespace std;void bianli(vector& vt){ //遍历1 c++11的新特性 for (auto it : vt) cout<<it<<" "; cout<<endl; //遍历2 直接访问任意元素 for (in

2018-01-11 15:15:31 401

原创 leetcode 690. Employee Importance

690. Employee ImportanceYou are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id. For example,

2018-01-11 10:53:31 221

原创 leetcode 542. 01 Matrix

542. 01 MatrixGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0O

2018-01-11 10:40:43 199

原创 leetcode 515. Find Largest Value in Each Tree Row

515. Find Largest Value in Each Tree RowYou need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5

2018-01-10 20:33:17 153

原创 leetcode 513. Find Bottom Left Tree Value

513. Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row of the tree. Example 1:Input: 2 / \ 1 3Output:1Example 2: Input

2018-01-10 19:48:06 152

原创 leetcode 713. Subarray Product Less Than K

713. Subarray Product Less Than KYour are given an array of positive integers nums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarra

2018-01-10 17:40:34 216

原创 leetcode 632. Smallest Range

632. Smallest RangeYou have k lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each of the klists. We define the range [a,b] is

2018-01-10 16:04:49 285

原创 leetcode 532. K-diff Pairs in an Array

532. K-diff Pairs in an ArrayGiven an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i

2018-01-10 14:58:23 164

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除