2019年3月6日

二维数组中的查找

摘要: Array基本操作: 1.声明:int[] arr; int arr[]=new int[3]; 2.初始化:int arr[]=new int[]{1,2,3,4,5}; 二维初始化: int[][] arr = new int[][]{{1,2}, {2, 3}, {4, 5}};(https: 阅读全文

posted @ 2019-03-06 14:30 q2013 阅读(105) 评论(0) 推荐(0) 编辑

从尾到头打印链表

摘要: 这道题考察的其实是arraylist 的用法(′д` )…然而全忘了 ArrayList 是一个数组队列,相当于 动态数组,它的容量能动态增长。 构造函数:ArrayList()ArrayList(int capacity) // capacity是ArrayList的默认容量大小。当由于增加数据导 阅读全文

posted @ 2019-03-06 09:13 q2013 阅读(91) 评论(0) 推荐(0) 编辑

2019年3月5日

删除链表中重复的结点

摘要: public class Solution { public ListNode deleteDuplication(ListNode pHead) { if(pHead == null || pHead.next == null) return pHead;//特殊情况 else { ListNod 阅读全文

posted @ 2019-03-05 13:26 q2013 阅读(115) 评论(0) 推荐(0) 编辑

2019年3月4日

两个链表的第一个公共结点

摘要: 我的思路:先求长度,每个长度长的遍历一次长度短的, 后看评论理解题意:第一个公共结点后面的都相同,所以可以先走长-短的差再比较。 public class Solution { public ListNode FindFirstCommonNode(ListNode pHead1, ListNode 阅读全文

posted @ 2019-03-04 21:12 q2013 阅读(117) 评论(0) 推荐(0) 编辑

合并两个排序的链表

摘要: public class Solution { public ListNode Merge(ListNode list1,ListNode list2) { if(list1 == null && list2 == null) return null; else{ ListNode list3 = 阅读全文

posted @ 2019-03-04 20:03 q2013 阅读(80) 评论(0) 推荐(0) 编辑

链表中倒数第k个结点

摘要: 思路:两个指针,一个先指到k,两个一起往后移,一个指到尾时另一个在倒数k处。 public class Solution { public ListNode FindKthToTail(ListNode head,int k) { ListNode p = head; ListNode q = he 阅读全文

posted @ 2019-03-04 17:16 q2013 阅读(63) 评论(0) 推荐(0) 编辑

反转链表

摘要: public class Solution { public ListNode ReverseList(ListNode head) { if(head == null || head.next == null)//考虑特殊情况 return head; ListNode pre = null; / 阅读全文

posted @ 2019-03-04 16:29 q2013 阅读(95) 评论(0) 推荐(0) 编辑

2019年1月16日

堆栈

摘要: 判断输入的序列是否可以从确定栈中得到Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to 阅读全文

posted @ 2019-01-16 17:15 q2013 阅读(102) 评论(0) 推荐(0) 编辑

2019年1月15日

一元多项式的乘法和加法

摘要: //一元多项式的乘法和加法 import java.util.*; class Node{ int index; int coef; Node next = null; public Node(int coef, int index) { this.index = index; this.coef 阅读全文

posted @ 2019-01-15 20:08 q2013 阅读(191) 评论(0) 推荐(0) 编辑

2019年1月13日

单链表每隔k反转

摘要: 初步版本,没有考虑特殊情况。 import java.util.*; class Node{ int data; Node next; public Node(int data) { this.data = data; }} class Link{ Node head = null; Node tm 阅读全文

posted @ 2019-01-13 20:08 q2013 阅读(641) 评论(0) 推荐(0) 编辑

导航