ckitt's Notes


  • Home

  • Archives

  • Tags

LeetCode 66 Plus One

Posted on 2016-03-13   |  

Question

[LeetCode 66] Given a non-negative number represented as an array of digits, plus one to the number.

Submission

Java Submission
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Solution {
public int[] plusOne(int[] digits) {
boolean allNine = true;

for (int i = 0; i < digits.length; i++) {
if (digits[i] != 9) {
allNine = false;
}
}

if (allNine) {
int[] newNumber = new int[digits.length+1];
newNumber[0] = 1;
return newNumber;
} else {
for (int i = digits.length - 1; i >= 0; i--) {
if (digits[i] == 9) {
digits[i] = 0;
} else {
digits[i]++;
break;
}
}
return digits;
}
}
}

LeetCode 133 Clone Graph

Posted on 2016-03-12   |  

Question

[LeetCode 133] Clone an undirected graph.

Submission

Java Submission
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Definition for undirected graph.
* class UndirectedGraphNode {
* int label;
* List<UndirectedGraphNode> neighbors;
* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
* };
*/

public class Solution {
public Map<Integer, UndirectedGraphNode> nodes = new HashMap<Integer, UndirectedGraphNode>();

public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
if (node == null) {
return null;
}

if (nodes.containsKey(node.label)) {
return nodes.get(node.label);
}

UndirectedGraphNode cloneNode = new UndirectedGraphNode(node.label);
nodes.put(node.label, cloneNode);

for (UndirectedGraphNode neigblor: node.neighbors) {
UndirectedGraphNode cloneNeigblor = cloneGraph(neigblor);
cloneNode.neighbors.add(cloneNeigblor);
}

return cloneNode;
}
}

Setting up a blog with Hexo using GitHub Pages

Posted on 2016-03-12   |  

Introduction

This articles will show you how to setup a blog with Hexo, a blog framework built with Node.js, and publish it to GitHub.

Setting up Hexo and host it in GitHub

Dependencies

  1. Node.js https://nodejs.org
  2. Git Bash https://git-scm.com or others git tools available online

Install Hexo

  1. Install Hexo, run the following command in git-bash

    1
    2
    cd /your hexo directory/
    npm install hexo-cli -g

    make sure you included the npm directory in your PATH variable

    ;C:\Program Files\nodejs\node_modules\npm
    
  2. Once Hexo is installed, initialize Hexo

    1
    $ hexo init

    following files will be created

    .
    ├── _config.yml
    ├── package.json
    ├── scaffolds
    ├── source
    |   ├── _drafts
    |   └── _posts
    └── themes
    
  3. The site is then ready for deploy

Start Hexo in local environment

  • After installing Hexo, you might want to have a look of the website, you can run the following command

    1
    $ hexo server
  • Server will be started and it can be accessed by using http://localhost:4000

Generate static files

  • Generating static files with the following command
    1
    $ hexo generate

Deploy to GitHub Pages

  1. create a new github repository with name (you github username).github.io

  2. update global setting of hexo _config.yml

    1
    2
    3
    deploy:
    type: git
    repo: link to your github repository
  3. Then run the following command to deploy your Hexo site to gitHub

    1
    $ hexo deploy
  4. you will be able you visit the site with http://(you github username).github.io


Usage

Adding a new post

  1. Run the following command

    1
    $ hexo new post "My First Blog Post"
  2. start blogging by editing the newly created markdown file in <Hexo directory>/source/_posts

  3. regenerate the static files

  4. deploy the changes to remote server if needed

Deleting an existing post

  1. remove the unwanted post in <Hexo directory>/source/_posts

References

  1. Hexo http://hexo.io
  2. GitHub Pages https://pages.github.com
123
ckitt

ckitt

13 posts
6 tags
GitHub
© 2016 ckitt
Powered by Hexo
Theme - NexT.Mist