返回首页

ARTS #006

ARTS #006

ARTS is an activity initiated by 由左耳朵耗子--陈皓: Do at least one leetcode algorithm question every week, read and comment on at least one English technical article, learn at least one technical skill, and share an article with opinions and thoughts. (That is, Algorithm, Review, Tip, and Share are referred to as ARTS) and persist for at least one year.

ARTS 006

This is the 6th article. It is relatively poorly written. I hope it will get better and better in the future.

Algorihm algorithm question

Leetcode algorithm question 41 First Missing Positive (the first missing positive number): Difficulty: Hard

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),并且只能使用常数级别的空间。

Problem-solving ideas: According to the question requirements, we need to find the smallest positive integer. So for a given array, the minimum value of the return value is 1. What is the maximum value? The maximum value should be the number of elements in the array plus 1. If you can think of this, the problem will be solved.

My implementation is as follows:

//第一次一次通过的代码  而且运行时间是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;
}

The following two solutions are codes submitted by others. You can learn from other people’s ideas.

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);
}

The following solution is excerpted from 刘新宇的算法新解一书, which is more space-saving (for specific ideas, you can Google Liu Xinyu’s new algorithm solution, there is an e-book)

#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

This article comes from: https://medium.freecodecamp.org/why-developers-should-know-how-to-write-dc35aa9b71ab <center> <font size=6> Why developers should know how to write </font> </center> 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. I recently saw an article by John Maeda about how writing - not coding - is the unicorn tip of design. This got me thinking about the role writing plays in a developer’s life.

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.

In today’s data-driven, data-intensive world, there is so much content to consume. We are constantly bombarded with videos, images, ads, podcasts and articles. Each of these media has a different type of appeal, and there always seems to be stiff competition trying 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. Over the past few decades, as various media channels have evolved, there has been less emphasis on textual content and more attention on visuals—particularly videos and images. According to a 1997 memo from 3M, people process images 60,000 times faster than text.

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. However, knowing how to write is still an important skill. Language is one of the purest forms in which a person can express his or her thoughts. Language can be expressed as a letter, an article or a text message. Writers communicate and share their ideas in ink on paper or digital 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. I learned that good writing can be a catalyst for success, whether it’s personal growth, professional development, or social prosperity. Over the past few years, many of the skills I gained from writing dozens of articles have translated into my new full-time role as a software engineer at Putnam Investments. Photo by Aaron Burden on Unsplash.

As a developer, here are five benefits I’ve come across by learning to write. As a developer, here are five benefits I’ve learned from learning to write.

1. Writing well makes you a better communicator (writing well can make 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. The most obvious benefit I’ve realized from writing frequently is that good writing makes me a better communicator. As humans, we rely primarily on our words to convey our thoughts and feelings to others. By writing regularly, I can express my ideas more easily without having to worry about whether I’m using the right words, writing too much or too little, or being too vague or complex.

Image from https://zalarieunique.ru.

At work, I can draft concise emails or send 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. At work, I can draft concise emails or send instant messages without having to resort to a dictionary or thesaurus to sound smart. When ideas can flow freely from your head to your hands, the words on the paper flow smoothly without having 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. Writing, like many other crafts, takes years of practice to hone. The best part about writing is that progress is noticeable. You can look at previous work and see noticeable improvements over time.

2. Writing for an audience helps you write better documentation (Writing for an audience can help 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.

Part of 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—and the same goes for communicating with stakeholders or writing any kind of documentation.

When working with less technical team members, you have to explain technical terms and concepts in a way that 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.

When working with less technical team members, you must explain technical terms and concepts in a way that makes sense and resonates with anyone you work with. For example, when working with product owners and designers, I usually provide a high-level overview of what I’m doing without getting bogged down in the details. For designers, I try to illustrate how the feature should be implemented from a user experience or UI perspective. For product owners, I try to organize my work from a business perspective.

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 (immediately/immediately) without having to deconstruct and reverse-engineer the code.

Additionally, developers must communicate their work with other developers. Whether naming variables or functions, writing inline comments, or documenting how a system should work from a high level, developers need to know how to write good documentation so that the code is easy to understand and maintain. Whenever I write a document, I try to make it as complete as possible. Any developer working on my code base understands the high-level structure and can contribute immediately without having to deconstruct and reverse-engineer the code.

3. Writing makes you appreciate the idiosyncrasies of programming

Back in 2011, a Redditor posted in the /r/programming subreddit 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.

Back in 2011, a reddit user posted on /r/programming about the similarities and differences between writing and programming. Some people say that programming is similar to writing in that it is a skill that is not conceptually difficult but becomes more and more refined over time. Others believe that writing and programming are completely different because writing is a creative endeavor while programming is a more complex science that requires a deeper understanding of basic concepts.

The 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(experienced; veteran/veteran/veteran) in each field is the ability to be creative and deal with the complexity of the system or topic at hand.

The general consensus, with slight disagreements on every detail, is that both writing and programming require knowledge of the basic fundamentals - syntax, structure, and semantics. In every field, however, what separates amateurs from veterans is their creative ability to handle the complexities of the system or topic at hand.

A lot of these ideas touch upon(touch upon involve; touch; talk about) the fields of linguistics and language. Many of these perspectives relate to 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.

Writing teaches developers to think differently. For developers, writing code can be restrictive because of the limited number of keywords, functions, and libraries that can be used. However, written language allows a complete freedom of expression that programming languages ​​generally do not 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 brings up another interesting point when it comes to the way we use words in code and other media.

“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 (based on; close to; on) the old.

In the field of writing, it seems that a strict dichotomy has been created over time, dividing the concerns of the writer and the reader. Writing seems static (set in stone), while coding is an ongoing effort to improve something old.

In many ways, writing “creatively” and writing code share many similarities, but knowing their differences makes me appreciate both much more.

In many ways, writing “creatively” and writing code have many similarities, but understanding their differences has made me appreciate both even more.

4. Writing gives you a chance to apply what you learn (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 (special; detailed; unique; picky) area is to write about that topic.

When I write, it always feels like I’m having a conversation with myself. When I finish reading a book or discover something important, I try to wrap my mind around it by writing an essay about what I learned. For me, I find that the best way to advance my knowledge in a particular field is to write about the subject.

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 volunteers 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.

On freeCodeCamp and many other websites that provide basic development tutorials, authors write about a variety of different topics and concepts. Part of the reason so many volunteers devote their time to writing articles is that not only can they share their experiences and help others, but they can also enhance their knowledge of the topics they write about.

freeCodeCamp, one of the best resources for development tutorials and articles. freeCodeCamp, one of the best resources for development tutorials and articles.

When I write about topics I learn about, I usually conduct (conduct; lead vt. management; guidance; performance n. conduct; behavior; implementation) additional (additional, additional) research (research; investigation) that often results in me coming across snippets (fragments) of information I wouldn’t otherwise be exposed to. 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.

When I write about a topic I know something about, I often conduct additional research, which often exposes me to snippets of information that I wouldn’t normally be exposed to. When I write, I’m more likely to remember what I’ve learned. In addition, I sometimes encounter different perceptions and perspectives that challenge my original views. The entire process of writing is a living, ongoing conversation that allows me to process the information I encounter 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.

Writing is a great way to digest and process the information we have. However, erudition and intelligence arise not from the amount of information we receive, but from our ability to process that information and draw meaningful conclusions from it.

Writing is a great way to digest and process information. However, knowledge and intelligence do not come from the amount of information we absorb, but from our ability to process that information and draw meaningful conclusions from it.#### 5. Writing as a form of catharsis(Writing is a form of catharsis/Writing is 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. The last reason I think writing is important may not be directly related to the developer role for the last four reasons. But I think that’s also important, if not more important. A large part of the reason why I choose to write is because writing is an important outlet for my emotions and feelings. I don’t like to keep my feelings and thoughts bottled up, so I use writing as a form of catharsis. The last reason I think writing is important may not be as directly related to the role of a developer as the last four reasons. But I think it’s just as important, if not more important. A big part of the reason I choose to write is because writing is a great outlet for me to express my emotions and feelings. I don’t like to keep my feelings and thoughts bottled up, so I seek 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. When I was younger, I used to write journal entries in a journal. Now I write about many topics and publish them for the world to read. But from time to time I use pen and paper to express my personal thoughts. I occasionally write in a personal journal when I’m doubting my career goals, personal life, social relationships, and everything in between. When I was young, I often kept a diary. Now, I write about a variety of topics and publish them for the world to read. But every now and then, I return to pen and paper to express my personal thoughts. I keep a personal journal that I write in occasionally when I have questions about my professional goals, personal life, social relationships, and everything in between.

<font size=6> There’s nothing to writing. All you do is sit down at a typewriter and bleed. </font> Nothing to write home about. All you have to do is sit in front of a typewriter and bleed. Writing is nothing. All you do is sit 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. When I write about my feelings, it feels like I’m talking to a friend who is a great listener. It’s a way for me to clear my mind of negativity and speak to an empty page without fear of judgment. When I write about my feelings, it feels like I’m talking to a friend who listens well. For me, it’s a way to let go of negative emotions and speak to a blank page without fear of being judged.

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. There are many benefits to writing, and while it may not be your first choice for expressing your thoughts, it is a necessary and useful skill even in today’s noisy and chaotic world. Even if you are a beginner in the world of writing, I recommend that you think about your thoughts alone and let your thoughts flow freely. What you can think of is amazing. Writing has many benefits, and while it may not be your first choice for expressing your thoughts, it is a necessary and useful skill, even in today’s noisy and confusing world. Even if you are new to writing, I suggest you try sitting alone with your thoughts and letting your thoughts flow freely. It’s amazing what you can come up with.

. . .

Thanks for taking the time to check out my article! Thank you 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! If you liked this article, please put down a few claps, follow my instructions, and recommend this article to your friends. Feel free to follow me on Instagram or connect with me on LinkedIn!

Derek Mei http://www.derekmei.com

TIPS:

How to download a large image

We usually use SDWebImage to download pictures. SDWebImage downloads pictures directly into the memory and uses them directly for display. However, if an image is very large, downloading it directly using SDWebImage is likely to cause a sudden increase in memory and cause a crash. How to solve this problem? Apple officially has an example of loading local large images (https://developer.apple.com/library/archive/samplecode/LargeImageDownsizing/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011173-Intro-DontLinkElementID_2),参照这个例子,我们可以先把图片下载到本地,然后再用苹果的例子进行加载图片,下载图片到本地可以用AFNetWorking,把图片先下载到本地。

Share:

How to learn data structure well:

Here are some other people’s opinions for reference:

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

Here are some summaries of sorting:

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


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

My opinion: When learning algorithms and data structures, if the foundation is relatively poor, you can first write down the data structures of some basic algorithms, and then you must be able to implement these basic algorithms and data structures yourself. After thoroughly understanding these basic things, you can then do more difficult questions, because the solutions to more difficult questions will use basic things. Don’t take difficult questions right from the start. It’s meaningless. Not only will it undermine your confidence, but you won’t be able to understand many of the solutions. All you have to do is become familiar with the basic algorithms and data structures. If you are familiar with it, you can at least be able to implement it in code. It does not just mean that you feel you understand it. There is a big gap between understanding and implementation. Only when you implement it yourself can you feel the details and essence.

It’s best to become familiar with sorting and searching as follows: Commonly used sorting: insertion sort selection sort merge sort bubble sort Heap sort Quick sort counting sort Radix sort bucket sort

Find structure: Binary Search Tree [BST] Balanced Binary Search Tree [AVL] Multi-way search tree/B~ tree/B+ tree red black tree [RBT] Dynamic search tree comparison

FAQ

读完之后,下一步看什么

如果还想继续了解,可以从下面几个方向接着读。

Related

继续阅读

这里整理了同分类、同标签或同类问题的文章。