[Java] 支付寶(alipay) 境內支付API介接與實作




閱讀更多[Java] 支付寶(alipay) 境內支付API介接與實作

(Visited 2,923 times, 4 visits today)

How to find the longest possible quasi-constant subsequence of array?

This is my task2 challenge. I’ve tried to solve this question, but my result wasn’t good. Although there was no error after testing, I only got 33% score.?

The summary of question shows as below:

I was given a non-empty unsorted array such as: A = [6, 10, 6, 9, 7, 8]. The amplitude of a subsequence of array A is the difference between the largest and the smallest element in this subsequence. The amplitude of the empty subsequence is assumed to be 0.

These are some of the subsequences of array A and their amplitudes:
[6, 6, 7] has amplitude 1;
[6, 10, 6, 9, 7, 8] has amplitude 4;
[6, 6, 7, 8] has amplitude 2.

If this subsequence of array is called quasi-constant, it means its amplitude does not exceed 1. In the example above, subsequence [6, 6, 7] is the longest possible quasi-constant subsequence of array A.

Now, you are expected to provide a method that takes in an array and returns the maximum number of quasi-constant subsequence of array. In above example, the function should return 3.

閱讀更多How to find the longest possible quasi-constant subsequence of array?

(Visited 6,794 times, 1 visits today)

My first Codility test experience

Last week, I received an email from a recruiter who asked me to do Codility assessment. I had to answer three questions within 245 minutes. Although I’ve heard about Codility, this was my first Codility test experience. To be honest, it was really difficult to me.

These questions were not easy to understand, so it took me some time to understand each question. Then I tried to answer the questions by Java or Python programming language. Even though I eventually found the solutions and summited the answers, my average score was not good enough. When I finished this assessment, I was very disappointed with myself. I even thought whether I should keep a programmer job.???

It seems that more and more companies like to use Codility assessments to evaluate developers, but I don’t think it is the best way to test a programmer’s coding/programmer abilities.

閱讀更多My first Codility test experience

(Visited 1,609 times, 1 visits today)

[Java] How to use SSL and Google Protobuf on Netty?

Recently, I tried to use Netty framework dealing with message transferring between different virtual machines which are including one server and some clients. Meanwhile, I need to use SSL mutual authentication and Google protobuf when these VMs do communication cross the internet. Although I had already encountered the term “SSL” a lot of times, I soon realised that I had never fully understood how it really works and how it could be implemented in Java.

I would like to share my experience about implementing SSL plus Google Protobuf on Netty. But I wouldn’t exactly tell you what Netty, SSL and Google protobuf are.

閱讀更多[Java] How to use SSL and Google Protobuf on Netty?

(Visited 1,000 times, 1 visits today)

[Java] Using Jackson and Jersey to parse a JSON file to an List

This example will show you how to convert a JSON file into a JSON String, then parse it to ArrayList. Assuming I hava a timeZoneList.json file:

    "zoneID": "Pacific/Kwajalein",
    "offset": -12,
    "zoneName": "(GMT -12:00) Eniwetok, Kwajalein"
    "zoneID": "Pacific/Midway",
    "offset": -11,
    "zoneName": "(GMT -11:00) Midway Island, Samoa"
    "zoneID": "US/Hawaii",
    "offset": -10,
    "zoneName": "(GMT -10:00) Hawaii"
  .....(more timezone objects)

閱讀更多[Java] Using Jackson and Jersey to parse a JSON file to an List

(Visited 117 times, 1 visits today)

[Java] Converting between Decimal and Binary with Recursion

I am trying to write a program that will convert a binary number into its equivalent decimal number using recursion. Recursion has always been a confusing topic in programming. I write a simple code to implement convert from decimal to binary and from binary to decimal.

閱讀更多[Java] Converting between Decimal and Binary with Recursion

(Visited 24 times, 1 visits today)

[Java] Quick Sort Algorithm

Quick sort is a very fast sort algorithm, which it’s used “divide and conquer strategy” to sort the data. On the average and best case, it has O(n log n) time complexity, on worst case, it has O(n^2) time complexity. And it is unstable sorting.

閱讀更多[Java] Quick Sort Algorithm

(Visited 14 times, 1 visits today)

[Java] Selection Sort Algorithm

Time complexity of Selection Sort Algorithm in best case , worst case and average are all O(n^2) and need O(1) extra space. Selection sort can be implemented in stable sort or not.

閱讀更多[Java] Selection Sort Algorithm

(Visited 22 times, 1 visits today)

[Java] 100 – The 3n + 1 problem

題目連結:UVa Online Judge


if(n%2 == 1)
    int number = (3 * n) + 1;
    n = n/2;

閱讀更多[Java] 100 – The 3n + 1 problem

(Visited 21 times, 1 visits today)

[Java] Binary search algorithm

Binary search algorithm time complexity is O(log2(n)), and this algorithm requires that source array is sorted in order to work correct.

Algorithm is quite simple. It can be done either recursively or iteratively:

1.get the middle element;
2.if the middle element equals to the searched value, the algorithm stops;
3.otherwise, two cases are possible:
   (1)searched value is less, than the middle element. In this case, go to the step 1 for the part of the array, before middle element.
   (2)searched value is greater, than the middle element. In this case, go to the step 1 for the part of the array, after middle element.

閱讀更多[Java] Binary search algorithm

(Visited 25 times, 1 visits today)