`
betakoli
  • 浏览: 168735 次
社区版块
存档分类
最新评论
文章列表

链表的归并排序

class Node { int num; Node next; Node(int num) { this.num = num; } } public class TestA { public static void main(String[] args) { int a[] = { 3, 1, 6, 8, 4, 2, 8, 4 }; TestA tA = new TestA(); Node node = tA.create(7, a); Node node1 = tA.split(node); while (node1 != ...
1.     关于hibernate缓存的问题: 1.1.1.         基本的缓存原理 Hibernate缓存分为二级,第一级存放于session中称为一级缓存,默认带有且不能卸载。
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The s ...
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c) The solution set must not contain duplicate t ...
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) ar ...
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a time Each intermediate word must exist in the dictionary For example, Given:start = "hit"end = "cog"dict ...
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", "cats", "and", "sand&quo ...
Word Maze 是一个网络小游戏,你需要找到以字母标注的食物,但要求以给定单词字母的顺序吃掉。如上图,假设给定单词if,你必须先吃掉i然后才能吃掉f。     但现在你的任务可没有这么简单,你现在处于一个迷宫Maze(n×m的矩阵)当中,里面到处都是以字母标注的食物,但你只能吃掉能连成给定单词W的食物。 如下图,指定W为“SOLO”,则在地图中红色标注了单词“SOLO”。    注意区分英文字母大小写,你只能上下左右行走。 输入: 5 5 SOLO CPUCY EKLQH CRSOL EKLQO PGRBC 输出: YES   这道题目比较 ...
Word Break Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because "leetcode" can be seg ...
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example,Given {1,2,3,4}, reorder it to {1,4,2,3}.   题目的思路是,找到中间节点,将后半截链表反转。将前半截链表和翻转后的链表进行遍历交叉组合。 /**
Sort List sort a linked list in O(n log n) time using constant space complexity. 排序,时间复杂度为n(logn),   我们知道堆排序,归并排序即使在最坏的情况下时间复杂度为n(logn)。   这里使用链表的归并排序实现。   /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * ...
Max Points on a Line  Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 一个平面中有很多点,找出能在同一条直线上的最多的点 思路:遍历所有的点,在每次遍历中再依次遍历其他与该点没有计算过斜率的点,计算斜率,并统计数量。   /** * Definition for a point. * class Point { * int x; * int y; * Point() ...
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". click to show clarification. 给定一个字符串,将字符串中的英文单词反转过来: 实现一:以单词作为整体的方式,实现 public class Solution { public String reverseWords(String s) { s=s. ...
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 题意:如何判断链表是否有环 这是一个经典的问题,后面还有追问: 如果有环,计算环的长度? 找到碰撞点的位置?   首先,如何找环,设计两个指针,分别从链表的头节点开始,走一部和走两步,循环一直到走两步指针为空(说明没有环)或者两指针相遇(说明有环)为止。 主要代码: /** * Definition for singly-linked list. * ...
spring默认情况下管理的类是singleton模式,如果在类A中注入了B类,但是B类属于non-singleton,每次使用A的时候都需要初始化B类。 spring提供了ApplicationContextAware,让A意识到spring容器的存在,并且在调用B类的时候通过容器去询问B类是否是单例模式,需要重新初始化?  // a class that uses a stateful Command-style class to perform some processing package fiona.apple; // Spring-API imports impor ...
Global site tag (gtag.js) - Google Analytics