leetcode Missing Number

Use the sumup of all the number subtract the sum of them.

int missingNumber(int* nums, int numsSize) {
long long int sum = 0;
for(int i = 0;i < numsSize;++ i) sum += nums[i];
return (numsSize + 1) * numsSize / 2 - sum;

leetcode Ugly Number II

This is not a difficult one.
Basic idea is, assum that we have a self-sorted queue. Everytime, we choose the smallest one n, insert 2*n , 3*n , 5*n into this queue. After n times, we will get the n-th Ugly number.
The time will be $O(nlogn)$. Do we have a better way? The answer is YES!

Tower of Hanoi

I’m so tierd and upset today. I want to practise a DFS, BFS and a recursive.
I find it’s easy for me to write a BFS or DFS. So I just wrote a Hanoi tower.
It’s a very basic algorithm. This is my code.

Heap insertion and deletion in C

It’s a program about basic insertion and deletion of a heap.(include heapify)
It’s insertion and deletion time complexity is $O(logn)$
Once I finished this code and began to run, it runs without bug.
Which means I finished this code Without any debuging~
I spent half an hour to write this program
This is a small top heap

Very basic hashtable

This is only a very basic hashtable
I use half an hour to write it(such a easy program takes me so long)
The hash function of string is simply sum all of the charactors up and times a prime number
This program is used to calculate how many times of every input string appears
The structure of this hashtable is like this:


I finished merge sort, heap sort. If I leave quicksort along, he must be very upset.
So… Quicksort, here we go.
Quicksort, not only quick, but also … quick.
The first quick means it runs quickly, the second one is it writes short and quick.
Here is my code

void quicksort(int *line, int from, int to){
if(from == to) return ;
int pivot = line[to - 1],now = from;
for(int i = from;i < to - 1;++ i)
if(line[i] < pivot) swap(line[i],line[now ++]);
swap(line[now],line[to - 1]);
quicksort(line, from, now);
quicksort(line, now + 1, to);


Heap sort? What? You choose this?
I don’t know why I choose heapsort. Maybe I just want to practise how to write something about heap.
If you want to know how it works, go to Wiki, or Baidu, or Google.
It’s just my implement.
We can see that heapsort may have more actions compared with quicksort. But heapsort is always $O(n * log_2n)$, while quicksort may cause a $O(n^2)$. Especially I’m always in bad luck. T.T
Here is my code:

Distance Calculator GUI

Everyone want to calculate the distance between his Goddess and himself. This calculator can meet your need!
This is the first time that I use Python to generate a calculator.

This program is used to get a GUI software for a edit distance calculator

Sort List use merge sort

Why you are so sad? Just because you can not sort a list?
If someone want you to sort a list, what will you do? quicksort? No.
Merge sort is your choose! How much do you think a merge sort will cost? $O(n^2)$ ? $O(n^3)$ ? No!
It ONLY take you $O(n * log_2n)$! Buy now, you can get a input part freely!