自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode 1-100 medium难度题目汇总

2. Add Two Numbers (Medium)题目描述给两个链表, 做加法Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8Explanation: 342 + 465 = 807.解题思路"""类似于合并两个链表1. 依顺序把l2的元素加到l1中2. 当一个链表已经加完, ...

2019-09-07 12:49:52 1038

原创 leetcode 1-100 easy难度题目汇总

主要是考虑到easy题目没什么好分析的, 故统一总结在一篇文章里. 留作记录.收录leetcode1文章目录1. Two Sum (Easy)7. Reverse Integer (Easy)9. Palindrome Number (Easy)13. Roman to Integer (Easy)14. Longest Common Prefix (Easy)20. Valid Parenth...

2019-08-26 21:26:58 694

原创 leetcode高频面试题

文章目录一. 写在开头二. Lnho大神总结的高频题三. 频度五题解1. Two Sum \[Difficulty: Easy\]15. 3Sum \[Difficulty: Medium20. Valid Parentheses [Difficulty: Easy]56. Merge Intervals [Difficulty: Medium]57. Insert Interval [Diffi...

2019-03-22 19:53:21 823

原创 OJ系统的常见输入输出问题——Java语言描述

文章目录分别读取每行中每个字符1. 字符较少2 指定读取行数3 字符数量较多3.1 每行第一个字符表示后面字符的数量3.2 每行字符数量不等对于输入,主要用到Scanner的方法,包括:Scanner.hasnext()等判断是否有下一个字符;Scanner.next(),Scanner.nextInt()获取下一个字符(token);Scanner.nextLine()将扫描往前进一行,并将跳过的这一行输入返回;记得导入包import java.util.Scanner;分别读取每行中每个字符

2021-02-22 10:37:58 270

原创 Java中Class.forName()的用法

总结一下Class.forName的用法以及它是如何应用在动态创建对象中。Class.forNmae主要用于当我们事先不知道类名的时候,一旦class被装载,我们将使用 newInstance() 方法来动态创建对象。看一看以下代码Logic.javaimport java.util.Scanner;public class Logic { public static void main(String args[]) { try { String someCl

2021-02-09 11:37:42 821 1

原创 linux shell 批量生成文件夹

模拟生产环境的日志文件夹,文件夹下放置一个log.txt,将其复制到生成的空文件夹中。echo "make new dir by date"day=40while(($day > 0));do d=`date -d "${day} days ago" +%Y-%m-%d` if [ ! -d "${d}" ];then mkdir ${d} echo "创建文件夹成功" else echo "文件夹已经存在" fi cp "log.txt" ${d} ((day--))

2021-01-27 13:52:32 758

原创 linux shell 压缩指定日期的日志文件

功能1:日志在workspace下,文件格式为YYYY-MM-DD,创建一个文件夹 logBackup,将指定日期内的文件放入,并压缩文件,然后删除文件夹,保留压缩文件。功能2:删除30天前的日志文件echo "Please wait..." curDay=$(date "+%Y-%m-%d")f=`ls ~/workspace/ -1 -c` #获取logs下文件列表cd ~/workspace/mkdir logBackup #创建文件夹,把要压缩的文件放进去day=3while(

2021-01-27 13:47:44 1422 1

原创 linux shell 删除指定日期前的文件

find path -type d -ctime +90 -exec rm -rf {} \;explanation根据文件属性,删除指定的多少日期前的文件find is the commandpath is the root directory you want to scan-type d means look for directories only-type f means look for files only-ctime +90 means created time older

2021-01-27 13:44:09 403

原创 二分查找相关专题(重复target值)

文章目录1 二分查找2 二分查找的变种2.1 查找第一个与key相等的元素2.2 查找第一个等于或者第一个大于key的元素2.3 查找第一个大于key的元素2.4 查找最后一个与key相等的元素2.5 查找最后一个等于或者最后一个小于key的元素2.6 查找最后一个小于key的元素3 二分查找变种总结3.1 首先判断是返回left,还是返回right3.2 判断比较符号1 二分查找二分查找是一个基础的算法,也是面试中常考的一个知识点。二分查找就是将查找的键和子数组的中间键作比较,如果被查找的键小于中间键

2020-07-23 16:27:16 207

原创 linux下使用crontab设置定时任务

文章目录1. 键入 crontab -e 编辑crontab服务文件2. 启动crontab服务3. 查看服务是否已经运行4. crontab命令5. cron文件语法:6. 任务调度设置文件的写法新增调度任务查看调度任务删除任务调度工作任务调度执行结果的转向1. 键入 crontab -e 编辑crontab服务文件文件内容如下:(在最后加入命令语句)# Edit this fil...

2019-11-15 15:30:45 350

原创 leetcode 124. Binary Tree Maximum Path Sum

Binary Tree Maximum Path Sum题目描述找出尽可能使得和最大的路径(所有点需要连接)解题思路设计递归函数findPathSum(node),传入节点,节点为空时停止递归,返回到传入节点(左右子节点)为止积累的最大和。如图左半部分,每次计算三个值:sumLeft:根节点和左子树的和sumRight:根节点和右子树的和sumAll:根节点和左右子树的和计算当...

2019-11-05 14:38:25 160

原创 leetcode108/109 Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree题目描述给定一个有序升序数组,输出可能的平衡二叉树Example:Given the sorted array: [-10,-3,0,5,9]One possible answer is: [0,-3,9,-10,null,5] 0 / \ -3 9 ...

2019-11-05 12:43:23 173

原创 基于虚拟机的hadoop分布式集群搭建(搭建成功)

【正式安装】1. 安装VMware、安装ubuntu16.04这里就不截图了,详细安装过程百度一下或参考:http://blog.itpub.net/26230597/viewspace-1255651/注意事项:(1)安装顺序:虚拟机节点先安装一个,完成基本配置后通过“克隆”的方式复制另外两个,这样既可以保证环境统一,又比较方便。(2)网络连接:选择桥接方式。建议最好手动把IP地址固定...

2019-11-01 16:10:49 564 1

转载 面试中的 10 大排序算法总结

查找和排序算法是算法的入门知识,其经典思想可以用于很多算法当中。因为其实现代码较短,应用较常见。所以在面试中经常会问到排序算法及其相关的问题。但万变不离其宗,只要熟悉了思想,灵活运用也不是难事。一般在面试中最常考的是快速排序和归并排序,并且经常有面试官要求现场写出这两种排序的代码。对这两种排序的代码一定要信手拈来才行。还有插入排序、冒泡排序、堆排序、基数排序、桶排序等。面试官对于这些排序可能会要求...

2019-10-21 13:29:49 290

转载 转载 二分查找关于边界问题的坑点与总结

原文链接:https://blog.csdn.net/haolexiao/article/details/53541837二分查找足够简单,但是坑点也有不少,下面来总结一下以下是二分查找的标准写法以下这个函数是二分查找nums中[left,right)部分,right值取不到,如果查到的话,返回所在地,如果查不到则返回最后一个小于target值得后一个位置。//右值点不能取到的情况 ...

2019-08-30 10:01:28 453

原创 leetcode 144/145. Binary Tree Traversal

144. 中序遍历https://leetcode.com/problems/binary-tree-preorder-traversal/思路递归方法如下, 本题要求iretatively, 也就是用迭代的方式做.class Solution: def preorderTraversal(self, root: TreeNode) -> List[int]: ...

2019-08-26 21:38:36 181

原创 leetcode 200. Number of Islands

200. Number of Islands题目描述1 代表岛屿, 0 代表海洋, 1 被 0 包围算作一个岛屿. 只要1被连接, 都只能算一个岛屿.解题思路用DFS解题. 遍历grid所有点, 如果grid[i][j]==1, 则对grid[i][j]由四个方向进行DFS, 把所有经过的点标记为x(表示去过), 所以每次遇到grid[i][j]==1的点一定是一个新的岛屿.代码Pyt...

2019-08-26 09:57:03 170

原创 leetcode 199. Binary Tree Right Side View

199. Binary Tree Right Side View题目描述假设站在二叉树右侧, 求能看到的节点.解题思路层序遍历, 每层的最后一个就是能被看到的.代码Python# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = ...

2019-08-26 09:16:57 140

原创 leetcode 198. House Robber (easy)

198. House Robber题目描述从一个数组中取(rob)若干数, 使得结果(money)最大, 这些数不能相邻Input: [1,2,3,1]Output: 4Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).Total amount you can rob = 1 + 3 = 4.解...

2019-08-26 08:53:19 164

原创 leetcode 187. Repeated DNA Sequences

187. Repeated DNA Sequences题目描述简单来说就是找出一个字符串中 所有重复一次以上 的长度为10的子串Input: s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”Output: [“AAAAACCCCC”, “CCCCCAAAAA”]解题思路这种在长字符串中找字符串的题目, 要使用dictionary或者hashmap来保存数据,...

2019-08-24 14:01:26 151

原创 leetcode 179. Largest Number (medium)

179. Largest Number题目描述Given a list of non negative integers, arrange them such that they form the largest number.Input: [3,30,34,5,9]Output: “9534330”Note: The result may be very large, so you n...

2019-08-23 22:13:20 172

原创 leetcode 167. Two Sum II - Input array is sorted (easy)

167. Two Sum II - Input array is sorted题目描述Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.Note:默认只有一个解, 而且...

2019-08-23 19:22:42 365 1

原创 leetcode 165. Compare Version Numbers

165. Compare Version Numbers题目描述Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.You may assume that the...

2019-08-23 16:49:55 129

原创 leetcode 154. Find Minimum in Rotated Sorted Array II (hard)

154. Find Minimum in Rotated Sorted Array II题目描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2])....

2019-08-22 21:27:46 157

原创 leetcode 153. Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array题目描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Fi...

2019-08-21 22:59:31 194 1

原创 leetcod 152. Maximum Product Subarray (medium)

https://leetcode.com/problems/maximum-product-subarray/

2019-08-21 17:43:22 142

原创 leetcode 151. Reverse Words in a String

https://leetcode.com/problems/reverse-words-in-a-string/题目描述Given an input string, reverse the string word by word.Example 1:Input: “the sky is blue”Output: “blue is sky the”解题思路用split()将string...

2019-08-20 20:27:57 143

原创 leetcode 150. Evaluate Reverse Polish Notation (medium)

https://leetcode.com/problems/evaluate-reverse-polish-notation/题目描述Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an i...

2019-08-20 00:08:32 107

原创 leetcode 146. LRU Cache (medium)

https://leetcode.com/problems/lru-cache/题目描述Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the val...

2019-08-15 16:56:00 134

原创 leetcode 144/145 Binary Tree Traversal (medium/hard)

144. Binary Tree Preorder Traversal (medium)https://leetcode.com/problems/binary-tree-preorder-traversal/题目描述用迭代的方式前序遍历二叉树, 而不使用递归.解题思路前序遍历的顺序为 中->左->右, 考虑左边节点的始终比右边节点的要先遍历, 因此可以用栈, 先进后出的特性...

2019-08-15 14:28:17 97

原创 leetcode 143. Reorder List (medium)

题目描述Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list’s nodes, only nodes itself may be changed.举个例子:0 1 2 3 4 ---->...

2019-08-15 11:50:11 111

原创 leetcode 141/142 Linked List Cycle (easy)

141. Linked List Cyclehttps://leetcode.com/problems/linked-list-cycle/题目描述Given a linked list, determine if it has a cycle in it.Return True or False思路1最常规的思路,直接开辟一个list存放所有节点,每次都判断当前节点的子节点是否在li...

2019-08-15 11:05:53 130

原创 leetcode 137. Single Number II

https://leetcode.com/problems/single-number-ii/题目描述:Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:要求时...

2019-08-14 16:19:44 165

原创 leetcode 136. Single Number

https://leetcode.com/problems/single-number/submissions/题目描述:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear r...

2019-08-13 23:03:19 103

原创 leetcode 134. Gas Station (Medium)

https://leetcode.com/problems/gas-station/非常经典的一道题。解这道题的思路基于一个数学定理:如果一个数组的总和非负,那么一定可以找到一个起始位置,从他开始绕数组一圈,累加和一直都是非负的有了这个定理,判断到底是否存在这样的解非常容易,只需要把全部的油耗情况计算出来看看是否大于等于0即可。那么如何求开始位置在哪?注意到这样一个现象:假如从位置i...

2019-08-12 21:53:58 173

原创 leetcode leetcode 120. Triangle

https://leetcode.com/problems/triangle/submissions/sumList用来保存上一层路径的求和结果,nextSumList保存当前层的求和结果,nextSumList[i] = row[i] + min(sumList[i-1], sumList[i]),当前值加上 上一层两个路径最小的和。class Solution: def minim...

2019-08-05 15:05:00 171

原创 Linux 退出云服务器后不结束进程

1.nohup.out的由来及作用用途:LINUX命令用法,不挂断地运行命令。语法:nohup Command [ Arg … ] &描述:nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 & ( 表示“and”的符号)到命...

2019-08-02 19:41:25 1104

原创 Linux 任务/进程 查看/切换/终止

常用命令操作1. &加在一个命令的最后,可以把这个命令放到后台执行 ,如gftp &,2. ctrl + z可以将一个正在前台执行的命令放到后台,并且处于暂停状态,不可执行3. jobs / top / ps - Ajobs: 查看当前有多少在后台运行的命令jobs -l选项可显示所有任务的PID,jobs的状态可以是running, stopped, Termina...

2019-08-02 19:40:22 2605

原创 leetcode 116. Populating Next Right Pointers in Each Node

https://leetcode.com/problems/populating-next-right-pointers-in-each-node/层序遍历,只不过在遍历同一层的时候,每次将当前节点的next指向队列中下一个即将遍历的节点。class Solution: def connect(self, root: 'Node') -> 'Node': if r...

2019-07-30 21:35:34 104

原创 leetcode 115. Distinct Subsequences (hard)

https://leetcode.com/problems/distinct-subsequences/经典DP,归结为给两个数组,执行某些操作后,需要怎样。dp[i][j]表示目前为止 s[1:j] 中能匹配出多少个 T[1:i],绿色表示 t[i] = s[j] 的情况下有多少种可行解,是 s[1:j-1] 中匹配出 T[1:i-1] 的数量+不使用当前 s[j] 而匹配的 T[1:i-1...

2019-07-30 20:39:10 127

空空如也

空空如也

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

TA关注的人

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