Questions

What is the difference between the array length and its capacity

public class Solution {
        public ListNode removeNthFromEnd(ListNode head, int n) {
            ListNode before = head;
            ListNode end = head;
            //????why cannot construct a new listnode();
            //ListNode end = new ListNode();

why? 有人写

Stack<Character> stack = new Stack<Character>();

有人写

Stack stack = new Stack();



When does j expire?

for(j=1;j<s.length();j++){
            if(s.charAt(j)==s.charAt(j-1))
                num++;
            else{
                t=t.append(num);
                t=t.append(s.charAt(j-1));
                num=1;
            }
        }
        t=t.append(num);
        t=t.append(s.charAt(j-1));

copy value是否只适用于primitive type

38 count and say

public class Solution {
    public String countAndSay(int n) {
        if (n == 0 || n == 1) {
            return "" + n;
        }
        StringBuilder s2 = new StringBuilder("1");
        for (int i = 1; i < n; i++) {
            StringBuilder s1 = s2;
            s2 = s2.delete(0, s2.length());
            int count = 1;
            for (int j = 1; j < s1.length(); j++) {
                if (s1.charAt(j) == s1.charAt(j-1)) {
                    count++;
                } else {
                    s2 = s2.append(count);
                    s2 = s2.append(s1.charAt(j-1));
                    count = 1;
                }
            }
            s2 = s2.append(count);
            s2 = s2.append(s1.charAt(s1.length() - 1));
        }
        return s2.toString();
    }

what is wront with this??? }