MicroSoft
文章平均质量分 73
dongbeier
这个作者很懒,什么都没留下…
展开
-
116 Populating Next Right Pointers in Each Node
Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right node...原创 2018-06-14 06:38:26 · 138 阅读 · 0 评论 -
8 String to Integer (atoi)
Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this ...原创 2018-06-14 06:30:25 · 79 阅读 · 0 评论 -
238 Product of Array Except Self
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Output: [24,1...原创 2018-05-13 07:29:01 · 84 阅读 · 0 评论 -
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 if the ...原创 2018-06-14 06:30:12 · 145 阅读 · 0 评论 -
33 Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in t...原创 2018-05-13 07:29:45 · 77 阅读 · 0 评论 -
5 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.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:...原创 2018-06-14 06:29:59 · 83 阅读 · 0 评论 -
24 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only constant...原创 2018-06-14 06:30:07 · 86 阅读 · 0 评论 -
208 Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.这道题让我们实现一个重要但又有些复杂的数据结构-字典树, 又称前缀树或单词查找树,例如,一个保存了8个键的trie结构,"A", "...原创 2018-06-14 06:30:03 · 117 阅读 · 0 评论 -
168 Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB...原创 2018-06-14 06:29:52 · 95 阅读 · 0 评论 -
153 Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume no duplicat...原创 2018-06-14 06:29:47 · 74 阅读 · 0 评论 -
20 Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brack...原创 2018-06-14 06:30:29 · 113 阅读 · 0 评论 -
2 Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-06-14 06:30:33 · 78 阅读 · 0 评论 -
117 Populating Next Right Pointers in Each Node II
Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right node...原创 2018-06-14 06:38:19 · 115 阅读 · 0 评论 -
48 Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix directl...原创 2018-06-14 06:38:13 · 82 阅读 · 0 评论 -
151 Reverse Words in a String
Given an input string, reverse the string word by word.Example: Input: "the sky is blue",Output: "blue is sky the".Note:A word is defined as a sequence of non-space characters.Input string may contai...原创 2018-06-14 06:38:09 · 139 阅读 · 0 评论 -
141 Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?使用Set做法. O(n) space:/** * Definition for singly-linked list. * class ListNode { * int...原创 2018-06-14 06:38:05 · 88 阅读 · 0 评论 -
13 Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...原创 2018-06-14 06:32:11 · 78 阅读 · 0 评论 -
75 Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the inte...原创 2018-06-14 06:32:01 · 87 阅读 · 0 评论 -
121 Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), d...原创 2018-06-14 06:31:58 · 72 阅读 · 0 评论 -
73 Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]]Example ...原创 2018-06-14 06:31:54 · 121 阅读 · 0 评论 -
268 Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,1]Output: 8N...原创 2018-06-14 06:30:40 · 74 阅读 · 0 评论 -
98 Validate Binary Search Tree
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 node contains only nodes with keys less than the node's key.The right ...原创 2018-06-14 06:29:43 · 87 阅读 · 0 评论 -
4 Median of Two Sorted Arrays
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 complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2...原创 2018-06-14 06:29:39 · 96 阅读 · 0 评论 -
237 Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with ...原创 2018-06-14 06:29:32 · 76 阅读 · 0 评论 -
102 Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \...原创 2018-05-13 07:31:17 · 100 阅读 · 0 评论 -
47 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]递归DFS扩展节点,每次从小到大,选一个没有被用光的元素,直到所...原创 2018-06-14 06:25:37 · 118 阅读 · 0 评论 -
365 Water and Jug Problem
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two j...原创 2018-06-14 06:25:31 · 87 阅读 · 0 评论 -
213 House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is ...原创 2018-06-14 06:25:26 · 131 阅读 · 0 评论 -
672 Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of sta...原创 2018-06-14 06:25:14 · 209 阅读 · 0 评论 -
591 Tag Validator
Given a string representing a code snippet, you need to implement a tag validator to parse the code and return whether it is valid. A code snippet is valid if all the following rules hold:The code mus...原创 2018-06-14 06:24:49 · 226 阅读 · 0 评论 -
722 Remove Comments
Given a C++ program, remove comments from it. The program source is an array where source[i] is the i-th line of the source code. This represents the result of splitting the original source code strin...原创 2018-06-14 06:25:04 · 202 阅读 · 0 评论 -
513 Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3 / / \ 4 5 ...原创 2018-06-14 06:25:09 · 99 阅读 · 0 评论 -
191 Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).Example 1:Input: 11Output: 3Explanation: Integer 11 has binary representa...原创 2018-06-14 06:27:55 · 92 阅读 · 0 评论 -
174 Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially pos...原创 2018-06-14 06:28:00 · 245 阅读 · 0 评论 -
160 Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ c...原创 2018-06-14 06:29:28 · 91 阅读 · 0 评论 -
173 Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and has...原创 2018-06-14 06:29:24 · 64 阅读 · 0 评论 -
285 Inorder Successor in BST
Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null. 这道题让我们求二叉搜索树的某个节点的中序后继节点,那么...原创 2018-06-14 06:29:17 · 168 阅读 · 0 评论 -
55 Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you ar...原创 2018-06-14 06:25:56 · 75 阅读 · 0 评论 -
452 Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordin...原创 2018-06-14 06:25:52 · 87 阅读 · 0 评论 -
333 Largest BST Subtree
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.Note:A subtree must include all of its descendants.Her...原创 2018-06-14 06:25:48 · 149 阅读 · 0 评论