03 2018 档案
摘要:Given a target integer T, a non-negative integer K and an integer array A sorted in ascending order, find the K closest numbers to T in A. Assumptions
阅读全文
摘要:做图的时候千万要小心,如果 当前点的邻居已经访问过了, 则不要再放入queue 中 否则一定死循环 所以图的 bfs 一定要 用一个字典来mark 访问过的点
阅读全文
摘要:time o(n)--每一个点都要遍历 space o(1)
阅读全文
摘要:Find the target key K in the given binary search tree, return the node that contains the key if K is found, otherwise return null. 对于 tail recursion 的
阅读全文
摘要:Implement an iterative, in-order traversal of a given binary tree, return the list of keys of each node in the tree as it is in-order traversed. Examp
阅读全文
摘要:Implement an iterative, pre-order traversal of a given binary tree, return the list of keys of each node in the tree as it is pre-order traversed. Exa
阅读全文
摘要:Insert a new element at a specific index in the given linked list. The index is 0 based, and if the index is out of the list's scope, you do not need
阅读全文
摘要:Given a matrix of size N x M. For each row the elements are sorted in ascending order, and for each column the elements are also sorted in ascending o
阅读全文
摘要:Find the K smallest numbers in an unsorted integer array A. The returned numbers should be in ascending order. Assumptions A is not nullK is >= 0 and
阅读全文
摘要:https://leetcode.com/problems/binary-tree-level-order-traversal/description/ Given a binary tree, return the level order traversal of its nodes' value
阅读全文
摘要:Given a sorted array and a target value, return the index where it would be if it were inserted in order. AssumptionsIf there are multiple elements wi
阅读全文
摘要:Given a target integer T and an integer array A sorted in ascending order, Find the total number of occurrences of T in A. Examples A = {1, 2, 3, 4, 5
阅读全文
摘要:Delete the node at the given index for the given linked list. Examples [1, 2, 3], delete at 1 --> [1, 3] [1, 2, 3], delete at 4 --> [1, 2, 3] [1, 2, 3
阅读全文
摘要:Return the number of nodes in the linked list. Examples L = null, return 0L = 1 -> null, return 1L = 1 -> 2 -> null, return 2
阅读全文
摘要:Find the height of binary tree. Examples: 5 / \ 3 8 / \ \ 1 4 11 The height of above binary tree is 3. 1 public class Solution { 2 ...
阅读全文
摘要:will do it later
阅读全文
摘要:DFS recursive: since this is called tail recursion, you are recommended to do it in interative: time: O(h) space: O(1) Interative:
阅读全文
摘要:1 /* 2 note, here we use the concept of circle array: so head and tail could be in the middle of it. 3 head index is the 1st real value; tail index is the 1st available slot 4 h t 5 ...
阅读全文
摘要:1 /* H tail 2 (last in) 1->2->3->4 (1st in) 3 o/H 4 first-out 5 6 */ 7 public class UseLinkedListImpleme...
阅读全文
摘要:1 public class UseLinkedListImplementStack { 2 private ListNode head; 3 private int length ; 4 public UseLinkedListImplementStack() { 5 this.head = null ; 6 this.len...
阅读全文
摘要:http://www.lintcode.com/en/problem/search-range-in-binary-search-tree/ Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Searc
阅读全文
摘要:时空复杂度:
阅读全文
摘要:https://leetcode.com/problems/intersection-of-two-linked-lists/description/ Write a program to find the node at which the intersection of two singly l
阅读全文
摘要:Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted list. The given node can be any single node in the l...
阅读全文
摘要:https://leetcode.com/problems/insertion-sort-list/description/Sort a linked list using insertion sort.insertion sort 默认第一位已经SORT 好了, 取出下一位,然后从头比较。 一点一点向后面挪动time complexity: o(n^2)space complexity: o(1...
阅读全文
摘要:https://www.youtube.com/watch?v=kU9M51eKSX8 插入排序 插入排序(Insertion Sort)的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一个新的、个数加一的有序数据,算法适用于少量数据的排序,时间复杂度为O(n^2)。是稳定的排序方法。
阅读全文
摘要:https://leetcode.com/problems/search-for-a-range/description/ Given an array of integers sorted in ascending order, find the starting and ending posit
阅读全文
摘要:这是 Implement Deque Using Two Stacks 的升华版本, 存一半有效的把时间复杂度最坏情况降低到O(N/2) 这里最好,最坏的情况正好和 Implement Deque Using Two Stacks 相反。 最好的情况: 雨露均沾 最坏的情况:专宠一人
阅读全文
摘要:个人感想: 这并没有优化太多,因为SHUFFLE 把整个都搬过去另一边, WORST CASE 的情况是 “雨露均沾”: 当你SHUFFLE 从左边到右边的时候, 马上REMOVELEFT, 那你就得马上再从右边SHUFFLE 到左边。。。 和捉迷藏一样,每次POP 都是O(N) 所以是很糟糕的一个
阅读全文
摘要:1 public class ListNode { 2 public int val ; 3 public ListNode next; 4 public ListNode(int val) { 5 this.val = val; 6 this.next = null ; 7 } 8 9 } 1 publi...
阅读全文
摘要:没有难度,但是需要理解:这其实是说TARGET 和 MID 的关系
阅读全文
摘要:https://leetcode.com/problems/find-peak-element/description/A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return...
阅读全文
摘要:如果有特别多重复的数进来的情况,并且是一整块一样的数进来,那是可以被优化的。 1111111 222222 -1-1-1-1 111111 -2-2-2-2-2 33333 如果 进来的数字是交叉的,则优化空间有限: 1212121212
阅读全文
摘要:这种写法 stack 1 stack 2 同步操作,stack 1 进来一个 stack2 也要进来一个。如果有特别多重复的数进来的情况,并且是一整块一样的数进来,那是可以被优化的。 1111111 222222 -1-1-1-1 111111 -2-2-2-2-2 33333 如果 进来的数字是交
阅读全文
摘要:重要假设,必须要时刻知道queue 的 size 如果不知道,则做不了。
阅读全文
摘要:https://leetcode.com/problems/implement-stack-using-queues/description/Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on t...
阅读全文
摘要:worse case出现在 所有元素都在stack1 中,第一次 从 stack2 中 pop
阅读全文
摘要:TEST:
阅读全文
摘要:注意针对 rotated sorted array 去重复的固定套路 参考 33,81,153, 154
阅读全文
摘要:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/description/Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How...
阅读全文
摘要:https://leetcode.com/problems/search-insert-position/description/Given a sorted array and a target value, return the index if the target is found.If not, return the index where it would be if it were ...
阅读全文
摘要:https://leetcode.com/problems/first-bad-version/description/ You are given an API bool isBadVersion(version) which will return whether version is bad.
阅读全文
摘要:Given a integer dictionary A of unknown size, where the numbers in the dictionary are sorted in ascending order, determine if a given target integer T
阅读全文
摘要:https://leetcode.com/problems/merge-sorted-array/description/Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space...
阅读全文
摘要:https://leetcode.com/problems/move-zeroes/description/Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, ...
阅读全文
摘要:https://leetcode.com/problems/sort-colors/description/Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent,with the colors in the order re...
阅读全文
摘要:以下内容,拷贝自 http://www.ruanyifeng.com/blog/2013/11/stack.html 学习编程的时候,经常会看到stack这个词,它的中文名字叫做"栈"。 理解这个概念,对于理解程序的运行至关重要。容易混淆的是,这个词其实有三种含义,适用于不同的场合,必须加以区分。
阅读全文
摘要:以下内容拷贝自 http://www.ruanyifeng.com/blog/2018/02/nginx-docker.html 春节前,我看到 Nginx 加入了 HTTP/2 的 server push 功能,就很想试一下。 正好这些天,我在学习 Docker,就想到可以用 Nginx 容器。万
阅读全文
摘要:以下内容摘自 http://www.ruanyifeng.com/blog/2018/02/docker-wordpress-tutorial.html Docker 是一个容器工具,提供虚拟环境。很多人认为,它改变了我们对软件的认识。 站在 Docker 的角度,软件就是容器的组合:业务逻辑容器、
阅读全文
摘要:以下内容,拷贝自 http://www.ruanyifeng.com/blog/2018/02/docker-wordpress-tutorial.html 2013年发布至今, Docker 一直广受瞩目,被认为可能会改变软件行业。 但是,许多人并不清楚 Docker 到底是什么,要解决什么问题,
阅读全文
摘要:以下内容,拷贝自 http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html 今天中午,我突然想搞清楚 Unicode 和 UTF-8 之间的关系,就开始查资料。 这个问题比我想象的复杂,午饭后一直看到晚上9点,才算初步搞清
阅读全文
摘要:When you start JVM you define how much RAM it can use use for processing. JVM divides this into certain memory locations for its processing purpose, t
阅读全文
摘要:
阅读全文
摘要:heapify unsorted array: n*logn -> o(n): 最贵的 o(logn) 操作集中在少数几个node 上 但heapify 并不是 sort, 左右并没有排序,如果需要排序的话,需要先heapify 然后再 一个一个的poll 时间复杂度是 on + onlogn =
阅读全文
摘要:这道题首先要明确题目背景 二叉搜索树。也正是因为是二叉搜索树,所以我们可以利用二叉搜索树从小到大排好序的特性来做。 对于一个root和另外两个Node来说,它们的值会有以下几种情况: 1. root.val < p.val && root.val < q.val 此时,两个node的值都比root大
阅读全文
摘要:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/description/Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, ...
阅读全文
摘要:https://leetcode.com/problems/validate-binary-search-tree/description/Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a ...
阅读全文
摘要:https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/description/Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of node...
阅读全文
摘要:https://leetcode.com/problems/path-sum-ii/description/Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and ...
阅读全文
浙公网安备 33010602011771号