Algorithm--Partition-array-for-maximum-sum
Dynamic ProgrammingPartition Array for Maximum SumTitle Detail
Given an integer array A, you partition the array into (contiguous) subarrays of length at most K. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
Return the largest sum of the given array after partitioning.
Example 1:123Input: A = [1,15,7,9,2,5,10], K = 3Output: 84Explanation: A becomes [15,15,15,9,10,10,10]
Note:121 <= K <= A.length <= 5000 <= A[i] <= 10^6
...
Java-for循环那些事
Java for循环里面的 i++ 与 ++i在for循环里两者的作用是一样的
i++12345for(int i=0; i<5; i++){ System.out.print(i + ",");}>> 0, 1, 2, 3, 4
++i12345for(int i=0; i<5; ++i){ System.out.print(i + ",");}>> 0, 1, 2, 3, 4
工作原理
i++1234{ System.out.print(i + ","); i++;}
++i1234{ System.out.print(i + ","); ++i;}
区别
在Java里面,i++ 需要开辟新的存储空间用于存储结果,++i 直接在原存储空间中存储结果。故 ++i 在 for 循环里面执行效率要高。 可以作为代码优化的一部分。
foreach 与 for ...
Java:Map API
Java Map常用类型
类型
特征
HashMap
根据 HashCode 存储数据,访问速度快。至多允许一条记录键为 null;允许多条记录的值为 null;线程非同步
TreeMap
保存的记录按照键(key)排序,也可自定义排序规则。用生成的 Iterator 遍历 TreeMap 得到记录是排序后的。不允许记录的键为 null;线程非同步
Hashtable
用 HashMap 类似,不同的是键值都不允许为 null。 支持线程同步,但写入较慢
LinkedHashMap
保留记录的插入顺序,生成Iterator遍历顺序与插入顺序一致。遍历比HashMap慢,键值都允许为 null;线程非同步
—> HashMap剖析
常用 API
方法
描述
Object put(Object k, Object v)
存入键值对
Object get(Object k)
返回键所映射的值;如果不存在该映射则返回 null
boolean containsKey(Object k)
是否包含键 k
b ...
Algorithm--Coin Change
Dynamic ProgrammingCoin ChangeTitle Detail
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
Example 1:123Input: coins = [1, 2, 5], amount = 11Output: 3 Explanation: 11 = 5 + 5 + 1Example 1:12Input: coins = [2], amount = 3Output: -1Note:
You may assume that you have an infinite number o ...
Algorithm--Sqrt(x)
Some Algorithm using Math AlgorithmAlgorithm-1 Sqrt(x)Title detail
Implement int sqrt(int x)Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
Example 1:12Input: 4Output: 2Example 2:1234Input: 8Output: 2Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
思路
牛顿迭代法
公式: ...
Algortthm--Jewels and Stones
Map的应用Jewels and StonesTitle Detail
You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so “a” is considered a different type of stone from “A”.
Example 1:12Input: J = "aA", S = "aAAbbbb"O ...
Algorithm--Fast and Slow Pointer
快慢指针的应用判断链表是否存在环Title Detail
Given a linked list, determine if it has a cycle in it.
To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.
Example 1:
123Input: head = [3,2,0,-4], pos = 1Output: trueExplanation: There is a cycle in the linked list, where tail connects to the second node.
思路利用快慢指针,快指针每次走两步,慢指针每次走一步。如果快指针能够追上慢指针,则链 ...
Algorithm--Find Common Characters
Find Common CharactersTitle detail
Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
You may return the answer in any order.
Example 112Input: ["bella","label","roller"]Output: ["e","l","l& ...
在Linux系统中同步更新我们的Github博客
原理介绍类似于版本管理,我们把hexo博客文件系统在Github上建立一个分支,通过管理分支提交最新的博客文件系统,保证我们博客框架的更新。然后我们基于最新的博客框架,撰写文章,进行Github Pages网页的更新,即我们博客内容的更新。
创建两个分支,一个用于存放博客静态资源,一个用于备份博客的部署文件。
参考资料
前期准备
一台Linux系统的电脑(我的linux系统是Ubuntu 18.04.2 LTS)
安装node.js 及 npm
安装 ssh
安装 git
按照我们前面教程搭建好的博客
创建Github 博客仓库分支首先在我们搭建Hexo博客的电脑上,创建我们博客仓库在Github上的分支。
打开我们的博客仓库,选择setting:
选择Branches,创建博客仓库的Hexo分支,并将其设置为默认分支。
将该仓库克融到本地,并把本地博客的(所有Hexo目录下文件)全部拷贝进username.github.io文件目录中去。
然后把更新后的博客部署文件提交到Github的hexo分支中。
依次执行123git add .git commit ...
Markdown简单教程
Markdown语言简介Markdown是一种轻量级的「标记语言」,语法简单易于上手,2004年由John Gruber创建。Markdown通过纯文本编写的方式实现文章的撰写与排版,然后被转化为html或者pdf,可以轻松地将文章分享。相较于文本编辑器word的文章排版的方式,Markdown通过固定的文本格式实现了绝大多数的排版场景,让创作者可以专心于文章的构思于撰写,而从繁琐的排版工作中解脱出来。
Markdown书写工具Markdown也得到了广泛的支持,例如简书、github、知乎、博客园等等都支持直接上传Markdown文档,同时一些桌面程序也支持利用Markdown语法记录文章。推荐的Markdown文档工具如下:
Mac系统:Mou
Windows系统:MarkPad
Linux系统:retext
网页版:简书,可支持在线预览Markdown文档的功能
一些在线的Markdown工具:
MaHua在线编辑器,无须测试
Cmd Markdown客户端编译器
Markdown语法很多博客的文章也是用Markdown写成的,因此花几分钟学习Markdown的语法还是 ...