![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
面试题
文章平均质量分 59
happyxuma1991
这个作者很懒,什么都没留下…
展开
-
蛇形矩阵C++
输出以上螺旋矩阵#include #include using namespace std;// 输出螺旋矩阵void Matrix(){ const int size = 10; // 矩阵大小 int matrix[size][size] = { 0 }; int row = 0; int col = 0; int start = 1; // 起始值 int原创 2016-04-05 21:43:20 · 4294 阅读 · 0 评论 -
leetcode——116—— Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2016-05-01 14:11:47 · 186 阅读 · 0 评论 -
leetcode——117——Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note: You may only use constant ext原创 2016-05-01 14:58:29 · 231 阅读 · 0 评论 -
leetcode——120——Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,原创 2016-05-01 15:14:48 · 228 阅读 · 0 评论 -
leetcode——129——Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the total sum原创 2016-05-01 18:42:50 · 258 阅读 · 0 评论 -
leetcode——130——Surrounded Regions
Given a 2D board containing 'X' and '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,X X X XX O O XX X原创 2016-04-21 14:20:45 · 278 阅读 · 0 评论 -
leetcode——338——Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2016-04-21 19:01:43 · 236 阅读 · 0 评论 -
leetcode——238——Product of Array Except Self
Given an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(n).原创 2016-04-22 10:49:52 · 192 阅读 · 0 评论 -
leetcode——341——Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Given the list [原创 2016-04-22 11:53:38 · 286 阅读 · 0 评论 -
leetcode——344——Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh". class Solution {public: string reverseString(string s) {原创 2016-04-22 13:49:47 · 343 阅读 · 0 评论 -
leetcode——114—— Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:1 \ 2 \原创 2016-05-01 11:57:04 · 179 阅读 · 0 评论 -
leetcode——92——Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note:Given m, n satisfy the fol原创 2016-04-30 17:41:48 · 167 阅读 · 0 评论 -
leetcode——188——Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not原创 2016-04-30 17:23:42 · 259 阅读 · 0 评论 -
leetcode——113——Path Sum II
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 sum = 22, 5 / \原创 2016-04-27 17:50:04 · 208 阅读 · 0 评论 -
leetcode——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原创 2016-04-27 18:28:11 · 176 阅读 · 0 评论 -
leetcode——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原创 2016-04-27 18:52:04 · 261 阅读 · 0 评论 -
leetcode——95——Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2016-04-29 14:57:01 · 206 阅读 · 0 评论 -
leetcode——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 re原创 2016-04-30 11:43:17 · 224 阅读 · 0 评论 -
leetcode——309——Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one原创 2016-04-30 12:40:22 · 216 阅读 · 0 评论 -
leetcode——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 dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2016-04-30 15:53:28 · 167 阅读 · 0 评论 -
leetcode——122——Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one原创 2016-04-30 15:58:04 · 178 阅读 · 0 评论 -
leetcode——123——Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most two transactions.题意:用一个数组表示股票原创 2016-04-30 16:41:14 · 203 阅读 · 0 评论 -
求一个字符串中连续出现次数最多的子串
#include #include using namespace std;void main(){ string str = "abcabcabcccccdefefefefefef"; int len = str.length(); int maxCount = 0; string longest = ""; for(int pos1 = 0;原创 2016-06-02 14:51:46 · 177 阅读 · 0 评论