返回首页

ARTS #011

ARTS #011

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 011

This is article 11

Algorihm algorithm question

leetcode algorithm question 241.Reorganize String: Difficulty: Moderate


Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.

Example 1:
Input: "2-1-1"
Output: [0, 2]
Explanation: 
((2-1)-1) = 0 
(2-(1-1)) = 2

Example 2:
Input: "2*3-4*5"
Output: [-34, -14, -10, -10, 10]
Explanation: 
(2*(3-(4*5))) = -34 
((2*3)-(4*5)) = -14 
((2*(3-4))*5) = -10 
(2*((3-4)*5)) = -10 
(((2*3)-4)*5) = 10

Divide and conquer method, using recursion, the code is as follows, the running time of leetcode is 0ms:


int*  diffWaysToCompute1(int* str,int min,int max) {
    
    if(min == max){
        int *charCount = (int*)malloc(sizeof(int) * 2);
        charCount[0] = 2;
        charCount[1] = str[min];
        return charCount;
    }
    
  
    if (max - min == 2) {//if 里面的这个可以去掉,只是为了加快运算
        int minNum = str[min] ;
        int maxNum = str[max] ;
        int mid = str[min +1];
        int num = 0;
        if (mid==-42) {//*
            num = minNum * maxNum;
        }
        else if(mid==-43){//+
            num = minNum + maxNum;
        }
        else if(mid==-45){//-
            num = minNum - maxNum;
        }
        int* charCount = (int*)malloc(sizeof(int) * 2);
        charCount[0] = 2;
        charCount[1] = num;
        return charCount;
    }
    else
    {
        int *charCount = NULL;//
        for (int mid = min; mid < max; mid +=2) {
            int *nums_1 = diffWaysToCompute1(str,min,mid);
            int *nums_2 =  diffWaysToCompute1(str,mid+2,max);
            
            int nums_1_count = nums_1[0] - 1;
            int nums_2_count = nums_2[0] - 1;
            int index = 1;
            if (charCount == NULL) {
                charCount =(int*)malloc(sizeof(int) * (nums_1_count * nums_2_count +1));
                 charCount[0] = nums_1_count * nums_2_count + 1;
            }
            else{
                charCount=(int*)realloc(charCount,sizeof(int)*(charCount[0]+ nums_1_count * nums_2_count));
                index = charCount[0];
                charCount[0] = nums_1_count * nums_2_count + charCount[0];
                
            }
        
            int op = str[mid + 1];
            for (int i= 1; i <= nums_1_count; i++) {
                int left = nums_1[i];
                for (int j= 1; j <= nums_2_count; j++) {
                    int right = nums_2[j];
                    int num = 0;
                    if (op==-42) {//*
                        num = left * right;
                    }
                    else if(op==-43){//+
                        num = left + right;
                    }
                    else if(op==-45){//-
                        num = left - right;
                    }
                    
                    charCount[index++] = num;
                }
            }
            free(nums_1);
            free(nums_2);
        }
        return charCount;
    }
    return NULL;
}

//因为存在连续数字字符的情况,比如 "109-23-9",所以先把字符串转为数组
int* diffWaysToCompute(char* input, int* returnSize) {
    //计算运算符的个数 用来计算要需要分配的内存空间,比如比如 "109-23-9",有两个运算符,需要分配的内存空间是5个
    int operatorCount = 0;
    for(int i = 0; i < strlen(input); i++){
        if (input[i]==42 || input[i]==43 || input[i]==45){
            operatorCount++;
        }
    }
    
    int *inputToIntArray = (int*)malloc(sizeof(int) * (2*operatorCount +1));//分配数组空间
    int index = 0;
    int data = 0;
    for(int i = 0; i < strlen(input); i++){
        char dataChar = input[i];
             //42 * , 43 + , 45 -,因为输入中不含负数,为了区分运算符和数字,把运算符用负数表示,
        if (dataChar == 42 || dataChar == 43 || dataChar == 45){
            inputToIntArray[index++] = data;
            inputToIntArray[index++] = -dataChar;
            data = 0;
            continue;
        }
        data = data *10 + (dataChar - 48);
    }
    inputToIntArray[index] = data;

    int* charCount = diffWaysToCompute1(inputToIntArray, 0, index);
    free(inputToIntArray);
  
    *returnSize = charCount[0] -1;
    int *ffcharCount =  charCount +1;
    return ffcharCount;
}

You can also remove the if code


int*  diffWaysToCompute1(int* str,int min,int max) {
    
    if(min == max){
        int *charCount = (int*)malloc(sizeof(int) * 2);
        charCount[0] = 2;
        charCount[1] = str[min];
        return charCount;
    }
    
 
    int *charCount = NULL;//
        for (int mid = min; mid < max; mid +=2) {
            int *nums_1 = diffWaysToCompute1(str,min,mid);
            int *nums_2 =  diffWaysToCompute1(str,mid+2,max);
            
            int nums_1_count = nums_1[0] - 1;
            int nums_2_count = nums_2[0] - 1;
            int index = 1;
            if (charCount == NULL) {
                charCount =(int*)malloc(sizeof(int) * (nums_1_count * nums_2_count +1));
                 charCount[0] = nums_1_count * nums_2_count + 1;
            }
            else{
                charCount=(int*)realloc(charCount,sizeof(int)*(charCount[0]+ nums_1_count * nums_2_count));
                index = charCount[0];
                charCount[0] = nums_1_count * nums_2_count + charCount[0];
                
            }
        
            int op = str[mid + 1];
            for (int i= 1; i <= nums_1_count; i++) {
                int left = nums_1[i];
                for (int j= 1; j <= nums_2_count; j++) {
                    int right = nums_2[j];
                    int num = 0;
                    if (op==-42) {//*
                        num = left * right;
                    }
                    else if(op==-43){//+
                        num = left + right;
                    }
                    else if(op==-45){//-
                        num = left - right;
                    }
                    
                    charCount[index++] = num;
                }
            }
            free(nums_1);
            free(nums_2);
        }
        return charCount;

}

//因为存在连续数字字符的情况,比如 "109-23-9",所以先把字符串转为数组
int* diffWaysToCompute(char* input, int* returnSize) {
    //计算运算符的个数 用来计算要需要分配的内存空间,比如比如 "109-23-9",有两个运算符,需要分配的内存空间是5个
    int operatorCount = 0;
    for(int i = 0; i < strlen(input); i++){
        if (input[i]==42 || input[i]==43 || input[i]==45){
            operatorCount++;
        }
    }
    
    int *inputToIntArray = (int*)malloc(sizeof(int) * (2*operatorCount +1));//分配数组空间
    int index = 0;
    int data = 0;
    for(int i = 0; i < strlen(input); i++){
        char dataChar = input[i];
             //42 * , 43 + , 45 -,因为输入中不含负数,为了区分运算符和数字,把运算符用负数表示,
        if (dataChar == 42 || dataChar == 43 || dataChar == 45){
            inputToIntArray[index++] = data;
            inputToIntArray[index++] = -dataChar;
            data = 0;
            continue;
        }
        data = data *10 + (dataChar - 48);
    }
    inputToIntArray[index] = data;

    int* charCount = diffWaysToCompute1(inputToIntArray, 0, index);
    free(inputToIntArray);
  
    *returnSize = charCount[0] -1;
    int *ffcharCount =  charCount +1;
    return ffcharCount;
}

Review

####Article 1: Google releases new phones, tablets, telegraph and smart home control assistant Google has launched the latest versions of its Pixel smartphone, as well as a new tablet computer and a smart home controller. Google has unveiled its latest Pixel smartphones, along with new tablets and a smart home control assistant.

The new products were announced during an event Tuesday in New York. Google announced the new products at a launch event in New York on Tuesday.

Google launched the first Pixel smartphone two years ago as part of a major new effort to develop hardware. As one of its major moves in hardware development, Google released its first Pixel smartphone two years ago.

The company is better known for building software to power internet search technology and the Android smartphone operating system. The company is best known for developing software that powers web search technology and the Android smartphone operating system.

Over the past two years, Google has sold about 7 million Pixel phones, the technology research company IDC estimates. Technology research firm IDC estimates that Google has sold about 7 million Pixel smartphones in the past two years.

Those sales are a very small part of the estimated 3.6 billion phones sold by all manufacturers during that same two-year period. These sales represented only a small portion of the estimated 3.6 billion mobile phones sold by all manufacturers during the same period.

Apple, for example, sold about 388 million iPhones during the two years. For example, Apple sold approximately 366 million iPhones in the past two years.

Google’s new smartphones - the Pixel 3 and Pixel 3 XL - appear aimed at providing iPhone-like features at a lower price. Google’s new smartphones, the Pixel 3 and Pixel 3 XL, appear to be designed to offer iPhone-like features at a lower price.

The Pixel 3 will be available October 18 in the United States for $799. The Pixel smartphone will go on sale in the United States on October 18, priced at only $799.

The larger Pixel 3 XL will cost $899. The larger Pixel 3 XL smartphone costs $899.

This compares to the iPhone Xs, which sells for $999, and the iPhone Xs Max, priced at $1099. In comparison, the iPhone Xs sells for $999 and the iPhone Xs Max costs $1,099.

Both new Pixels are also being released in 12 other countries, including Japan, Singapore and India. The two new Pixel series phones will be sold in 12 other countries, including Japan, Singapore and India.

During Tuesday’s launch event, Google officials demonstrated new features and improvements to the Pixel 3. At a press conference on Tuesday, Google officially showed off the new features and improvements of Pixel 3.

At times, they made direct comparisons to iPhones. They also sometimes directly compare it to the iPhone.

Google promises better camera performance in its Pixel 3 devices. Google promises better camera features in its Pixel 3 devices.

A new tool is designed to use machine learning software to produce better low-light and close-up shots. The new device aims to use artificial intelligence software to deliver better low-light and close-up shots.

The tool works by combining many shots quickly taken one after the other. The device works by quickly combining multiple lenses one after the other to achieve a shot.

The camera also uses machine learning to examine the many photos it takes in an effort to find and suggest the best ones The camera also uses artificial intelligence software to examine multiple photos taken and can find or recommend the best one.

Pixel 3 phones were also built with two camera lenses in front, which Google demonstrated as a helpful tool when taking selfies with large groups. The Pixel 3 smartphone also comes with two front-facing cameras, and Google has proven them to be a useful tool for taking photos of large groups.

The phone is also able to answer itself if the user cannot or does not want to pick up. The phone can also automatically answer calls if the user is unable or unwilling to answer the call.

If a call comes in, the user can touch the screen to have the phone answer and ask who is calling. If a call comes in, users can touch the screen to have the phone automatically answer the call.

The answer from the person placing the call is then put into a text message and shared with the user in real time. The caller’s response is converted into a text message and shared with the user in real time.

Google Product Manager Liza Ma said the feature puts the user in complete control of the phone. Google product manager Lisa Ma said this feature allows users to fully control their phones.

“You can decide whether to pick up, send a quick reply, or mark the call spam. You’ll never have to talk to another telemarketer.” “You can decide whether to answer the call, send a quick reply message, or mark it as a spam call. You won’t have to talk to a telemarketer,” she said.

As with the earlier models, the new Pixels center heavily on the company’s search engine and other products. Like earlier models, the new Pixel phones focus on Google’s search engine and other products.

These include maps, Google Assistant and YouTube video service. Includes Maps, Google Assistant and YouTube video services.

Google also introduced its new Home Hub, an internet-connected smart speaker and home controller with a small screen. Google also launched its new smart home assistant Home Hub, which is a smart connected speaker and home smart control device equipped with a small screen.

The device is similar to Amazon’s Echo Show and Facebook’s new Portal. The device is similar to Amazon’s Echo Show and Facebook’s latest Portal.The company said Home Hub is designed to be a central controller for many devices throughout the home, such as lights, outdoor cameras, temperature controls and televisions. According to Google, the smart home assistant Home Hub is designed to be a controller for many devices in the home, such as lights, outdoor cameras, temperature controllers and TVs.

Like similar devices, it can be activated by voice to play music and look up information on the internet. Like similar devices, it can be controlled by voice to play music and search for information on the Internet.

Home Hub will cost $149 when it goes on sale later this month in the United States, Britain and Australia. The smart home assistant Home Hub will be on sale in the United States, the United Kingdom and Australia later this month, priced at 149 yuan.

This compares to the new version of Amazon’s Echo Show, which sells for $229. The cost of the Facebook Portal starts at $199. By comparison, Amazon’s latest Echo Show costs $229, while Facebook’s Portal costs $199.

Google also announced it would launch a new computer tablet later this year called the Pixel Slate. Google also announced that it will release a new tablet called the Pixel Slate later this year.

The company says the device will be powered by its own newly designed Chrome OS system. It appears aimed at competing with Apple’s iPad Pro. The company says the device will be powered by its own version of Chrome OS, which appears to be designed to compete with Apple’s iPad Pro.

The Slate will run Android phone apps, but Google says it offers performance closer to a desktop computer. The Slate will run Android mobile software, but Google says the device will offer performance close to that of a desktop computer.

It is priced at $599. An exact release date has not yet been announced. The tablet is priced at $599, and its specific release date has not yet been announced.

####Article 2:

He Jiang, the first Chinese student on the Harvard graduation podium in 2016 When I was in middle school, a poisonous spider bit my right hand.

When I was in middle school, I was bitten on my right hand by a venomous spider. I ran to my mom for help, but instead of taking me to a doctor, my Mom set my hand on fire.

I went to my mother for help, but instead of calling a doctor, she burned my hands with fire. After rubbing my hand with several layers of cotton then soaked in wine, she put a chopstick into my mouth and ignited the cotton.

She wrapped wine-soaked cotton yarn around my hand. After wrapping it several times, I put a chopstick in my mouth and lit the cotton yarn. Heat quickly penetrated the cotton and began to roast my hand.

The heat quickly penetrated the cotton and began to burn my right hand. The searing pain made me want to scream but the chopstick prevented it.

The burning pain made me want to scream, but the chopsticks in my mouth kept me from screaming. All I could do was watch my hand burn, one minute, then two minutes, until my mom put out the fire.

All I could do was look at my burning hand. One minute passed, then two minutes passed, until my mother put out the fire. You see the part of China I grew up in was a rural village, and at that time, pre-industrial.

As you can see, I grew up in a small mountain village in China, which was not yet industrialized at that time. When I was born, my village had no cars, no telephones, no electricity, not even running water and we certainly didn’t have access to the modern medical resources.

In the era when I was born, our village had no cars, no telephones, no electricity, not even running water, let alone access to modern medical resources. There was no doctor my mom could bring me to see about this spider bite.

When I was bitten by a spider, there was no doctor my mother could take me to. For those who study Biology, you may have brought the science behind my mom’s cure: heat deactivates proteins and the spider’s venom is simply a form of protein.

For those of you who study biology, you may already know the scientific basis for my mother’s treatment: heat inactivates proteins, and spider venom is only made of proteins. It’s cool how that folk remedy actually incorporates the base of biochemistry, isn’t it?

The basic principles of modern biochemistry are actually included in the traditional method. It’s pretty cool to think about it, isn’t it? But I am a Ph. D student in Biochemistry at Harvard, I now know that better, less painful and less risky treatment existed.

But as a PhD student in biochemistry at Harvard, I now know that there are better, less painful, and less dangerous treatments. So, I can’t help but ask myself, why I did’t receive one at that time?

So I couldn’t help but ask myself, why didn’t I use this method to treat it at that time? Fifteen years have passed since that incident, I am happy to report that my hand is fine.

It’s been fifteen years since this incident, and I’m happy to report that my hand is now recovering very well. But this question lingers and I continued to be troubled by the unequal distribution of scientific knowledge throughout the world.

But this question still haunts me, and I am still troubled by the uneven distribution of scientific knowledge in the world. We have learned to edit the human genome and unlock many secrets of how cancer progress.

We have learned to edit the human genome, unlocking many of the secrets of cancer development. We can manipulate neuron activity literally with the switch of light.

We can even manipulate the activity of brain neurons with light beams. Each year brings more advances in Biomedical research, exciting transformative accomplishments. Every year there are tremendous advances and exciting, disruptive achievements in the field of biomedicine.

Yet, despite the knowledge we have amassed, we haven’t been so successful in deploying it to where it’s needed most. However, although humans have mastered and accumulated a large amount of knowledge, we still fail to apply it well where it is needed most.

According to the World Bank, 12% of the world population lives on less than 2 dollars a day. According to World Bank statistics, 12% of people in the world still live on less than $2 a day.

Malnutrition kills more than 3 million children annually. More than three million children die from malnutrition every year.Three hundred million people are afflicted by Malaria globally. Three hundred million people worldwide are suffering from malaria.

All over the world, we constantly see these problems of poverty, illness, and lack of resources impeding the flow of scientific information. Around the world, we often see problems such as poverty, disease, and resource shortages that hinder the spread of scientific knowledge.

Life-saving knowledge we take for granted in our modern world is often unavailable in the underdeveloped regions. The life-saving knowledge that is taken for granted in modern society is usually not popularized in underdeveloped areas.

And so, in far too many places, people are still essentially trying to cure a spider bite with fire. Therefore, in many parts of the world, people still use fire therapy to treat spider bites.

While studying at Harvard, I saw how scientific knowledge can help others in simple, yet profound ways. While studying at Harvard, I learned how scientific knowledge can help others in both simple and profound ways.

The bird flu pandemic in the 2000s looked to my village like a spell cast by demons. In 2000, bird flu was raging. To our village, this disease was like a curse from the devil.

Our folk medicine didn’t even have half-measures to offer. The solution simply cannot be found in our folk remedies.

What’s more, farmers didn’t know the difference between the common cold and flu. To make matters worse, farmers don’t know the difference between a common cold and the flu.

They did not understand that the flu was much more lethal than common cold. They don’t understand that the flu is much more deadly than the common cold.

Most were also unaware that the virus could transmit across different animal species. What’s more, most people simply don’t understand that influenza viruses can spread between species.

So when I realized that simple hygiene practices like separating different animal species could help to contain the spread of the disease, So when I learned that simple and effective hygiene measures, such as isolating different species, can curb the spread of disease,

and that I could help make this knowledge available to my village. And tell this information to my villagers.

That was my first aha moment as a bioscientist. For the first time, I felt a sense of accomplishment as a biological scientist.

But it was more than that: it was also a vital inflection point of my own ethical development, my own self-understanding as a member of the global community. But it was more than that: it was an important turning point in my personal ethics and understanding of my destiny as a human being on this planet.

Harvard dares us to dream big, to aspire, to change the world. Harvard teaches us to dare to dream big and move forward to change the world.

Here on this Commencement Day, we are probably thinking of grand destinations and big adventures that await us. Today at this graduation ceremony, you may be imagining the great ideals and journeys that await us.

As for me, I am also thinking of the farmers in my village. For me, I am still thinking about the fate of the farmers in my hometown.

My experience here reminds me how important it is for researchers to communicate our knowledges, to those who need it. My experience reminded me how important it is for scholars to impart knowledge to those who need it.

Because by using the science we already have, we could probably bring my village and thousands like it into the world you and I take for granted every day. Because by using the science we already have, we can bring the villagers of my hometown and thousands of others like them into the world you and I know.

And that’s an impact every one of us can make! This is an impact each of us can make!

But the question is, will we make the effort, or not? But the question is, will we do this?

More than ever before, our society emphasized science and innovation, but an equally important emphasis should be on distributing the knowledge we have to those who need. Today’s society emphasizes the importance of science and innovation more than ever before. But equally important is the dissemination of knowledge that humans already possess to the places where it is most needed.

Changing the world doesn’t mean everyone has to find the next big thing. Changing the world doesn’t mean everyone has to find the next big breakthrough.

It can be as simple as becoming better communicators and finding more creative ways to pass on the knowledge we have, to people like my mom and farmers in the local community. Changing the world can be simple: becoming a better communicator and using effective methods to pass on the knowledge we have to people like my mother and other villagers in the village.

Our society also needs to recognize that the equal distribution of knowledge is a pivotal step of human development and we will work to bring this into a reality. We as a society also need to realize that the balanced dissemination of knowledge is a key link in human development and should strive to make it a reality.

And if we do that, then perhaps a teenager in rural China who is bitten by a poisonous spider will no longer have to burn his hand, but will know to seek a doctor instead. If we can do this, then a Chinese rural boy bitten by a poisonous spider will not endure “fire therapy” but will receive professional treatment from a doctor.

Thank you! Thank you!

TIPS

How to add rounded corners to UIView with high performance, generally use the following method,

  UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(r, r)];
  CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
 maskLayer.frame = rect;
  maskLayer.path = maskPath.CGPath;
  
  view.layer.mask =   maskLayer
            

That is to say, set view.layer.mask, but when using the above method to add a mask to the subview of tableViewCell, as in the following code, when the height of the cell is not an integer, such as 30.23, the edge of the tableViewCell will appear virtual. No solution has been found yet.

UIVIew *bgView = [UIVIew  new];
bgView.frame = tableViewCell.bounds;
[tableViewCell.contentView addSubview:bgView];

bgView.layer.mask =  maskLayer;

Share:

An APP came alive today. It is an APP that calculates how many days are left in 2018. It was originally free. Later, due to the recommendation of a Douyin public account, the number of downloads was very large. The author made the APP chargeable, and the price was 3 yuan. I heard that the author’s daily income should be tens of thousands. The traffic is really amazing.

APP money-making model: 1 paid download 2 Free downloads, feature unlocking charges 3 Free download Free trial Advertising charges 4. Free download, free subscription trial of the function. This is very confusing. Many users don’t know how to cancel the subscription or it is very troublesome to cancel.

When I see other people making apps, I feel very itchy and want to make my own app, but I don’t have any good ideas. Current job: 1 work 2 Learning algorithms, English, arts 3. Read books to gain a deeper understanding of computer systems. csapp and sicp are best read in English. 4 Improve iOS skills, log, image compression, obfuscation, detect memory leaks, etc.

FAQ

读完之后,下一步看什么

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

Related

继续阅读

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