Question 3 Longest Substring

The description of the question is in the following link.

code

The idea is really clear: For the longest substring, different from the longest subsequence, they must be continuous, hence if for the first time we meet a repeated character, we shall abandon all the character before and included the repeated one, because for any string starting before the repeated character, there will always be a repetition in the string. For each time, we take the maximum between the max we have already had and the maximum of sub string we have now.

 

 

 

Question 2: Add Two Number

The description of the question can be in the link

https://leetcode.com/problems/add-two-numbers/

 

  1. My code for the question:

code

Idea: The full idea is clear that we need to take out the number one by one and then do the sum. The first thing needs to be careful is the carry for the number. Next thing we need to be careful is when the last digits are calculated, we need to make sure that there is no extra 1 there to be appended.

Question 1 Two Sum

The description of the question is in the following link: https://leetcode.com/problems/two-sum/

//My code:

for i in range(len(nums)-1):
for j in range(i+1,len(nums)):
if (nums[i]+nums[j] == target):
return [i,j]

Explanation:

My idea is to search all the pairs and return the index pair whenever I found the pair. So for the first for loop, I start from the very beginning. For the second for loop, I start from the number due to the symmetry of the sum. It could be modified by returning an empty array if there is no such pair.

// The code from the forum:

    def twoSum(self, num, target):
        map = {}
        for i in range(len(num)):
            if num[i] not in map:
                map[target - num[i]] = i + 1
            else:
                return map[num[i]], i + 1

        return -1, -1

This uses the idea called “Hash Table”. It is a dictionary, however, the key of the Hash Table is a function of the input value, and then we save it in the RAM and we are able to obtain it whenever we want.

Back to this example. For each value num[i], we want to know if it corresponds to a specific value in the hash table we construct. For example, for the index 0, the table is empty, thus we definitely want to save the value (target – num[0]) into the dictionary and gives a value for the key as the index. So if for the first time, the element num[i] is in the dictionary, corresponding to the element num[j],  and the index we stored for the (target -num[j]) in the dictionary is j + 1 (as the starting number in python is 0).

Summary:

  1. Going through all the pairs is the basic idea of finding things, however, the enumeration is not the best and the most efficient way to do it, because it may waste some the computational power and does not make full use of the space capacity.
  2. Ideas for the Hash Table in this case:
    1. We have the relation of two things: e.g. a+b = k, k is a constant. or b = f(a)
    2. We want to output the value a and b.
    3. We store the dictionary element {f(a) = b: a}
    4. If the ith element num[i-1] gives the value b we want, then we may output num[i-1] and a for these two pairs.

These are the main explanations for these two ideas. There is definitely more things for the Hash Table to learn.

LeetCode Introduction

最近打算开始系统化地刷一些Leetcode 的面试题,一方面是为了为自己的quantitative trader / Researcher的职业做准备,另一方面也是为了以后能够在复习的时候有一个更加系统化的索引。

很多时候,自己的思路和能力是很有限的,所以我不仅希望提供自己的思路,我也可能会去读一些别人写的code,去分析他们的思路,并且和自己的思路进行比较,然后可以提升自己的分析code的能力以及一些不一样的思路。

我知道很多事情都是道阻且长,除了自己努力没有别的办法,每天都坚持努力,不管怎么样都应该会变得更好。想到什么事情就要去做。不应该为自己的行为去找任何借口。

陆琮然

01/03/2020

UpDate:

在咨询朋友的建议之后,我决定按照算法得类型来集中练习,不再序号顺序做题。主要还是因为很多算法和数据结构都是需要系统性学习和练习的,集中练习可以比较好地记住这些知识。

15/03/2020

索引:

我打算在这里增加一个索引,对任何有需要的朋友,这个可以更加方便地替你找到你想要的类型的问题。如果有leetcode的小伙伴其实可以直接查看leetcode上的tag然后直接搜索对应的问题即可。

26/03/2020

计划

最近思考了一下自己之后的计划。

首先是在语言方面,一方面是要巩固自己的英语,每天坚持看英语新闻,提升自己英语的语感, 另一方面,我觉得是有必要学习一门外语了。我之前一直在法语和日语之间纠结, 现在看来,我觉得好像是法语在欧洲这一块更加实用一些。我打算自己学习法语。

其次是在学术方面。我现在越来越觉得Q quant已经越来越局限。我觉得 p quant才是未来。所以我打算自己学习一下 machine learning, deep learning and reinforcement learning, 以及相关的数学知识, 包括线性代数,优化和数值计算问题。除此之外, 我还打算认真细致地学习数学统计和金融时间序列分析。

但是话又说回来,对于Q quant的部分,也不应该就此完全放弃。我觉得有一些数学工具还是必要的。

另外除了数学, 我觉得有必要看完整本Hull的《期权,期货和其他衍生品》。看完这个会对自己在衍生品方面的认识有所提高。因为我自己最终的目标也是希望自己能成为一个能够做量化交易的人,所以有些必要的数学工具也是要扎扎实实地去补充提高的。

最后,就是自己生活方面的提升。以前自己并没有经常注意这一点,我觉得这个是我自己的失职以及对自己的不负责任。包括的是个人的卫生以及对自己的周围环境的整洁度的注意。以及我觉得真的要一直坚持健身。

所以现在(无工作,自由状态)大致计划是这样的:

每天早上计划八点起床

语言:

  1. 每天早上起来看一篇彭博的文章,然后写下自己的一些思考(用英语),发在网上。
  2. 现阶段,每天一课的你好法语。每天花一些时间背诵一些法语单词。不需要很多,每天先来5个,即使只有5个我觉得坚持下来就会有收获。
  3. 对于法语的话,我觉得一个小时听和读,一个小时写和说会好一些。如果有什么不懂的地方,可以去请教法国的朋友。教材暂时打算用你好法语。

数学:

  1. 每天的重头戏是机器学习,深度学习和增强学习这一块。首先是每天一到两个section的ESL。这个是最基础的机器学习。然后如果有代数方面的问题不会的, 再抽出时间去翻看资料。对于deep learning,这一块的话可以看Ian goodfellow的deep learning. 再然后就是 reinforcement learning,这一块的话,可以详见Sutton 的 reinforcement learning: an introduction.
  2. 其次有一点,就是可能要再强化一下对于线性代数的学习。本科的时候并没有学tensor(张量),但是我认为这个是非常重要的。因为在整个机器学习里面很多高维度的运算都会用到张量这个概念。
  3. 然后就是计算数学和优化问题。这方面比较复杂。我觉得对于整个优化的问题,我应该去看斯坦福的那本书。优化问题应该做到每天都坚持了解学习,因为这个对机器学习来说是一个比较重要的问题。但是数值计算的话,我觉得可以有一个大概的了解,所以我现在的想法就是认真看优化,但是不要太过于深究数字计算。
  4. 其次就是重头戏:金融时间序列分析。这一块的话非常重要,尤其是对想要了解p quant的人来说。
  5. 剩下的话还有一些量化交易的内容,比如quantitative portfolio management之类的书,对于我以后的目标还是有帮助的。这些可能得视我的进度耳边

生活:

  1. 坚持做到每天起床和睡觉前都做好护肤
  2. 每周两次用面膜清洁脸部。
  3. 每两周一次更换床单和被单。
  4. 自己手洗内衣裤和袜子
  5. 坚持每天健身,唯一的休息日只有周三
  6. 每两周用消毒湿巾擦拭卫生间以及自己房间里的柜子等等
  7. 坚持清淡饮食,偶尔可以出门去吃好吃的东西,但是要节制。
  8. 洗干净的衣服和外面回来换洗的脏衣服,分开来悬挂。
  9. 洗衣服的时候要用金纺和滴露的消毒液,要注意卫生。
  10. 偶尔也应该逛街,去买自己喜欢的衣服和裤子。

其他:

  1. 既然自己选择了想要学习摄影,那我觉得我应该争取抽出时间来思考摄影的内涵,以及怎么提高自己。我希望这个能成为我的一个很不错的爱好。
  2. 游戏的话不是不能打,但是我也知道,自己对于游戏已经越来越没有以前的热情了,我不知道现在的自己是不是还会和以前一样沉迷游戏,我估计我是不会了。
  3. 健身是一方面,但是我觉得我现在已经没有时间去提高自己的篮球水平了,一方面是由于时间限制,另一方面也是因为场地限制。所以我现在只希望自己能够提高自己的桌球水平,这样至少在别人问起来的时候,我也能和他们说我桌球打得很好。
  4. 文学方面。我觉得自己应该看一些非学术类的书籍,但是我还没决定好到底要看哪些东西。不过我必须要承认的是文学带给人的是精神上的慰藉与鼓舞。可能先从东野圭吾的《解忧杂货店》开始看起吧。
  5. 我觉得应该不断告诉自己不能急于求成,我希望自己能够安下心来,踏踏实实提高自己。希望自己能够摆脱那份浮躁,做一个更加成熟的人。

 

 

 

这些大致就是我近期的目标和计划。有的时候只有走出学校了,沉下心来看待自己,才会发现自己有那么多的不足之处,以及需要提高的地方,不论是生活上还是学习上。曾经的我是一个习惯被生活拽着走的人,但是现在开始我想要做一个能够掌控生活的人。

希望,也相信自己能够坚持,也希望自己能够做到不忘初心,成为更好的自己。我知道很多时候,自己离做得好还差得很远,但是这个不是借口。种一棵树,最好的时间是十年前,其次是现在;想成为一个更好的人,最好的开始时间是十年前,其次也是现在。的确只有跳出现在生活的循环与桎梏,我才能看清自己到底想要的是什么,到底怎么才能提高。

随笔

想起来尼采曾经说过的一句话,英语大概是这个样子的:

To live is to suffer, and to survive is to find meaning in the suffering.

我承认我从没有找到过真正的自我,一切都似乎是虚无的,即使是外部的支撑,也总是在不经意间分崩离析。寻找意义真的是一件非常困难的事情, 我有时候甚至怀疑自己是不是需要依靠不切实际的信仰来重新找到内在的平静。

活着就是痛苦,是一种找不到解药的痛苦。

随笔

这集vlog我们拍了十年,致最美好的青春

深夜,一如既往得睡不着,熟练得刷着视频网站,想要在这安静的世界里稍微招募一些喧嚣。偶然一刷就看到了这个视频(本文开头链接)。

视频的大致内容是这样的:两个人恩爱了十年,从高中毕业开始,一直到结婚的那一刻。两个人为对方做出的努力和牺牲。视频的最后,他们在蜜月旅行的途中收到了许许多多的陌生人的祝福。听着那一声声殷切热烈的congratulations,即使是平时很少流泪的我也不禁湿润了眼眶。我觉得视频中流露出的点点真情是表达匮乏的我所无法用言语轻易描述的,所以建议点开链接自己细细品味一下个中滋味。

爱情真是一个奇特的东西,因为你不知道它从何而来,也不知道它将往何去。我一直抱持着这样一个观点:真正的爱情绝大多数情况下都在校园中诞生。那时候的人们青涩,懵懂,单纯的喜欢在感情中那个占有绝对的统治力。我并不敢断言除了校园,就没有了真爱;只是当我们解除了社会,不免沾染一些风尘,很快便风干了那份稚嫩。房,车,钱等各种各样的客观因素将我们的视线从纯粹的理想拉回现实。

我个人一直不欣赏这种充满着铜臭味的婚姻。这种纯粹的物质婚姻和野蛮的原始文明中的交合没有任何区别。以前的所谓婚姻,不过是女性提供生育权,换取男性的物质支持以及保护。这是婚姻的雏形。但是现代婚姻之所以建立在自由恋爱之上,不就是为了能够让我们在粗暴原始的婚姻中留下一丝丝文明的烙印么?倘若我们把爱情的那一片给活生生扯去,在我眼里那就是一种背弃文明的恶劣行径。我这里想要强调的是,我并不是说婚姻一定要和物质撇清关系,而是婚姻的目的不能是单纯地为了物质和生育。

诚然,我相信会有人大声斥责,说你这种居庙堂之高的人,怎么可能理解底层人民的想法。我承认我不可能会了解所有人的想法,但是倘若一个人连最基本的物质都无法满足,那ta婚姻,也只是野蛮的,原始的婚姻,而非现代的婚姻。这个是我所不愿意所看见的。但是我没有办法干涉逼人的生活,也只能在这里埋怨几句罢了。

但是话又说转回来,这种真正的爱情,天下又有多少人可以遇见呢?这就好比打德州扑克,总是能看到别人的皇家同花顺,但是自己却从来没有遇见过。真正的爱情也只存在于别人的世界中,仿佛自己与真爱绝缘。每次想到这种事情,我的内心便会有一种淡淡的落寞。

真正的爱情到底会不会来呢?没有人知道。那也无妨,就让我们静静欣赏别人的爱情,嘴角微微上扬就好了。

BABA IS YOU LEVEL: Solitary Island

  1. Stage 00: Poem
    • Push down the line is twice
    • Push violet into the block next to it
    • Push the rose underneath the work baba
    • Push up the word rose
    • Use rose to touch baba to get the win
  2. Stage 01: Float
    • Make the rule” Rock is you “
    • Use rock to touch the flag
  3. Stage 02:Warm River
    • Make the rule” River is hot and float”
    • Go through everything that is floating to touch the flag.
  4. Stage 03: Bridge Building:
    • Push rock to sink one block of water
    • Make rule ” rock is you ” to move the rock
    • Make the rule “rock is push ” again to sink one block of water again
  5. Stage 04: Bridge Building?
    • Use Push to sink one block of water
    • Make the rule “Rock is You”
    • Sink another block with the word”sink” from the sentence “flag is win”
    • Push word “flag” and ” win” to the very right of the place
    • Push is from the sentence “rock is you ” to make the rule “flag is win”
  6. Stage 05:Victory Spring
    • Use two cog to sink the water next to the word”win”
    • push the line  text is float next to the win and push the word”win” back
    • Deactivate the rule” text is float” to clear the paths
    • Make the rule“ baba is w.in”
  7. Stage 06:Research Facility
    • Push the bolt to the line where keke and the word”skull” is.
    • Push the bolt one grid right to make sure it moves rightward.
    • Push the word ” defeat”  leftward to take the place of the word “hot”
    • Then keep tapping space to let the bolt push away the word “skull”
    • Go downward to push out the word “win” and the only thing needs to be noticed is that you should keep waiting until the bolt comes out.
    • Then make the rule “bolt is win”
  8. Stage 07: Assembly Team
    • Push the word “baba” to the most left. Then use the word to make two robots standing on two different lines.
    • Sink one block of water with one robot.
    • Make the rule: baba is you
  9. Stage 08: Tiny Pond
    • Make the rule: key is flag
    • Make the rule: flag is you and open. As one key has already been transferred into a flag. Use on flag to sink the water and use the other flag to push the word “win” out
    • Make the sentence “flag is win ” and “baba is you “
  10. Stage 09:Catch the thief
    • Push down the rule “baba is you”
    • Make rule “robot is baba”
    • Push word “win ” out
    • Make rule “baba is win”
  11. Stage 10: