489. Convert Array List to Linked List Convert an array list to a linked list. Example Example 1: Input: [1,2,3,4], Output: 1->2->3->4->null 定义两空指针,一个用来返回整个链表,一个用来创建新节点. 新创建的节点作为当前p的next节点,再把p重新指向新创建的节点. public ListNode toLinkedList(List<In…
Java – How to convert Array to Stream 1. Object Arrayspackage com.mkyong.java8; import java.util.Arrays;import java.util.stream.Stream; public class TestJava8 { public static void main(String[] args) { String[] array = {"a", "b", "…
206. Reverse Linked List(Easy) 题目地址https://leetcode.com/problems/reverse-linked-list/ Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed eith…
160. Intersection of Two Linked Lists(Easy) 题目地址https://leetcode.com/problems/intersection-of-two-linked-lists/ Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists:…
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 有序数组变二叉平衡搜索树,不难,递归就行.每次先序建立根节点(取最中间的数),然后用子区间划分左右子树. 一次就AC了 注意:new 结构体的时候对于 struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x)…
leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has th…
一,前言 ​ 先来一张Collection集合图. ​ 今天分享一些关于Collection集合中的List,讲真的集合这东西在网上真是老生常谈了.说实话连本人都觉得腻了(哈哈),但是话又说回来,整个集合体系对于我们实际开发来说是非常重要的,所以还是有必要系统总结下. ​ 不过在此之前先说说两种数据结构,链表和红黑树. 1.1,链表 ​ 链表:linked list,由一系列结点node(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每个结点包括两个部分:一个是存储数据元素的数据域,…
Array List样例: /** * 增加泛型 * 自动增加数组容量 * 增加set.get方法:增加数组边界的检查 * 增加remove方法 */package cn.study.lu.four; public class MyArrayList <E>{ private Object[] elementData; private int size; private static final int DEFALT_CAPACITY = 10; public MyArrayList() {…
977. Squares of a Sorted Array (Easy)# Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. Example 1: Input: [-4,-1,0,3,10] Output: [0,1,9,16,100] Example 2:…
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 begin to intersect at node c1. Notes: If the two linked lists have…