12 2017 档案

摘要:[抄题]: 给出一个链表,每个节点包含一个额外增加的随机指针可以指向链表中的任何节点或空的节点。 返回一个深拷贝的链表。 [思维问题]: [一句话思路]: 完完全全地复制,否则不好操作。 1->1`->2->2`->3->3`->4->4` 紧随其后地复制,再拆开 [输入量]:空: 正常情况:特大: 阅读全文
posted @ 2017-12-31 22:44 苗妙苗 阅读(240) 评论(0) 推荐(0)
摘要:方法一:堆 [抄题]: 合并k个排序链表,并且返回合并后的排序链表。尝试分析和描述其复杂度。 [思维问题]: [一句话思路]: 堆的基本操作 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: [总结]: 用比较函数+堆的做法 两 阅读全文
posted @ 2017-12-31 11:43 苗妙苗 阅读(308) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个链表,旋转链表,使得每个节点向右移动k个位置,其中k是一个非负数 样例 给出链表1->2->3->4->5->null和k=2 返回4->5->1->2->3->null 给出链表1->2->3->4->5->null和k=2 返回4->5->1->2->3->null [思维问 阅读全文
posted @ 2017-12-30 21:54 苗妙苗 阅读(298) 评论(0) 推荐(0)
摘要:1 [抄题]: 给定一个链表,判断它是否有环。 [思维问题]: 反而不知道没有环怎么写了:快指针fast(奇数个元素)或fast.next(偶数个元素) == null [一句话思路]: 快指针走2步,慢指针走1步。 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不 阅读全文
posted @ 2017-12-30 11:09 苗妙苗 阅读(135) 评论(0) 推荐(0)
摘要:[抄题]: Given a linked list, remove the nth node from the end of list and return its head. Given linked list: 1->2->3->4->5, and n = 2. After removing t 阅读全文
posted @ 2017-12-27 22:46 苗妙苗 阅读(185) 评论(0) 推荐(0)
摘要:链表排序 · Sort List [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: quick sort 整体-局部(先找大小值,再局部递归) 里面不稳定 最坏n2, 最好 平均 nlgn 数组 阅读全文
posted @ 2017-12-26 16:19 苗妙苗 阅读(466) 评论(0) 推荐(0)
摘要:[抄题]: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserv 阅读全文
posted @ 2017-12-25 22:35 苗妙苗 阅读(136) 评论(0) 推荐(0)
摘要:全部 [抄题]: Reverse a singly linked list. [思维问题]: 以为要用dummy node [一句话思路]: 直接全部转过来就行了,用dummy node反而多余 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 阅读全文
posted @ 2017-12-24 10:48 苗妙苗 阅读(183) 评论(0) 推荐(0)
摘要:不留: [抄题]: 给定一个排序链表,删除所有重复的元素只留下原链表中没有重复的元素。 [思维问题]: 给出 1->2->3->3->4->4->5->null,返回 1->2->5->null 给出 1->1->1->2->3->null,返回 2->3->null [一句话思路]: dummy 阅读全文
posted @ 2017-12-22 22:03 苗妙苗 阅读(2363) 评论(0) 推荐(0)
摘要:2组: [抄题]: 给出一个整数数组 nums 和一个整数 k。划分数组(即移动数组 nums 中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置 i,满足 nums[i] 大于等于 k。 [思维问题]: 想不到两个小人的partiti 阅读全文
posted @ 2017-12-19 15:37 苗妙苗 阅读(341) 评论(0) 推荐(0)
摘要:4sum [抄题]: [思维问题]: [一句话思路]: [输入量特别大怎么办]: [画图]: [一刷]: if (i > 0 && nums[i] == nums[i - 1]) , 之前的已经操作过, continue;退出 [总结]: 先排序,然后一吃通吃 [复杂度]: [英文数据结构,为什么不 阅读全文
posted @ 2017-12-17 20:46 苗妙苗 阅读(259) 评论(0) 推荐(0)
摘要:[抄题]: 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 s 阅读全文
posted @ 2017-12-15 10:40 苗妙苗 阅读(161) 评论(0) 推荐(0)
摘要:[抄题]: 设计b并实现一个 TwoSum 类。他需要支持以下操作:add 和 find。add -把这个数添加到内部的数据结构。find -是否存在任意一对数字之和等于这个值 [思维问题]: 不知道为什么要用到ArrayList。 [一句话思路]: 就是写两个方法就行了。 [画图]: [一刷]: 阅读全文
posted @ 2017-12-14 16:46 苗妙苗 阅读(311) 评论(0) 推荐(0)
摘要:原版 sorted [抄题]: [思维问题]: 存sum - nums[i](补集),若出现第二次则调出 [一句话思路]: hashmap中,重要的数值当做key,角标当做value. [画图]: [一刷]: [总结]: [复杂度]:n/n [英文数据结构,为什么不用别的数据结构]: 2根指针 n^ 阅读全文
posted @ 2017-12-13 16:24 苗妙苗 阅读(264) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个整数数组,找到和为零的子数组。你的代码应该返回满足要求的子数组的起始位置和结束位置.给出 [-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. [思维问题]: 老是想着数组双重循环用枚举法,想不到任何别的数据结构。 用hashmap的好处:一个数据结构可以包 阅读全文
posted @ 2017-12-12 09:49 苗妙苗 阅读(306) 评论(0) 推荐(0)
摘要:一 [抄题]: If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the 阅读全文
posted @ 2017-12-10 16:07 苗妙苗 阅读(222) 评论(0) 推荐(0)
摘要:[抄题]: 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 阅读全文
posted @ 2017-12-10 08:59 苗妙苗 阅读(232) 评论(0) 推荐(0)
摘要:http://zhangnai.xin/2016/09/20/LeetCode-Framework/ 目录结构: LeetCode ——项目名称,方便Eclipse内置Git对代码进行管理和多终端同步 pid1 ——题目包,每个题目封装在一个单独的包中,包名用LeetCode题目编号表示 Solut 阅读全文
posted @ 2017-12-09 16:31 苗妙苗 阅读(5869) 评论(1) 推荐(0)
摘要:Array Data Structure ‘Recent Articles’ on Arrays Topic : Introduction Array Rotations Arrangement Rearrangement Order Statistics Range Queries Searchi 阅读全文
posted @ 2017-12-09 09:02 苗妙苗 阅读(706) 评论(0) 推荐(0)
摘要:[抄题]: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complex 阅读全文
posted @ 2017-12-08 12:30 苗妙苗 阅读(151) 评论(0) 推荐(0)
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam 阅读全文
posted @ 2017-12-07 11:08 苗妙苗 阅读(193) 评论(0) 推荐(0)