0%

2018年 ARTS 周周享 (27)

2018 27th week

Algorithm


给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。

设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。

注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。

初次完成的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
func maxProfit(prices []int) int {
if len(prices) <= 0 {
return 0
}

income := 0
j := len(prices)
i := 0;
for i < (j - 1) {
rLarge := prices[i]
rNum := i
for l := i + 1 ; l < j ; l ++ {
if rLarge > prices[l] {
break
}
if rLarge < prices[l] {
rLarge = prices[l]
rNum = l
}
}
income = income + rLarge - prices[i]
i = rNum + 1
}
return income
}

最终完成的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func maxProfit(prices []int) int {
if len(prices) <= 0 {
return 0
}

income := 0
j := len(prices)
i := 0;
for i < (j - 1) {
if prices[i] < prices[i + 1] {
income += prices[i+1] - prices[i]
}
i++
}
return income
}

我的想法

一开始, 是我想多了, 按照自己的思维, 这种算法对人来说,
可能加的运算少了, 比较容易计算, 但是边界问题没有处理, 多次出现问题

最后发现, 总归是要遍历的, 一次从头到尾就ok了, 为啥还要那么麻烦.

Review


PHP 学习的必备网站

原文 Best Websites for Learning PHP Programming

https://medium.com/@simpliv/best-websites-for-learning-php-programming-5562697d5fbb

This article show 16 website for learning PHP programing.

  1. Codecourse

    You can learn PHP and other web development.

    It also available watch videos at their YouTube channel.

  2. Stone River eLearning

    In this website, the course is not free.

    It is not a PHP specific website

  3. PHP Manual

    Learn PHP, this website is helpful.

    It also has comments and support Chinese.

  4. Killer PHP

    Maybe you don’t have technical backgrounds, This website is match you.

  5. PHP 101

    PHP For the Absolute Beginner

  6. Tutorials Point

    W3Schools, when I first sawed it, but is not true.

    It has more content and more importantly, the right content.

  7. Tizag

    This website looks like antique.
    I can not understand author

  8. Simpliv

    This is video course site point.(and not free)

    I can not Accept their accent.

  9. Hacking with PHP

    Update to PHP7 you just need $20

  10. Codeigniter

    CodeIgniter is a powerful PHP framework, But I love Laravel

  11. Lynda

    This website is teaching many kinds of course (Not free)

  12. Udemy

    Support Chinese, a on-line course website. (Note free)

  13. W3 Schools

    It need not instruction. Name means content.

  14. Derek Banas Video Tutorial on YouTube

    It is so old.

  15. StackOverflow

    As a coder no one does not know it.

  16. Code Academy

    You can learn many different language. (Free)

Tip


看了下自己的博客, 已经好久没有更新了. 真是汗颜.

正好此次写 ARTS , Next 主题进行了大的版本升级, 内置了 gitment.

关于 hexo 主题 Next 的 6.3 升级步骤

源码库

1
git clone https://github.com/theme-next/hexo-theme-next themes/next

修改你的主题配置

1
2
# gitment: 
....

so easy it

关于 Markdown 有一个以前不常用的 图片链接记录下

1
[![微信图片_20180705113552.jpg](https://i.loli.net/2018/07/05/5b3d922e4bfea.jpg)](https://i.loli.net/2018/07/05/5b3d922e4bfea.jpg)

Share


因为是首次的分享, so, 我就说下放弃 blog 的这些日子吧.
真的是很轻松, 而且没有什么压力和负担.
但是技术好像也荒废了, 能及时的把知识, 归纳成体系, 总结成系统, 这个是很有必要.

希望回过头, 看看自己走过的路, 不是那么的迷茫未来.

最主要也是感谢一下, 耗子叔(陈皓), 左耳听风专栏的作者. 给了我很大的支持以及鼓励. 传送门

如果你也喜欢, 欢迎订阅他的专栏 微信图片_20180705113552.jpg "喜欢就订阅吧!"

下一次分享, 本人计划把, slack 好好研究下, 做个分享.