每日算法练习(2020-1-27)

public int removeElement(int[] nums, int val) {
        if(nums==null||nums.length==0)
        {
            return 0;
        }
        int j=0;
        for(int i=0;i<nums.length;i++)
        {
            if(nums[i]!=val)
            {
                nums[j]=nums[i];
                j++;
            }
        }
        return j;
    }

      public class ListNode {
          int val;
          ListNode next;
          ListNode(int x) { val = x; }
     }

    class Solution {
        public ListNode swapPairs(ListNode head) {
            if(head==null||head.next==null)
            {
                return head;
            }
            ListNode next=head.next;
            head.next=swapPairs(next.next);
            next.next=head;
            return head;
        }
    }
原文地址:https://www.cnblogs.com/qyx66/p/12237291.html