• Home
  • About
    • Lei's Blog photo

      Lei's Blog

      I'm a programmer based in Toronto, Canada, currently engaging in web development.

    • Learn More
    • Email
    • Facebook
    • LinkedIn
    • Github
  • Posts
  • Tags
    • ALL TAGs
    • .net 1
    • ajax 2
    • Algorithm 1
    • Amazon 1
    • async 1
    • autoprefixer 1
    • AWS 1
    • c# 2
    • CMS 1
    • css 3
    • Domain 1
    • ElasticBeanstalk 1
    • example 4
    • GithubPage 5
    • Google 1
    • GoogleCharts 1
    • html 1
    • install 1
    • interview 1
    • Java 1
    • javascript 5
    • javaScript 1
    • jekyll 4
    • jquery 2
    • js 6
    • jsx 1
    • KNN 1
    • liquid 1
    • Netlify 1
    • plugin 1
    • Project 1
    • react 1
    • regex 1
    • script 1
    • scrollnav 1
    • scrollspy 1
    • setInterval 1
    • sort 1
    • studynotes 2
    • submit 1
    • tag 1
    • TOC 1
    • XSL 1
  • Projects

LeetCode 笔记

136

异或表达式

相同为0, 不同相加?

class="highlight">
1
2
1^1 = 0
1^2 = 3

104

二叉树的本质是递归

206

返置链表

指针问题

class="highlight">
1
2
3
4
5
6
7
8
9
10
11
12
public class Solution {
    public ListNode ReverseList(ListNode head) {
        ListNode rList = null;
        while(head!=null){
            ListNode temp = rList;
            rList = head;
            head = head.next; //这行与下行对调顺序结果不同, 因为指针
            rList.next = temp;         
        }
        return rList;
    }
}

169

数组里数元素个数问题用dictionary 解决

242

  • string to char array
  • sort array
  • array to string
class="highlight">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Solution {
    public bool IsAnagram(string s, string t) {
        if(s.Length != t.Length) return false;
        //string to char array
        char[] sArray = s.ToCharArray();
        char[] tArray = t.ToCharArray();
        //sort
        Array.Sort(sArray);
        Array.Sort(tArray);
        //array to string and compare
        string sNew = String.Join("",sArray);
        string tNew = String.Join("",tArray);
        if(sNew == tNew) return true;
        return false;
    }
}

108

平衡二叉树: 一直对半分数组

202

用HashSet解决重复问题