Reading guide
Fat friends, in order to better help new students adapt to algorithms and interview questions, we recently started a special assault step by step. In the last issue, we completed 21 days of dynamic programming, and now we will make a 14 day summary of various algorithms. What are you waiting for? Come to fat school for a 14 day challenge!!
Special introduction
📣 Xiaobai training column is suitable for newcomers who have just started. Welcome to subscribe Programming Xiaobai advanced
📣 The interesting Python hand training project includes interesting articles such as robot awkward chat and spoof program, which can make you happy to learn python Training project column
📣 In addition, students who want to learn java web can take a look at this column: Teleporters
📣 This is a sprint factory interview column and algorithm competition practice. Let's cheer together The way ashore
Algorithm training for 14 days
Write a function that inverts the input string. The input string is given as a character array s.
Do not allocate additional space to another array. You must modify the input array in place and use the additional space of O(1) to solve this problem.
Example 1: Input: s = ["h","e","l","l","o"] Output:["o","l","l","e","h"]
Example 2: Input: s = ["H","a","n","n","a","h"] Output:["h","a","n","n","a","H"]
class Solution { public void reverseString(char[] s) { int n = s.length; for (int left = 0, right = n - 1; left < right; ++left, --right) { char tmp = s[left]; s[left] = s[right]; s[right] = tmp; } } }
Given a string, you need to reverse the character order of each word in the string while still retaining the initial order of spaces and words.
Example: Input:"Let's take feixue contest" Output:"s'teL ekat euxief tsetnoc"
class Solution { public String reverseWords(String s) { char[] ss=s.toCharArray(); int n=s.length(); int l=0,r=0; while(l<n){ if(ss[l]==' ') l++; else{ r=l; while(r<n&&ss[r]!=' '){//Prevent cross-border and find the end r++; } if(r<n) swap(ss,l,r-1);//Considering cross-border, it is likely that the last word is directly to the last character else swap(ss,l,n-1); l=r; } } return new String(ss); } void swap(char[] ss,int l,int r){//Exchange order for(int i=0;i<=(r-l)/2;i++){ char temp=ss[l+i]; ss[l+i]=ss[r-i]; ss[r-i]=temp; } } }
Interview questions
Continue with the previous issue:
How is Io density = Ncpu*2 calculated? When I/O-Intensive tasks are applied, the system will spend most of its time processing I/O interaction, and threads will not occupy CPU for processing during the time period of processing I/O. at this time, the CPU can be handed over to other threads for use. Therefore, in the application of I/O-Intensive tasks, we can configure more threads. For example: database interaction, file upload and download, network transmission, etc. IO intensive, that is, the task requires a large number of IO, that is, a large number of blocking, so the number of threads needs to be configured.
7,G1 What are the characteristics of the collector? G1 My full name is Garbage-First,It means garbage first. Whichever piece of garbage has the most, clean it first. G1 GC The main design objectives are: STW The pause time and distribution become predictable and configurable. Deemed JDK1.7 in HotSpot An important evolutionary feature of virtual machine. It has the following characteristics: Parallelism and Concurrency: G1 Can make full use of CPU,Hardware advantages in multi-core environment, using multiple CPU(CPU perhaps CPU Core) to shorten Stop-The-World Pause time. Some other collectors would have needed to pause Java Line Process execution GC Action, G1 The collector can still use concurrency to java The program continues. Generational collection: Although G1 You can manage the whole system independently without the cooperation of other collectors GC Heap, but keep it The concept of generation is introduced. Spatial integration: and CMS Tag for-The clean-up algorithm is different, G1 On the whole, it is based on "tag"-"Finishing" calculation Collector implemented by method; Locally, it is based on "tag"-The "copy" algorithm is implemented. Predictable pause: This is G1 be relative to CMS Another big advantage of reducing pause time is G1 and CMS common Same concerns, but G1 In addition to pursuing low pause, it can also establish a predictable pause time model for users to understand Be sure to specify a length of M In milliseconds. G1 The collector maintains a priority list in the background. Each time, according to the allowable collection time, the collector gives priority to the one with the greatest recycling value Region(That's its name Garbage-First
Click to receive the data directly
There are python, Java learning materials, interesting programming projects and various resources that are hard to find. It's not a loss to look at it anyway.