Today the college entrance examination is over, perhaps some students who love code after 00, saw the answers published on the Internet, began to estimate points, from 985/211 poor to do wrong or less to do a question, feel no chance, to the community to see the code. I was admitted to the double non school many years ago. Although there is a little strange his ignorant crush on the female deskmate in an examination room before and after the table, in the examination room play is not good, but, each course, to the difficult topic, never jump lei Chi step, some of the heart double non ability set, not unrelated.

As an old driver who has been writing code for many years, I would like to say to the students who are preparing for the autumn recruitment that algorithm is really important. Just like in the college entrance examination, if you get the last one or two questions of math right, you can enter 985/211. If you get the wrong answer, you can enter the double Non-school. And in the autumn recruit, the algorithm is not good, it is difficult to enter the famous enterprises.

Leetcode is popular

Not to mention, the universe bar, the front-end interview test is a pile of algorithm questions, Tencent/Ali, two or three have a special algorithm online pen test questions. Several LeetCode-related projects were among github’s most popular open source projects in the first half of the year. As Leetcode becomes more and more popular, the good days of leaving it to the front-end interns to go through the sorting algorithm and get an offer from a company that is not bad are probably over.

  • Write a webpack from scratch, 200 lines of code to implement mini-React, etc. The author deconstructs the leetcode question bank with his ideas of solving Leetcode and the examination points of the interview, which is highly recommended.
  • Leetcode Animation comes from programmer Brother Wu, a god open source project of 30,000 + Start. It is it that animates the understanding of Leetcode and brings leetcode learning wind, which should not be missed. With it, no algorithm, excuse.
  • The beauty of data structures and algorithms by Geek Time Teacher Wang Zheng

If you want to go to a famous company, go firstleetcodeThe website problem solving

Interview and write online code, using niuke, I suggest to study efficiently, using a variety of learning artifacts and online learning products. Because these online test products are used directly or indirectly to improve the efficiency of big factory interviews, and most importantly, it allows our learning of algorithms to be recorded, leetcode learning can be proven.

Innovative leetcode learning ways to share

I would like to share with you here a relatively suitable front-end, visualization, ES6, easy to use problem solving strategy.

Leetcode questions 86Chain table space

List separation, is a data structure linked list of basic examination questions, questions as follows:

Given a linked list and a particular value x, separate the list so that all nodes less than x precede those greater than or equal to x. You should preserve the initial relative position of each node in the two partitions.

Input: the head = 1 - > > 4-3 - > 2 - > - > 2, 5 x = 3 output: 1 - > 2 - > 4 - > 2 - > 3 - > 5Copy the code
  • I went to Leetcode Animation to see the illustrations. In fact, most of the time, I followed Brother Wu to solve leetcode problems. He can always get the intention of the algorithm as he animates it.

  • From trekhleb

Trekhleb data structure implementation, very nice, strong recommendation, I brush in leetcode data structure class topic, using Trekhleb code to implement

Node code

export default class LinkedListNode {
 constructor(value, next = null) {
   this.value = value;
   this.next = next;
 }

 toString(callback) {
   return callback ? callback(this.value) : `${this.value}`; }}Copy the code

Linked list implementation code

import  LinkedListNode from './LinkedListNode.js';

class LinkedList {
 constructor() {
   // 1->4->3->2->5->2 
   this.head = null;
   this.tail = null;
 }
 append(value) {
   const newNode = new LinkedListNode(value);
   if(! This. head) {// Empty list this.head = newNode; this.tail = newNode; }else {
     this.tail.next = newNode;
     this.tail = newNode;
   }
   return this;
 }
 toArray () {
   const nodes = [];
   let currentNode = this.head;
   while(currentNode) {
     nodes.push(currentNode);
     currentNode = currentNode.next;
   }
   return nodes;
 }
 toString() {
   returnthis.toArray().map(node=>node.val); }}export default LinkedList;
Copy the code

The linked list is made up of nodes, each node contains data and Pointers, WHEN I write this problem, in the list of only append and child nodes, toString view linked list and other methods.

  • In the code, using es6 modularization, I used WebPack to compile the code, let it run, and used Webpack-dev-server to let it visualize the whole learning process in the browser. My webpack.config.js configuration is as follows:
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html'// Configure the output file name and path template:'src/index.html'// Config file template}),], devServer: {port:'1314'}},Copy the code
  • Reference to paopao2 code to achieve a separated linked list

    The main idea is divided into two linked lists less than a certain number, separate operation, and finally synthesize linked list ideas, code implementation is relatively simple.

import LinkedList from './LinkedList'; // Implement a linked list const partition = (head, x) => {// divide into 2 nodesletCur = head, next, preHead, // less than preTail, afterHead, // greater than or equal to afterTail;if (head === null)
    return null;
  while(cur) {// next = cur.next; cur.next = null; // Get rid of the old relationshipif (cur.val < x) {
      if(! PreHead) {// Empty list preHead = cur; preTail = cur; }else{ preTail.next = cur; preTail = cur; }}else {
      if(! AfterHead) {afterHead = cur; afterTail = cur; }else {
        afterTail.next = cur;
        afterTail = cur;
      }
    }
    cur = next;
  } 
  if (preTail) {
    preTail.next = afterHead;
    return preHead;
  } else {
    return afterHead;
  }
  
}
const list = new LinkedList();
// 1->4->3->2->5->2 
list
  .append(1)
  .append(4)
  .append(3)
  .append(2)
  .append(5)
  .append(2)
// console.log(list.toString());
const newHead = partition(list.head, 3);
console.log(newHead);
let curNode = newHead;
while(curNode) {
  console.log(curNode.val);
  curNode = curNode.next;
}
Copy the code

conclusion

Above, I will mainly share with you my way of learning Leetcode and the open source project referred to. I hope it will be helpful to you. Thank you. code