Tuesday, September 27, 2016

Android Studio Project: Experiment Manager

Experiment Manager, focusing on biological research.

This application makes experiments arrangement as its main function, supplemented by columns such as biological information and data searching. What’s more, it can save your experiments experiences. With this application, you will be able to do every experiment more methodically. When not doing an experiment, you can either know about biological related news or seeking for the latest information from professional websites. How flexible and convenient!

Experiment Manager


Click To Download On Amazon Appstore

Project site

Thursday, September 22, 2016

Android Studio Project: Outside News Updated

The new version of Outside News repairs a bug that the application couldn't exit from MainActivity directly.

Installation package

Project site

Thursday, September 8, 2016

LeetCode Online Judge-10. Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be:
bool isMatch(const char *s, const char *p)

Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true

Tell you a secret. I initially added only 1 line and it was accepted!
Well, that's "return s.matches(p);" in Java. Ha-ha!

OK, I did know this answer was not expected for training.
So here comes my recursive program.

//Java Program: Regular Expression Matching
public class Solution {
    public boolean isMatch(String s, String p) {

if (p.length()==0) {
if (s.length()==0) {
return true;
} else {
return false;
}
}

if (p.length()==1) {
if (s.length()==1&&(p.charAt(0)=='.'||s.charAt(0)==p.charAt(0))) {
return true;
}
return false;
}

if (s.length()>0&&p.length()>0&&(p.charAt(p.length()-1)=='.'||s.charAt(s.length()-1)==p.charAt(p.length()-1))) {
return isMatch(s.substring(0, s.length()-1), p.substring(0, p.length()-1));
}

if (p.length()>1&&p.charAt(p.length()-1)=='*') {
if (s.length()==0) {
return isMatch(s, p.substring(0, p.length()-2));
}
if (p.charAt(p.length()-2)!='.'&&s.charAt(s.length()-1)!=p.charAt(p.length()-2)) {
return isMatch(s, p.substring(0, p.length()-2));
}
if (isMatch(s, p.substring(0, p.length()-2))) {
return true;
}
if (isMatch(s.substring(0, s.length()-1), p.substring(0, p.length()-2))) {
return true;
}
return isMatch(s.substring(0, s.length()-1), p);
}

return false;

    }
}

Friday, September 2, 2016

LeetCode Online Judge-9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
Acturally, I used extra space when solving this problem. But this answer was accepted. And I went to see the discussions about this problem. It seems impossible to solve the problem without extra space.
However, it's quite easy to solve this problem without the limit of extra space. Maybe there will be a perfect answer without extra space. Why not think about it?
OK, here comes my solution with extra space.

//Java Program: Palindrome Number
public class Solution {
    public boolean isPalindrome(int x) {
        String s = ((Integer)x).toString();
        for(int i=0;i<s.length()/2;++i) {
         if (s.charAt(i)!=s.charAt(s.length()-1-i)) {
         return false;
         }
        }
        return true;
    }
}