- 博客(409)
- 收藏
- 关注
转载 Morris 二叉搜索树遍历模板
Morris Traversal是o(n)时间复杂度,o(1)空间复杂度的BST遍历方法。下面是Morris Traversal模板:public void morrisInorderTraverse() { Node cur = root; while (cur != null) { if (cur.left == null) { ...
2019-09-08 09:58:42 254
原创 常用Docker命令
镜像类docker build --rm=true . 构建镜像docker pull ${IMAGE} 安装镜像docker images 显示已经安装的镜像docker images --no-trunc 显示已经安装镜像的详细内容docker rmi ${IMAGE_ID} 删除指定镜像docker rmi $(docker images | grep “^” | awk “{print $...
2018-03-29 07:53:22 341 1
原创 ROS配置python开发环境(pycharm)问题汇总
1. pycharm 无法使用ros的module问题,如rospy。在开启pycharm的时候使用命令 "sudo bash -i /home/shouyi/pycharm/bin/pycharm.sh"。这里加 -i 是为了可以使用ros环境的module。(待续……)...
2018-03-29 07:50:03 2295 6
原创 617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge them into a new binary tre
2017-08-18 06:09:07 290
原创 335. Self Crossing
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south, x[3] metres to the east and s
2017-08-18 03:00:52 463
原创 384. Shuffle an Array
Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3.int[] nums = {1,2,3};Solution solution = new Solution(nums);// Shuffle the array [1,2,3] and return
2017-08-16 04:59:40 231
原创 149. 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.这道题应该注意只要是在一条直线上就算。第一反应是用HashMap来存斜率,但是如果double精确到小数点后好多位之后就趋于相等,key值就相等了,所以一般不要用double作key。这里可以用
2017-08-12 04:46:12 299
原创 540. Single Element in a Sorted Array
Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once. Example 1:Input:
2017-08-09 13:06:54 269
原创 二叉树遍历模板(前序,中序,后序)
Pre Order Traversepublic List preorderTraversal(TreeNode root) { List result = new ArrayList<>(); Deque stack = new ArrayDeque<>(); TreeNode p = root; while(!stack.isEmpty() || p !
2017-07-26 05:04:30 665
原创 A clean DP solution which generalizes to k transactions
有一个解决股票买卖问题(Best Time to Buy and Sell Stock)的模板,可以推广到买卖n次。class Solution {public: int maxProfit(vector &prices) { // f[k, ii] represents the max profit up until prices[ii] (Note: NOT en
2017-07-24 13:02:36 298
原创 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Have you met t
2017-07-02 01:40:57 321
原创 Subarray Sum Closest
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.Have you met this question in a real interview? YesExample
2017-07-01 02:27:31 371
原创 518. Coin Change 2
You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite numbe
2017-06-25 07:28:06 1755
原创 85. Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1
2017-06-24 13:20:37 245
原创 480. Sliding Window Median
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median
2017-06-23 16:23:16 320
原创 239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window
2017-06-23 14:05:15 299
原创 84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o
2017-06-23 13:19:31 311
原创 212. Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor
2017-06-23 01:58:09 306
原创 295. Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median
2017-06-22 01:24:03 234
原创 407. Trapping Rain Water II
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.Note:Both m and n are l
2017-06-21 08:28:51 256
原创 42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1
2017-06-20 06:21:39 266
原创 388. Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner:The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:dir subdir1 subdir2 file.extThe direc
2017-06-19 14:10:37 242
原创 146. LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key i
2017-06-19 12:38:16 402
原创 560. Subarray Sum Equals K
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2Note:
2017-06-17 13:34:13 389
原创 398. Random Pick Index
Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.Note:The array size c
2017-06-17 13:16:05 255
原创 382. Linked List Random Node
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the linked list is extremely large and i
2017-06-17 13:01:00 234
原创 307. Range Sum Query - Mutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Examp
2017-06-17 09:00:34 297
原创 604. Design Compressed String Iterator
Design and implement a data structure for a compressed string iterator. It should support the following operations: next and hasNext.The given compressed string will be in the form of each letter
2017-06-17 02:05:11 507
原创 353. Design Snake Game
Design a Snake game that is played on a device with screen size = width x height. Play the game online if you are not familiar with the game.The snake is initially positioned at the top left cor
2017-06-16 16:41:06 636
原创 379. Design Phone Directory
Design a Phone Directory which supports the following operations:get: Provide a number which is not assigned to anyone.check: Check if a number is available or not.release: Recycle or release
2017-06-16 14:54:07 374
原创 348. Design Tic-Tac-Toe
Design a Tic-tac-toe game that is played between two players on a n x n grid.You may assume the following rules:A move is guaranteed to be valid and is placed on an empty block.Once a winning
2017-06-16 11:43:13 334
原创 362. Design Hit Counter
Design a hit counter which counts the number of hits received in the past 5 minutes.Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are being mad
2017-06-16 09:16:45 345
原创 251. Flatten 2D Vector
Implement an iterator to flatten a 2d vector.For example,Given 2d vector = [ [1,2], [3], [4,5,6]]By calling next repeatedly until hasNext returns false, the order of elements r
2017-06-16 03:18:53 310
原创 284. Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek()operation -- it essentially peek() at the element that will be r
2017-06-16 01:48:05 320
原创 281. Zigzag Iterator
Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 = [3, 4, 5, 6]By calling next repeatedly until hasNext
2017-06-15 15:29:30 316
原创 444. Sequence Reconstruction
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The org sequence is a permutation of the integers from 1 to n, with 1 ≤ n ≤ 104. Reconstruction me
2017-06-15 12:16:15 987
原创 399. Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the ans
2017-06-15 06:43:26 319
原创 310. Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called mini
2017-06-15 03:15:04 271
原创 286. Walls and Gates
You are given a m x n 2D grid initialized with these three possible values.-1 - A wall or an obstacle.0 - A gate.INF - Infinity means an empty room. We use the value 231 - 1 = 2147483647 to repr
2017-06-15 01:53:46 333
原创 130. Surrounded Regions
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,
2017-06-14 12:30:41 248
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人