Launched My Website Today!

Finally, I can launch this website today after trying multiple approaches. (I will write another post about the process.) So as the first post, it is essential for me to be very clear why I started this website. Only after that, I can continually write articles.

Why do I start this website?

It’s a portfolio of my school/side projects or other competitions I participate in.

Writing can help me to keep track of my thoughts on two of my favorite subjects: mindfulness and productivity.

It’s a simple approach to share my status and ideas without touching the overwhelming social media websites.

I hope my articles will also help others in some way.

2018-01-06, Seattle

完成了Leetcode网站Array中的

完成了Leetcode网站Array中的Easy部分

对于这些题目的总结:

– 如果需要频繁比较数据,可以考虑将原数据排序后再进行算法操作

– 求和、求差操作不依赖数据顺序,有时候很好用 268. Missing Number

– 要特别注意数组边界数据的处理(26. Remove Duplicates from Sorted Array

– 顺序操作、控制范围和求和是Array(数组)常规操作,但可能低效。如果善于运用高级一些的数据结构,如HashSet(217. Contains Duplicate)HashMap等,可以显著提高效率

– Java库中提供了很多例如排序查找的功能,善于利用事半功倍,例如:

  • Collections.rotate(List<?> list, distance) 189. Rotate Array (但是类型之间的转换可能会牺牲一些效率)

  • Arrays.binarySearch(int nums[], int target),如果这个target不存在,假设它应该插入的位置是pos,那么这个函数就返回-pos-1; 35. Search Insert Position

After years of worki

After years of working in the IT area, I step back to learn some basic skills like programming. These days I am learning Java in MOOC websites like coursera/edx/xuetangx, and will learn Python in a few days later on.

Java 8 has a lot of built in data structure and algorithms like sorting. And today, I did a simple measure on the merge sort(Arrays.sort()) and parallel sort(Arrays.parallelSort()). Here is the time needed in mill-seconds based on the number of the element (double[]) in this array, from which we can see:

– The performance of merge sort on small data volume (<100,000) is stable and even better than the parallel sort.

– The benefit of parallel sort shows when the volume exceeds 500,000

– The parallel sort is as twice better as the merge sort if the records is more than 5,000,000

– The parallel sort takes more heap space because Java will throw ‘out of memory space’ exception when the record number reach ‘100000000’. While the merge sort works in this case and take 12594 mills.

I am leaving Oracle.

Today is my last day in OARDC after 4 yearsworking here. 

 

Thanks to my coworkers Seal Liu, ChadChang, Kenny Yuan, Rohan Kumar, Xiangyi Zheng, Baohua Shan, Ying Chen, Shi Li,Yong Wu, etc. in Siebel Remote and Contact Center team. And others colleaguesin QA team, Release team and DMG team etc. You give me great help and support,and complete me on my profession.

Special thanks to my managers Kuang-YangHuang, who gave me a lot of support and opportunities; Chi Vong and SherlyZhao, who brought me in the Siebel team; Donghai Wang, who was my first managerand taught me with patience.

 

I cannot forget all the good time weperform together for the Annual dinners and we play together around thefoosball table and the activities in KuanGou.

 

You as well as the experience working with you inOracle is a life-time treasure. I have nothing but sincere thanks and bestwishes to you all. 

对任意输入的正整数N,编写C程序求N!的尾部连续0的个数

一个算法题:对任意输入的正整数N,编写C程序求N!的尾部连续0的个数,并指出计算复杂度。如:18!=6402373705728000,尾部连续0的个数是3。 分析:要出现末尾的0,必须乘数因子中有2和5,所以应该选取因子2和5数目较少的那个,因为阶乘是连续的,因子中第一个出现的是2而且出现2的速度远远大于5。所以,只要统计因子中5的数目,然后将这些数目加起来即可。 实现: import java.lang.*; import java.math.*; public class Factorial { public static void main(String[] args) { System.out.println(getTailZeros(Integer.parseInt(args[0])) + " " + factorial(BigInteger.valueOf(Integer.parseInt(args[0])))); } public static BigInteger factorial (BigInteger bigInteger) { BigInteger fact = BigInteger.ONE; for( BigInteger i = BigInteger.ONE;i.compareTo(bigInteger)<=0;i=i.add(BigInteger.ONE)) fact = fact.multiply(i); return fact; } //Count the amount of factor 5 for an int public static int countFactor5(int i) { if (i%5!=0) return 0; else return countFactor5(i/5)+1; } //Sum al the amount of factor 5 for all the factors public static int getTailZeros(int i) { int zeros = 0; for (int c=1; c <= i; c++) { zeros += countFactor5(c); } return zeros; } } 测试:编译 javac Factorial.java; 运行 java Factorial 100 结果: 24 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000