dental

today my sister and I went to a dental appointment to clean our teeth. l was up first. When I first got in the dental chair the dentist gave me sunglasses that were so big that even my dad could were them. when my turn was over it was my sister’s turn.I thought that my sister was not going to cry but she did. I thought that she wasn’t going to cry because I told her about the balls that you could pick at the end.Anyway, when we were done picking the balls we went to QFC then we went home to bake muffins

YUM!                                                                                                                   YUM!

Really!

Today I was asking my dad to play with me. I said daddy play with me. But he said Sophie can you write in your dairy? then I said DADDY!! Then he said if you write in your dairy I will let you type it on your mom’s keyboard REALLY!! Then I rushed to get started.

snow!

today i was looking out the window . suddently i spang up it’s snowing mommy! it’s snowing daddy! i told them . then i rushed to the window it is snowing bigger! i said.i ran to get them. but when i got there it was so small that you could hardly see it. oh! I said and I walked to write in diary. But when I looked again it was snowing so big.that I could not wait to go to play.

Palindrome Linked List

public class Solution {
    public boolean isPalindrome(ListNode head) {
         if(head==null||head.next==null)return true;
        ListNode newhead=head;
        int len=0;
        while(newhead!=null){
            newhead=newhead.next;
            len++;
        }
       
        int i=0;
        while(i<len/2){
            ListNode temp=head.next;
            head.next=newhead;
            newhead=head;
            head=temp;
            i++;
        }
        if(len%2==1)head=head.next;
        while(head!=null){
            if(head.val!=newhead.val)return false;
            head=head.next;
            newhead=newhead.next;
        }
        return true;
    }
}

Largest Number

public class Solution {
    public String largestNumber(int[] nums){
        Integer[]in=new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            in[i]=nums[i];
        }
        Arrays.sort(in,new Compare());
        StringBuilder sb = new StringBuilder();
        for (int i = nums.length - 1; i >= 0; i--) {
            sb.append(in[i]);
        }
        if(sb.charAt(0) == '0'){
            return "0";
        }
        return sb.toString();
    }

    public class Compare implements Comparator<Integer> {
        public int compare(Integer arg0, Integer arg1) {
            String s1 = arg0.toString();
            String s2 = arg1.toString() + arg1.toString();
            while (s1.length() < s2.length()) {
                s1 += s1;
            }
            while (s2.length() < s1.length()) {
                s2 += s2;
            }
            return s1.compareTo(s2);
        }

    }
}

Rectangle Area

public class Solution {
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int total=(C-A)*(D-B)+(G-E)*(H-F);
        return total-getIntersect(A,C,E,G)*getIntersect(B,D,F,H);
    }
    public int getIntersect(int x1,int x2, int x3, int x4){
        if(x2<x3||x1>x4)return 0;
        return Math.abs(Math.max(x1,x3)-Math.min(x2,x4));
    }
}

Summary Ranges

public class Solution {
    public List<String> summaryRanges(int[] nums) {
        int i=0;
        List<String> result=new ArrayList<String>();
        while(i<nums.length){
            int start =nums[i];
            int end=nums[i];
            while(i<nums.length-1&&nums[i]+1==nums[i+1]){
                end++;
                i++;
            }
            if(start==end){
                result.add(start+"");
            }else{
                result.add(start+"->"+end);
            }
            i++;
        }
        return result;
    }
}

Remove Duplicates from Sorted List II

public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        int c;
        ListNode newhead=head;
        ListNode last=head;
        boolean needMoveHead=true;
       
        while(head!=null&&head.next!=null){
            c=0;
            while(head.next!=null&&head.val==head.next.val){            
                c++;
                head=head.next;
            }
           
            if(c>=1){
                // need to cut it
                if(needMoveHead){
                    // it's the first element, move the new head
                    newhead=head.next;
                }
                // cut it
                last.next=head.next;
               
            }else{
                // doesn't need to cut it. No need to move new head now
                needMoveHead=false;
                last=head;
            }
            head=head.next;
        }
       
        return newhead;
    }
}

Pocket Mine 5 hidden achievement

Let’s Do This – 20 pts (Hidden)
Shuffle 3 mythical cards in one shuffle

Dream Run – 20 pts (Hidden)
Shuffle 3 5-stars cards in one shuffle

Treasure Hunter – 15 pts (Hidden)
Get 3 treasure-related powerups in one shuffle

Gold Digger – 15 pts (Hidden)
Get 3 gold-related powerups in one shuffle

Is This Real Life!? (Hidden)
Shuffle 3 mythical 5-stars cards in one shuffle

Leetcode: Subsets II (also work with no dups)

public class Solution {
    public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] S) {
        // Sort first
        Arrays.sort(S);

        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        // create a boolean array to track progress
        boolean[] b = new boolean[S.length];
        while (true) {
            // output a good subset
            result.add(getR(b, S));
            int i = 0;
            while (i < S.length) {
                if (b[i] == false) {
                    // if current position is false, just market it true and break;
                    b[i] = true;
                    break;
                } else {
                    // see if next position has same character
                    int k=i+1;
                    while(k<S.length&&S[k]==S[i]&&b[k]==true){
                        k++;
                    }
                    if(k==S.length){
                        // reach the end, break;
                        i=k;
                        break;
                    }
                    if(S[k]==S[i]){
                        // found a dup character that has false, just mark it true and break;
                        b[k]=true;
                        break;
                    }else{
                        // all same dup is true, mark everything false and go on
                        while(i<k){
                            b[i] = false;
                            i++;
                        }
                    }
                }
            }
            if (i == S.length)
                break;
        }
        return result;
    }
   
    public ArrayList<Integer> getR(boolean[]b,int[]S) {
        ArrayList<Integer> r=new ArrayList<Integer>();
        for(int i=0;i<b.length;i++){
            if(b[i])r.add(S[i]);
        }
        return r;
    }
}