ARTS #006

ARTS #006

Posted by Dan on September 8, 2018

ARTS是由左耳朵耗子--陈皓发起的一个活动: 每周至少做一个leetcode的算法题、阅读并点评至少一篇英文技术文章、学习至少一个技术技巧、分享一篇有观点和思考的文章。(也就是Algorithm、Review、Tip、Share简称ARTS),至少坚持一年。

ARTS 006

这是第6篇,写的比较水,希望以后越来越好。

Algorihm 算法题

leetcode算法第41题 First Missing Positive(缺失的第一个正数): 难度:困难

Given an unsorted integer array, find the smallest missing positive integer.
Example 1:
Input: [1,2,0]
Output: 3

Example 2:
Input: [3,4,-1,1]
Output: 2

Example 3:
Input: [7,8,9,11,12]
Output: 1
Note:

Your algorithm should run in O(n) time and uses constant extra space.

给定一个未排序的整数数组,找出其中没有出现的最小的正整数。
示例 1:
输入: [1,2,0]
输出: 3

示例 2:
输入: [3,4,-1,1]
输出: 2

示例 3:
输入: [7,8,9,11,12]
输出: 1
说明:

你的算法的时间复杂度应为O(n),并且只能使用常数级别的空间。

解题思路: 根据题目要求,要查找最小的正整数,那么一个给定的数组,返回值的最小值是1,最大值是多少呢?最大值应该是数组的元素的个数加1,如果能想到这一点这个题也就解决了。

我的实现如下:

//第一次一次通过的代码  而且运行时间是0ms
int firstMissingPositive(int* nums, int numsSize) {
    int i  = 1;
    for ( ;i<= numsSize; i++) {
        int flag = 0;
        for (int j = 0; j < numsSize; j++) {
            int data = nums[j];
            if (data ==i) {
                flag =1;
                break;
            }
        }
        if (flag == 0) {
            return i;
        }
    }
    return i;
}

下面这两个解法是别人提交的代码,可以学习一下别人的思路

int firstMissingPositive1(int* nums, int numsSize) {
    int *hashTable = (int*)calloc(numsSize+1,sizeof(int));
    int res = 1;
    for(int i=0;i<numsSize;++i){
        if(nums[i]>numsSize || nums[i] < 0)
            continue;
        hashTable[nums[i]]++;
    }
    while(hashTable[res]){
        res++;
    }
    return res;
}


int firstMissingPositive2(int* nums, int numsSize) {
    int temp, i, j = 0;
    
    for (i = 0; i < numsSize; i++)
    {
        while ((i != nums[i] - 1) && nums[i] > 0 && nums[i] < numsSize)
        {
            if ((temp = nums[nums[i] - 1]) == nums[i]) break;
            nums[nums[i] - 1] = nums[i];
            nums[i] = temp;
        }
        while (nums[j] == j + 1) j++;
    }
    
    return (j + 1);
}

下面这个解法摘自刘新宇的算法新解一书,比较节省空间(具体思路可以Google一下刘新宇的算法新解,有电子书)

#define N 1000000 // 1 million #define WORD_LENGTH sizeof(int) * 8
void setbit(unsigned int* bits, unsigned int i) {
    bits[i / WORD_LENGTH] |= 1<<(i % WORD_LENGTH);
}
int testbit(unsigned int* bits, unsigned int i) {
return bits[i/WORD_LENGTH] & (1<<(i % WORD_LENGTH));
}
unsigned int bits[N/WORD_LENGTH+1];
int min_free(int* xs, int n) {
    int i, len = N/WORD_LENGTH+1;
for(i=0; i<len; ++i)
    bits[i]=0;
for(i=0; i<n; ++i)
    if(xs[i]<n)
        setbit(bits, xs[i]);
for(i=0; i<=n; ++i)
    if(!testbit(bits, i))
        return i;
}

Review

这篇文章来自于: https://medium.freecodecamp.org/why-developers-should-know-how-to-write-dc35aa9b71ab

Why developers should know how to write

I recently came across an article by John Maeda about how writing — not coding — is design’s unicorn skill. That got me thinking about how writing plays a role in the life of developers. 我最近看到John Maeda的一篇文章,关于写作 - 而不是编码 - 是设计的独角兽技巧。 这让我开始思考写作在开发人员的生活中扮演着怎样的角色。

In today’s data-driven, data-heavy world, there’s so much content to consume. We’re constantly(经常) bombarded(炮轰) by videos, pictures, advertisements, podcasts, and articles. Each of these media has a different type of appeal(吸引力/呼吁), and it always seems like there’s strong competition(竞争) to try to attract and retain our attention.

在当今数据驱动、数据密集型的世界中,有太多的内容需要消费。我们经常被视频、图片、广告、播客和文章轰炸。这些媒体中的每一种都具有不同类型的吸引力,并且似乎总是有激烈的竞争试图吸引和留住我们的注意力。

A sampling of the different types of media channels available (image from Change Conversations).

With the proliferation(增殖/扩散) of different media channels in the past several decades, there has been a less of an emphasis(重点) on written content and more on the visual — specifically videos and images. According to this memo(备忘录) from 3M from 1997, people can process visuals 60,000 times faster than text. 在过去的几十年里,随着各种媒体渠道的发展,人们不再那么注重文字内容,而是更多地关注视觉——尤其是视频和图像。根据3M公司1997年的一份备忘录,人们处理图像的速度比文字快6万倍。

However, knowing how to write is still an important skill. Words can be one of the purest forms of expressing one’s thoughts. Words can be presented as letters, articles, or text messages. A writer will disseminate(传播) and share their thoughts in the form of ink on paper or digitized pixels on a screen. 然而,知道如何写作仍然是一项重要的技能。语言是一个人表达思想的最纯粹的形式之一。语言可以表示为信、文章或短信。作家会在纸上用墨水或屏幕上的数字化像素传播和分享他们的想法。

I’ve learned that writing well can be a catalyst(催化剂) for success, whether it be in the realm of personal growth, professional development, or social prosperity. A lot of the skills I’ve developed from writing dozens of articles in the past few years have translated over to my new full-time role as a software engineer at Putnam Investments. 我明白了,无论是个人成长、职业发展,还是社会繁荣,良好的写作都可以成为成功的催化剂。在过去几年里,我从写几十篇文章中获得的很多技能都转化成了我在Putnam Investments做软件工程师的全职新角色。 Photo by Aaron Burden on Unsplash.

As a developer, here are five benefits I’ve come across by learning to write. 作为一名开发人员,我在学习写作中获得了五个好处。

1. Writing well makes you a better communicator(写得好可以让你成为更好的沟通者)

The most obvious benefit I’ve realized from writing frequently is that writing well has made me a better communicator. As humans, we rely primarily on our words to convey our thoughts and feelings to others. By writing often, I’m able to express my thoughts easier, without having to worry about whether I’m using the right words, writing too much or too little, or being too vague(模糊) or convoluted(令人费解). 我从频繁写作中认识到的最明显的好处是,良好的写作使我成为一个更好的沟通者。作为人类,我们主要依靠我们的语言来传达我们的想法和感受给别人。通过经常写作,我可以更容易地表达我的想法,而不必担心我是否使用了正确的词,写得太多或太少,或太含糊或太复杂。

Image from https://zalarieunique.ru.

At work, I can draft(草案/草稿/起草) concise(简洁) emails or send instant(瞬间) messages(instant messages即时消息) without having to resort(采取/求助) to a dictionary for the correct spelling of a word or a thesaurus(词库) to make myself sound smarter. When thoughts can flow freely from your mind to your hand, the words that come out on paper flow fluidly(流畅) and don’t have to be manipulated to achieve(实现) a specific purpose. 在工作中,我可以起草简洁的电子邮件或发送即时消息,而不需要借助字典或同义词词典来让自己听起来更聪明。当思想可以自由地从你的头脑流向你的手时,纸上的文字就会流畅地流动,而不必为了达到特定的目的而被操纵。

Writing, like many other crafts(工艺), takes years of practice(实践) to hone(磨炼,训练.提高). The best part of writing is that the improvement is detectable(可检测的;可发觉的). You can look at previous(以前) works and see visible improvement over time. 写作,像许多其他的手艺一样,需要多年的练习才能磨练出来。写作最好的部分是进步是可以察觉的。您可以查看以前的作品并看到随着时间的推移明显的改进。

2. Writing for an audience helps you write better documentation(为读者写作可以帮助你写出更好的文档)

Part of the criteria(标准,条件) for being a good developer is knowing how to communicate technical requirements and specifications(规格/说明书) to other stakeholders(利益相关者). Knowing your audience is an important part of writing — the same applies when communicating with stakeholders or writing any type of documentation.

成为一名优秀开发人员的部分标准是知道如何向其他涉众传达技术需求和规范。了解你的读者是写作的一个重要部分——在与涉众交流或编写任何类型的文档时也是如此。

When working with less technical team members, you have to explain technical terms(条款;术语) and concepts(概念) in a way that makes sense(功能;观念;道理)(makes sense有意义的;讲得通;言之有理) and resonates(共鸣;共振) to whoever you’re working with. For example, when working with product owners and designers, I usually try to provide a high-level overview of whatever I’m working on without getting bogged(陷于泥沼的) down(bogged down陷入困境) in the details. For designers, I try to communicate how the feature should be implemented from a UX or UI perspective(观点;远景;透视图,角度). For product owners, I try to frame(设计/建造) my work from the perspective of the business.

当与技术含量较低的团队成员一起工作时,您必须以一种合理的方式解释技术术语和概念,并与与您一起工作的任何人产生共鸣。例如,当与产品所有者和设计师合作时,我通常会对我正在做的工作提供一个高层次的概述,而不会陷入细节之中。对于设计师来说,我试图从用户体验或UI的角度来说明该功能应该如何实现。对于产品所有者,我试图从业务的角度来组织我的工作。

In addition, developers also have to communicate their work to other developers. Whether it be naming variables or function names, writing inline comments, or documenting how the system should work from a high-level, developers need to know how to write good documentation so that code is understandable and maintainable. Whenever I write documentation, I try to make it as complete as possible. Any developers working on my codebase(代码库) will be able to understand the high-level structure, and also be able to contribute(贡献,出力) instantly(即刻/立即) without having to deconstruct(解构/拆析) and reverse-engineer(逆向工程) the code.

此外,开发人员还必须与其他开发人员交流他们的工作。无论是命名变量还是函数名,编写内联注释,还是记录系统应如何从高级别开始工作,开发人员都需要知道如何编写好的文档,以便代码易于理解和维护。每当我编写文档时,我都尽量使它尽可能完整。任何在我的代码基上工作的开发人员都能够理解高级结构,并且能够立即做出贡献,而无需对代码进行解构和反向工程。

3. Writing makes you appreciate(欣赏;感激;领会) the idiosyncrasies(特质气质,习性,癖好) of programming(写作让你欣赏编程的特质)

Back in 2011, a Redditor(社交新闻网站Reddit的读者) posted in the /r/programming subreddit(社交新闻网站Reddit的子版块) about the differences and similarities between writing and programming. Some say that programming is akin(类似的;同类的) to writing in that it’s a skill that isn’t conceptually(概念地/从概念上讲) difficult, but is something that is refined(精炼的;精确的;微妙的) over time. Others state that writing is completely different than programming in that writing is a creative(创造性的) endeavor(努力), whereas programming is a more involved(有关的/复杂的/涉及) science that requires a deeper understanding of the fundamental( 基本原理/基本的) concepts(概念,观念).

早在2011年,一位reddit的reddit用户在/r/programming 上贴出了关于写作和编程的异同的帖子。有人说,编程类似于写作,它是一种概念上并不困难的技能,但随着时间的推移,它会变得越来越精细。另一些人则认为,写作与编程是完全不同的,因为写作是一种创造性的努力,而编程则是一门更加复杂的科学,需要对基本概念有更深入的理解。

The general consensus(一致;舆论)(general consensus普遍的共识), with minor(未成年的/次要的;较小的) disagreements(不一致) in the nuances(细微差别) of each, is that both writing and programming require basic knowledge of the fundamentals(基本面;基本原理) — syntax, structure, and semantics(语义学;语义论). However, what differentiates an amateur(业余的;外行的/爱好者) from a veteran(经验丰富的;老兵的/老兵/老手) in each field is the ability to be creative and deal with the complexity of the system or topic at hand.

一般的共识是,在每一个细节上都有细微的分歧,即编写和编程都需要基本的基础知识——语法、结构和语义。然而,在每个领域中,业余爱好者与老手的区别在于他们具有创造性的能力,能够处理手头系统或主题的复杂性。

A lot of these ideas touch upon(touch upon涉及;触及;谈及) the fields of linguistics and language. 这些观点中有很多涉及到语言学和语言领域。

Writing teaches developers to think differently. For developers, writing code can feel restricted(受限制的;保密的) as there are a limited number of keywords, functions, and libraries that can be used. However, written languages allow for complete freedom in expression in a way that programming languages usually don’t allow.

写作教会开发人员以不同的方式思考。对于开发人员来说,编写代码可能会受到限制,因为可以使用的关键字、函数和库数量有限。但是,书面语言允许完全自由的表达,这是编程语言通常不允许的。

Ted Kaminski brings up another interesting point around the purpose of words as we use them in code and in other mediums. Ted Kaminski提出了另一个有趣的观点当我们在代码和其他媒介中使用词语的时候。

“For one, writing is meant(意味着) to be read. Code is meant to be read and changed.” -Ted Kaminski
“首先,写作是为了阅读。 代码应该被阅读和更改。“ - 泰德卡明斯基

Within the realm(领域) of writing, it appears as if a strict(严格的;绝对的) dichotomy(二分法;两分;分裂) has been created over time to separate( 使分离;使分开/单独的) the concerns(关注;关注点;关注者) of the writers from the readers. Writing seems to be set in stone(石头;结石), whereas code is an ongoing(不间断的,进行的) endeavor(努力;尽力) that seeks to improve upon(根据;接近;在…之上) the old.

在写作领域,随着时间的推移,似乎一种严格的二分法被创造出来,将作者和读者的关注点分开。写作似乎是固定不变的(一成不变的),而代码则是一种持续的努力,旨在改进旧的东西。

In many ways, writing “creatively” and writing code share many similarities, but knowing their differences makes me appreciate(欣赏;感激) both much more.

在很多方面,“创造性地”写作和编写代码有很多相似之处,但是了解它们的不同让我更加欣赏这两者。

4. Writing gives you a chance to apply what you learn(写作让你有机会应用你所学到的东西)

When I write, it always feels like I’m having a conversation with myself. Upon finishing a book or discovering(发现;使被知晓) something significant(有意义的事物,重大的;有效的;有意义的), I try to let my thoughts ruminate(沉思,反刍,反复思考) by writing an article on what I’ve learned. For me, I’ve found the best way to nudge( 推动;用肘轻推) my knowledge forward in a particular(特别的;详细的;独有的;挑剔的) area is to write about that topic.

当我写作时,总感觉像是在和自己对话。当我读完一本书或发现一些重要的东西时,我试着通过写一篇关于我所学的东西的文章来让我的思想反复思考。对我来说,我发现在某一特定领域推动我的知识进步的最好方法就是写下这个主题。

On freeCodeCamp and so many other websites that provide basic development tutorials(教程;专题报告;学习指南), authors write about a variety of different topics and concepts(概念,观念;思想). Part of the reason why so many volunteer(志愿者/志愿的) their time to write articles is not only so they can share their experiences and help others, but also so they can reinforce(加强,加固;强化;补充) their learned knowledge of the topic they’re writing about.

在freeCodeCamp和其他许多提供基础开发教程的网站上,作者撰写了各种不同的主题和概念。这么多志愿者花时间写文章的部分原因是,他们不仅可以分享自己的经验和帮助别人,而且可以加强他们对所写主题的知识。

freeCodeCamp, one of the best resources for development tutorials and articles. freeCodeCamp,开发教程和文章的最佳资源之一。

When I write about topics I learn about, I usually conduct(导电;带领 vt. 管理;引导;表现 n. 进行;行为;实施) additional(附加的,额外的) research(研究;调查) that often results in me coming across snippets(片段) of information I wouldn’t otherwise be exposed to. When I write, I’m more inclined(使…倾向/趋向于…的) to remember what I’ve learned for the long term(术语). Additionally, I sometimes also come across different perspectives(看法/观点展示) and viewpoints(观点) that challenge my initial outlook(展望;观点). The whole process of writing is a living and ongoing(不间断的,进行的;前进的) conversation that allows me to process the information I come across and make my own judgments.

当我写我所了解的话题时,我通常会进行额外的研究,这些研究通常会让我看到一些我平时不会接触到的信息片段。当我写作时,我更倾向于记住我学到的东西。此外,我有时也会遇到不同的看法和观点来挑战我最初的观点。写作的整个过程是一个活生生的、持续的对话,让我能够处理我遇到的信息,并做出自己的判断。

Writing is a great way to organize and collect your thoughts (Photo by Radu Florin on Unsplash).写作是组织和收集思想的好方法

Writing is a great way to digest(消化;吸收;融会贯通) and process the information we take in. However, erudition(博学;学识) and intellect( 智力,理解力;知识分子;思维逻辑领悟力;智力高的人) stem not from the quantity(数量;大量;总量) of information that we take in, but from our ability to process that information and draw meaningful conclusions from it.

写作是消化和处理我们所掌握信息的好方法。然而,博学和智力不是源于我们所接受的信息量,而是源于我们处理这些信息并从中得出有意义结论的能力。

写作是一种消化和处理信息的好方法。然而,学识和才智并不来自于我们吸收的信息量,而是来自于我们处理这些信息并从中得出有意义的结论的能力。

5. Writing as a form of catharsis(写作一种宣泄形式/写作是一种宣泄)

This last reason why I think writing is important might not be as directly relevant to the role of a developer as the last four reasons. But I think it’s just as, if not more, important. A big part of the reason why I choose to write is because writing is a great outlet for my emotions and feelings. I don’t like keeping my feelings and thoughts bottled up, so I seek out writing as a form of catharsis. 我认为写作很重要的最后一个原因可能与最后四个原因的开发者角色没有直接关系。 但我认为这也是重要的,如果不是更重要的话。 我之所以选择写作,很大一部分原因是因为写作是我情绪和感情的重要出路。 我不喜欢把自己的感受和想法保持在瓶颈里,所以我把写作作为一种宣泄形式。 我认为写作很重要的最后一个原因可能不像最后四个原因那样与开发人员的角色直接相关。但我认为这同样重要,如果不是更重要的话。我选择写作的很大一部分原因是因为写作是我表达情感和感受的一个很好的渠道。我不喜欢把我的感觉和想法藏起来,所以我寻求写作作为一种宣泄的方式。

When I was younger, I used to write journal entries in a diary. Now I write about a variety of topics and publish them for the world to read. But every now and then, I’ll return to pen and paper to express my personal thoughts. I keep a private journal that I write in occasionally when I have doubts about my professional goals, personal life, social relationships, and everything in between. 当我年轻的时候,我曾经在日记中写日记条目。 现在我写了很多主题,并将它们发布给全世界阅读。 但是我时不时地会用笔和纸来表达我个人的想法。 当我怀疑自己的职业目标,个人生活,社会关系以及介于两者之间的一切时,我会偶尔写一篇私人日记。 当我年轻的时候,我经常写日记。现在,我写了各种各样的主题,并发表给全世界阅读。但时不时地,我会回到纸和笔上来表达我的个人想法。我有一个私人日记,偶尔当我对我的职业目标、个人生活、社会关系以及两者之间的一切有疑问时,我就会写在里面。

*There’s nothing to writing. All you do is sit down at a typewriter and bleed.*

没什么可写的。你所要做的就是坐在打字机前流血。写作没什么。 你所做的就是坐在打字机上流血。

When I write about my feelings, it feels like I’m talking to a friend who is really good at listening. It’s a way for me to purge negative emotions and speak to an empty page without the fear of judgment. 当我写下我的感受时,感觉就像我正在和一个非常善于倾听的朋友交谈。 这是一种让我清除负面情绪并在不担心判断的情况下对空页说话的方式。 当我写下我的感受时,感觉就像我在和一个善于倾听的朋友交谈。对我来说,这是一种消除负面情绪的方式,对着空白的书页说话,不用害怕被评判。

Writing has a lot of benefits, and although it might not be your preferred way to express your thoughts, it’s a needed and useful skill even in today’s cacophonous and chaotic world. Even if you’re a beginner to the world of writing, I recommend that you try sitting alone with your thoughts and let your mind flow freely. It’s amazing what you can come up with. 写作有很多好处,虽然它可能不是你表达思想的首选方式,但即使在当今喧嚣和混乱的世界中,这也是一项必要且有用的技能。 即使你是写作世界的初学者,我也建议你单独考虑自己的想法,让自己的思想自由流动。 你能想到的是惊人的。 写作有很多好处,虽然它可能不是你表达思想的首选方式,但它是一项必要的有用技能,即使在当今嘈杂混乱的世界。即使你是一个写作新手,我建议你试着独自坐着思考,让你的思想自由地流动。你能想出的东西真是太神奇了。

. . .

Thanks for taking the time to check out my article! 感谢您抽出宝贵时间查看我的文章!

If you liked this article, drop a few claps, follow me on Medium, and recommend this article to your friends. Feel free to follow me on Instagram or connect with me on LinkedIn! 如果您喜欢这篇文章,请放下几个鼓掌,按照我的说明,将这篇文章推荐给您的朋友。 随意在Instagram上关注我或在LinkedIn上与我联系!

Derek Mei http://www.derekmei.com

TIPS:

如何下载一张大图

我们平时下载图片一般都是用SDWebImage,SDWebImage下载图片都是直接下载到内存的,直接用来显示的。但是如果一张图很大,如果直接用SDWebImage下载的话很可能导致内存暴增而闪退。该怎么解决这个问题呢? 苹果官方有一个加载本地大图片的例子(https://developer.apple.com/library/archive/samplecode/LargeImageDownsizing/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011173-Intro-DontLinkElementID_2),参照这个例子,我们可以先把图片下载到本地,然后再用苹果的例子进行加载图片,下载图片到本地可以用AFNetWorking,把图片先下载到本地。

Share:

怎么学好数据结构:

下面是一些别人的观点,可供参考:

https://www.zhihu.com/question/19830721/answer/205887662
数据结构的那些排序算法总是记不住,这个真的背的吗?
https://www.zhihu.com/question/51337272/answer/438910111
背下来吧,就背`快排`和`堆排`就行,`归并排序`不用背,但最好背下来怎么合并两个有序链表。这三个(其实是两个半)背下来,可以很多变化,比如说快排可以变换成找top k或者中位数的selection算法。堆排背下来就搞懂了二叉堆,堆可以做N多涉及优先级队列的算法,最短路也用得到。这些搞下来,你就熟悉了数组,链表,堆,二叉树,然后你会发现二叉树可以放在数组里,也可以像链表那样连着。图也是可以用数组和链表来表达成邻接表,然后你会发现Hash表也是类似的结构。到此为止,你只需要背这两个半的排序,本科时代的数据结构与算法你就基本学通了。。。。

下面是排序的一些总结:

理解的基础上归下类,记下每种特点就行了,还是挺直观的。下面就以常用的六个排序算法(升序)为例说下特点。
三种`n^2`的:冒泡,选择和插入。
冒泡:目的,每次排好最后一个。方式,从第一个开始查看相邻俩,不合适(前面的大)就交换,这样最后一个一定是最大的。然后,数组元素减一(最后一个排好了扔了吧),缩小规模再来一次。
选择:每次从待选数组中拎出一个最大的来,放到最后,然后缩小规模再来一次。
插入:假设后面的序列是有序的,每次从剩余数组中拎出最后一个,插入到有序数组中合适位置。然后剩余数组缩小规模再插一次。
三种nlgn的:快排,归并和堆排。
快排:每次随便选一个,把它整合适了(放到最终有序数组正确位置),然后比他小的扔左边,比他大的扔右边。然后除掉该数字外的左右子数组各自缩小规模再来一次。
归并:随便找个位置,砍成两半。这两半各自缩小规模了吧,然后假设他们自己来了好多次排好了。最后合并这俩有序数组就行。
堆排:这个比较有意思,核心要实现一个堆化函数。这个函数什么意思呢,就是假设一个大顶堆只有根元素不合法,左右子树都合法(符合堆性质),然后把堆顶元素一路往下搞,跟冒泡差不多,使整个树满足堆的性质。然后呢,把整个数组搞成符合堆的性质(自底而上,从第一个有孩子的元素一直调用堆化函数搞到根元素),把第一个(堆顶,即最大元素)和最后一个交换。如此一来,规模缩小一个,再来一次(堆化&交换)。其他还有shell排啦,桶排啦。不急,消化了这六个再说。


即便你看了算法的证明,某种程度上还是“背”(为什么这么说,后面会详述)。我自己遇到新算法基本是会看证明的,但是发现没多久还是会忘掉,这是死记硬背的标准症状。如果你也啃过算法书,我相信很大可能性你会有同感:为什么当时明明懂了,但没多久就忘掉了呢?为什么当时明明非常理解其证明,但没过多久想要自己去证明时却发现怎么都没法补上证明中缺失的一环呢?(http://mindhacks.cn/2011/07/10/the-importance-of-knowing-why-part3/)

我的看法: 学习算法和数据结构的时候,如果基础比较差,一些基础的算法的数据结构可以先记下来,然后要自己能够实现这些基础的算法和数据结构。把这些基础的东西吃透以后再去做难度大一点题目,因为难度大一点的题目的解法中都会用到基础的东西。 不要一上来就做难度大的题目,没有意义,不但会打击你的信心,而且很多解法你理解不了。 所有要把基础的算法和数据结构的搞熟,这里的搞熟至少自己能够代码实现,不是感觉理解就行了,理解和实现差距很大,只有自己实现的时候才能感受到里面的细节和精髓。

最好把下面这么排序、查找搞的很熟: 常用排序: 插入排序 选择排序 归并排序 冒泡排序 堆排序 快速排序 计数排序 基数排序 桶排序

查找结构 : 二叉查找树 [BST] 平衡二叉查找树 [AVL] 多路查找树/B~树/B+树 红黑树 [RBT] 动态查找树比较