Skip to content

Instantly share code, notes, and snippets.

View zwfang's full-sized avatar
📝
Know that it is you who will get you where you want to go, no one else.

zwfang

📝
Know that it is you who will get you where you want to go, no one else.
  • Remote
View GitHub Profile
@zwfang
zwfang / knight_tour.c
Created November 21, 2018 10:20
骑士周游问题,深度优先遍历+递归,
/************************************************************/
/** 马踏棋盘算法(骑士周游问题) **/
/************************************************************/
#include <stdio.h>
#include <time.h>
#define X 8
#define Y 8
@zwfang
zwfang / combine.py
Last active December 7, 2018 07:12
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
#!/usr/bin/env python3
import copy
class Solution:
def __init__(self):
self.res = []
def combine(self, n, k):
"""
@zwfang
zwfang / word_search.py
Last active December 7, 2018 08:41
word search
#!/usr/bin/env python3
"""
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
Example:
board =
[
@zwfang
zwfang / hanio.py
Created December 7, 2018 14:25
hanio
#!/usr/bin/env python3
import sys
def move(n, x, y, z):
if n == 1:
print("%s --> %s" % (x, z))
else:
move(n-1, x, z, y)
print("%s --> %s" % (x, z))
@zwfang
zwfang / fib.go
Created December 7, 2018 14:25
fib
package main
import "fmt"
func fib() func() int64 {
var i int64
var j int64 = 1
return func() int64 {
i, j = j, i+j
return i
@zwfang
zwfang / reverseNodeKGroup.c
Created December 7, 2018 14:37
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
//
// main.c
// reverse node in k group
//
// Created by fzw on 10/12/18.
// Copyright © 2018 n. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@zwfang
zwfang / rotateList.c
Created December 7, 2018 14:38
Given a linked list, rotate the list to the right by k places, where k is non-negative.
//
// main.c
// RotateList
//
// Created by fzw on 10/7/18.
// Copyright © 2018 n. All rights reserved.
//
#include <stdio.h>
@zwfang
zwfang / addBinary.c
Created December 7, 2018 14:39
Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0.
//
// main.c
// addBinary
//
// Created by fzw on 10/7/18.
// Copyright © 2018 n. All rights reserved.
//
#include <stdio.h>
#include <string.h>
@zwfang
zwfang / MergeTwoSortedArray.c
Created December 7, 2018 14:41
first c algorithm. help me open computer gate.
//
// main.c
// MergeTwoSortedArray
//
// Created by fzw on 9/26/18.
// Copyright © 2018 n. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@zwfang
zwfang / narcissisticNumber.c
Created December 7, 2018 14:42
水仙花数
//
// main.c
// narcissisticNumber
//
// Created by fzw on 10/7/18.
// Copyright © 2018 n. All rights reserved.
//
#include <stdio.h>