Showing posts with label LaTex. Show all posts
Showing posts with label LaTex. Show all posts

Wednesday, December 31, 2014

Leetcode 80: Remove Duplicates from Sorted Array II

Problem:
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A = [1,1,1,2,2,3],
Your function should return length = 5, and A is now [1,1,2,2,3]
Analysis:
As duplicates are allowed at most twice, the first thought is to compare the current element with the
previous two elements. However, we must remember that the array is a sorted array, which implies
that if current element equals to the second previous element, it must equal to the first previous one.
If not equal, current element can be added to the list.

Code:

public class Solution {
    public int removeDuplicates(int[] A) {
       if(A.length<=2){
           return A.length;
       }
       int tail=2;
       for(int i=2;i<A.length;i++){
           if(A[i]!=A[tail-2]){
               A[tail++]=A[i];
           }
       }
       return tail;
    }
}

Monday, June 4, 2012

"Error : could not start the command" in TexMakerX

If you meet the error "Error : could not start the command" while executing TexMakerX commands in Win7 X64, it is probably due to environment path of LaTex compiler.  The following steps may help you solve this error.
  1. Make sure that you did install a LaTex compiler like MiKTeX. You know,  TexMakerX is just a editor of latex input, not a compiler.
  2. Locate the bin directory in the installation directory of the LaTex compiler.
  3. Add the directory of bin like "d:\Program Files (x86)\MiKTeX 2.9\miktex\bin" to the environment paths of windows. 
    • Right click computer in start menu, choose properties.
    • Find the "Advanced system settings" in upper left corner.
    • Click the button "Environment Variables".
    • Find the row of variable path in the group of "System Variables" and add bin path like";d:\Program Files (x86)\MiKTeX 2.9\miktex\bin"to the tail. Remember to add a semicolon to separate different path. 

Then, try it again...