123
返回列表 发新帖
楼主: winry
跳转到指定楼层
上一主题 下一主题
收起左侧

工科女外表弱不经风内心强大励志呼口号劳资一定要找到工作留美的刷题记录

🔗
calalia 2015-10-13 05:08:55 | 只看该作者
全局:
CS女汉子~~虽然DS的申请都没音讯了 但是没事俺也想刷刷easy
回复

使用道具 举报

🔗
 楼主| winry 2015-10-13 17:01:06 | 只看该作者
全局:
https://leetcode.com/problems/re ... -from-sorted-array/   (array:easy)public class Solution {
    public int removeDuplicates(int[] nums) {
        int index=1;
        if(nums.length==0) return 0;
        if(nums.length==1) return 1;
        for(int i=0;i<nums.length-1;i++)
        {
            if(nums[i]!=nums[i+1])
            {
                nums[index++]=nums[i+1];
            }
            else
            {
                continue;
            }
        }
        return index;
    }
}

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
https://leetcode.com/problems/move-zeroes/   (array:easy)
public class Solution {
    public void moveZeroes(int[] nums) {
        int index=0;
        int len=nums.length;
        for(int i=0;i<len;i++)
        {
            if(nums[i]!=0)
            {
                nums[index++]=nums[i];
            }
        }
        for(int i=index;i<len;i++)
        {
            nums[i]=0;
        }
    }
}

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
https://leetcode.com/problems/merge-two-sorted-lists/   (Linked List:easy)
解法一:递归
/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
     if (l1 == null || l2 == null) {
            return l1 == null ? l2 : l1;
        }
        ListNode head = null;
        if (l1.val < l2.val) {
            head = l1;
            head.next = mergeTwoLists(l1.next, l2);
        } else {
            head = l2;
            head.next = mergeTwoLists(l1, l2.next);
        }
        return head;
    }
}


————————————————————————————————————————————————————————————————————————
解法二:
/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
    if(l1==null||l2==null)
    {
        return l1==null ? l2 : l1 ;
    }
    ListNode node = null;
    ListNode head = null;
    if(l1.val<l2.val)
    {
        head=l1;
        l1=l1.next;
    }
    else{
        head=l2;
        l2=l2.next;
    }
    node=head;
    while(l1!=null&&l2!=null)
    {
        if(l1.val<l2.val)
        {
            node.next=l1;
            l1=l1.next;
        }
        else{
            node.next=l2;
            l2=l2.next;
        }
        node=node.next;
    }
    if(l1==null) node.next=l2;
    if(l2==null) node.next=l1;
    return head;
}
}





回复

使用道具 举报

🔗
 楼主| winry 2015-10-13 17:02:07 | 只看该作者
全局:
calalia 发表于 2015-10-13 05:08
CS女汉子~~虽然DS的申请都没音讯了 但是没事俺也想刷刷easy

加油 一起刷起!
回复

使用道具 举报

🔗
 楼主| winry 2015-10-15 17:16:41 | 只看该作者
全局:
https://leetcode.com/problems/reverse-linked-list/     (Linked List:easy)链表好烦,头疼中
/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
    public ListNode reverseList(ListNode head) {
        if(head==null || head.next==null) return head;  

        ListNode pre = head;  
        ListNode p = head.next;  
        pre.next = null;  
        ListNode nxt;  
        while(p!=null) {  
            nxt = p.next;  
            p.next = pre;  
            pre = p;  
            p = nxt;  
        }  
        return pre;  
    }  
}  

回复

使用道具 举报

🔗
然陌语 2015-10-15 17:27:41 | 只看该作者
本楼:
全局:
说的好!!!!
回复

使用道具 举报

🔗
lili2014 2016-1-14 18:18:21 | 只看该作者
全局:
楼主好赞,上周有去亚马逊面试(散招实习),估计挂了~不知道之后好可不可以投~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表