`
文章列表
Given a N*N matrix contains lakes, each lake is represented by an elevation. The water in each lake can flow to its neighbours which has lower or equal elevations. Suppose the left and top side of the matrix is surrounded by Pacific, the right and bottom is Atlantic. Please write a function and re ...
Given a binary search tree and an integer K, find K-th smallest element in BST.For example: Input: 2 / \ 1 3 K = 2Output:2Note: Your solution musb be in-place
Given a binary tree, traverse it vertically. For example: 5 / \ 2 7 / \ / \ 1 3 6 8 \ \ 4 9   Should return as: [ [1], [2], [5, 3, 6], [4, 7], [8], [9] ]   Solution 1: 递归前序遍历,直接用vector或者ArrayList来保存结果。 /* struct TreeNode ...
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.   int romanToInt(string s) { unordered_map<char,int> map = {{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}}; int num = 0; for(int i=0; i<s.size(); ...
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.   public String intToRoman(int num) { StringBuilder sb = new StringBuilder(); Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "I" ...
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8   public ListN ...
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 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 horizontally or vertically neighboring. The same letter cell may not be used more than once in ...
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline formed by these build ...
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusi ...
Given a 2D matrix, print all elements of the given matrix in diagonal order. For example, consider the following 5 X 4 input matrix. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Diagonal printing of the above matrix is ...
Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most? Example For interval list [[1,10],[2,3],[5,8],[4,7]], return 3 Note If landing and flying happens at the same time, we consider landing should happen at first. 将所有区间的 ...
Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number. Example Given [-3, 1, 2, -3, 4], return [0, 2] or [1, 3]. Note There is at least one subarray that it's sum equals to zero
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. Example Given the array [2,3,1,2,4,3] and s = 7, the subarray [4,3] has the minimal length under the problem constraint. Chall ...
给一个树root的pointer,树包含多个分支,树结构要自己创造。求一条最长路径。例如(括号对应上面node)树:                  2      |            |            |                |     5            7          3                 6(|       | )( | )( | )        (|       |)  6       3        2         4              5       8                     |         ...
Global site tag (gtag.js) - Google Analytics