
算法
文章平均质量分 52
浣熊
北京邮电大学计算机学院 嵌入式系统与网络通信实验室 iOS/Android应用开发
展开
-
[LeetCode] 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 number 123.Find原创 2014-06-17 22:22:40 · 873 阅读 · 0 评论 -
[LeetCode] Permutations
题目:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].解答:原创 2014-06-10 14:43:13 · 640 阅读 · 0 评论 -
[LeetCode] Rotate Image
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?解答:class Solution {public: void rotat原创 2014-06-08 15:30:43 · 660 阅读 · 0 评论 -
[LeetCode] Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−原创 2014-05-24 11:22:14 · 797 阅读 · 0 评论 -
[LeetCode] Merge Sorted Array
题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional eleme原创 2014-05-24 16:32:30 · 695 阅读 · 0 评论 -
[LeetCode] Swap Nodes in Pairs
题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant原创 2014-05-24 14:35:03 · 1131 阅读 · 0 评论 -
[LeetCode] Generate Parentheses
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(()原创 2014-06-07 16:32:08 · 671 阅读 · 0 评论 -
[LeetCode] Pascal's Triangle
题目:解法:class Solution {public: vector> generate(int numRows) { vector> triangle; vector triangle_cell; if(numRows == 0) { return triangle; }原创 2014-05-24 14:13:12 · 709 阅读 · 0 评论 -
[LeetCode] Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in p原创 2014-05-24 16:53:44 · 518 阅读 · 0 评论 -
[LeetCode] Binary Tree Postorder Traversal [递归版]
题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recurs原创 2014-06-10 15:54:03 · 605 阅读 · 0 评论 -
[LeetCode] Search a 2D Matrix
题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first intege原创 2014-06-10 18:30:39 · 682 阅读 · 0 评论 -
[LeetCode] Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-06-12 23:30:50 · 683 阅读 · 0 评论 -
[LeetCode] Path Sum
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree原创 2014-06-15 10:53:43 · 707 阅读 · 0 评论 -
[LeetCode] Minimum Depth of Binary Tree
题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.原创 2014-06-16 10:39:23 · 790 阅读 · 0 评论 -
[LeetCode] Balanced Binary Tree
题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ne原创 2014-06-15 11:22:55 · 808 阅读 · 0 评论 -
[LeetCode] Minimum Path Sum
题目:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or原创 2014-06-14 14:35:30 · 718 阅读 · 0 评论 -
[LeetCode] 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 (ie, buy one and sell one share of th原创 2014-06-14 08:59:01 · 1439 阅读 · 0 评论 -
[LeetCode] Remove Duplicates from Sorted Array II
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is no原创 2014-06-16 09:46:19 · 781 阅读 · 0 评论 -
[LeetCode] Container With Most Water
题目:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i,原创 2014-06-15 09:24:47 · 776 阅读 · 0 评论 -
[LeetCode] Linked List Cycle II
题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?解答:原创 2014-06-14 16:05:54 · 776 阅读 · 0 评论 -
[LeetCode] Plus One
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解答原创 2014-06-08 16:41:39 · 1528 阅读 · 0 评论 -
[LeetCode] Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new len原创 2014-05-24 12:55:08 · 650 阅读 · 0 评论 -
[LeetCode] Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.解答:原创 2014-05-24 09:54:08 · 541 阅读 · 0 评论 -
[LeetCode] Single Number
题目:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without原创 2014-05-22 08:40:27 · 615 阅读 · 0 评论 -
[LeetCode] Same Tree
题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解答:原创 2014-05-22 08:35:47 · 750 阅读 · 0 评论 -
[LeetCode] Sort Colors
题目: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 red, white and blue.Here, we will use the原创 2014-06-04 08:37:37 · 664 阅读 · 0 评论 -
[LeetCode] Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2014-06-03 16:20:00 · 778 阅读 · 0 评论 -
[LeetCode] Gray Code
题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the seque原创 2014-06-03 08:49:19 · 817 阅读 · 0 评论 -
C++ 读取多行带空格的字符串,以EOF结束
string s;while(get line(cin,s)) { cout << s << endl;}输入eof:windows——ctrl+zunix/linux——ctrl+d原创 2014-03-05 22:16:56 · 9259 阅读 · 1 评论 -
读《一个递归引发的思考》有感 ——“码小农”第一期
首先,我想向阿里的凡提前辈表达诚挚的谢意,感谢前辈在百忙之中参与高校联盟的“码小农”活动,同时感谢集团技术发展部的高阳姐,多谢您从中沟通协调,保证本次活动顺利完成。以下涉及到凡提前辈本人的博文原文或解答等时,文字将被标记为蓝色,特此说明。 l 博文剖析 博文开始描述了凡提前辈遇到的一个需求:将某个路径作为参数传递给工具,然后工具可以遍历该目录下的所有子目录和文件,将所有数原创 2014-03-30 09:07:17 · 1544 阅读 · 0 评论 -
散列表碰撞的链接法解决之双向链表删除操作的代价
浣熊今天读到《算法导论》的第十一章散列表,看到中文书的第135页(英文P224~225)时,被其中的一个知识点难住,想了许久终于有了答案,故撰此文与大家分享 在散列表发生碰撞问题的时候,其中一种解决方法叫“链接法”,具体的做法我就不介绍了。在这一部分的最后,书作者提出如原创 2011-08-06 11:15:42 · 2915 阅读 · 4 评论 -
[LeetCode] Maximum Depth of Binary Tree
题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解答:原创 2014-05-22 08:44:28 · 664 阅读 · 0 评论 -
[LeetCode] Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321解答:class Solution {public: int reverse(int x) { int flag = 1; int resul原创 2014-05-22 09:14:32 · 1113 阅读 · 1 评论 -
[LeetCode] 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 day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i原创 2014-05-22 09:31:14 · 1026 阅读 · 0 评论 -
[LeetCode] Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.原创 2014-05-24 13:49:31 · 875 阅读 · 0 评论 -
[LeetCode] Climbing Stairs
tiYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2014-05-24 10:12:35 · 722 阅读 · 0 评论 -
[LeetCode] Binary Tree Inorder Traversal [递归版]
题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursiv原创 2014-05-23 08:10:17 · 680 阅读 · 0 评论 -
[LeetCode] 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?解答:/** * Definition for singly-linked list. * struct ListNode { *原创 2014-05-23 07:49:49 · 677 阅读 · 0 评论 -
[LeetCode] Search Insert Position
题目: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 inserted in order.You may assume no duplicates in t原创 2014-05-23 10:07:14 · 581 阅读 · 0 评论 -
[LeetCode] 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原创 2014-05-23 09:12:08 · 3035 阅读 · 3 评论