上一页 1 2 3 4 5 6 7 8 ··· 13 下一页
摘要: Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2014-06-24 22:21 OpenSoucre 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon... 阅读全文
posted @ 2014-06-24 21:51 OpenSoucre 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-06-24 20:35 OpenSoucre 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-06-24 20:13 OpenSoucre 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 第一节 Floyd-Warshall算法本算法可以求任意两个点之间的最短路径,又称“多源最短路径”,其时间复杂度为O(n^3)其核心部分只有下面几行,注意加法的溢出处理 //floyd最短路径算法的核心部分 for(int k = 0; k grid[i][k]+grid[k][j])... 阅读全文
posted @ 2014-06-24 11:38 OpenSoucre 阅读(348) 评论(0) 推荐(0) 编辑
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.先算出链表... 阅读全文
posted @ 2014-06-23 20:56 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.class Solution {public: ... 阅读全文
posted @ 2014-06-23 20:20 OpenSoucre 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2014-06-23 18:14 OpenSoucre 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2014-06-23 17:16 OpenSoucre 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2014-06-23 17:02 OpenSoucre 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.TreeNode *createSearchTree(ListNode *&hea... 阅读全文
posted @ 2014-06-23 16:06 OpenSoucre 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.TreeNode *createSearchTree(vector& num, int left , in... 阅读全文
posted @ 2014-06-23 15:26 OpenSoucre 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 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 n... 阅读全文
posted @ 2014-06-23 14:48 OpenSoucre 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文
posted @ 2014-06-23 14:11 OpenSoucre 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文
posted @ 2014-06-23 14:06 OpenSoucre 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2014-06-23 13:55 OpenSoucre 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 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 / \ ... 阅读全文
posted @ 2014-06-23 12:25 OpenSoucre 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 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 an... 阅读全文
posted @ 2014-06-23 12:19 OpenSoucre 阅读(101) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2014-06-23 12:03 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文
posted @ 2014-06-23 00:22 OpenSoucre 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 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 le... 阅读全文
posted @ 2014-06-22 23:21 OpenSoucre 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2014-06-22 22:49 OpenSoucre 阅读(429) 评论(0) 推荐(0) 编辑
摘要: 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.简单的链表合并题L... 阅读全文
posted @ 2014-06-22 22:25 OpenSoucre 阅读(126) 评论(0) 推荐(0) 编辑
摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文
posted @ 2014-06-22 22:14 OpenSoucre 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 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 fol... 阅读全文
posted @ 2014-06-22 21:35 OpenSoucre 阅读(296) 评论(0) 推荐(0) 编辑
摘要: Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(... 阅读全文
posted @ 2014-06-22 20:28 OpenSoucre 阅读(505) 评论(0) 推荐(0) 编辑
摘要: GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]... 阅读全文
posted @ 2014-06-22 20:01 OpenSoucre 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 第5节 宝岛探险利用广度优先搜索实现其中可以不用开辟visit变量,直接用将本身的值改为-1,然后判断即可注意输入数据时周围加了一层-1,作为边界广度优先搜索利用深度优先搜索实现,注意下面的方法是将搜索到的点着成-1的颜色深度优先搜索注意如果n和m比较大的话,建议用广度优先搜索,由于深度优先搜索,一... 阅读全文
posted @ 2014-06-22 15:44 OpenSoucre 阅读(435) 评论(0) 推荐(0) 编辑
摘要: Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not co... 阅读全文
posted @ 2014-06-21 22:17 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2014-06-21 18:24 OpenSoucre 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ret... 阅读全文
posted @ 2014-06-21 17:46 OpenSoucre 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2014-06-21 16:54 OpenSoucre 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2014-06-21 16:34 OpenSoucre 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 由于题目数据量比较小,故可以开辟一个数组存储每个index出现的次数然后遍历即可string canItBeDone(int k, vector A){ vector cnt(52,0); int n = A.size(); for(int i = 0 ; i A) { ... 阅读全文
posted @ 2014-06-20 21:30 OpenSoucre 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 关于证明可以参考题解http://codeforces.com/blog/entry/12739就是将概率从大到小排序然后,然后从大到小计算概率#include #include #include #include #include #include using namespace std;int ... 阅读全文
posted @ 2014-06-20 20:44 OpenSoucre 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 本题要考虑字符串本身就存在tandem,如测试用例aaaaaaaaabbb3输出结果应该是8而不是6,因为字符串本身的tanderm时最长的故要考虑字符串本身的最大的tanderm和添加k个字符后最大的tanderm#include #include #include #include #inclu... 阅读全文
posted @ 2014-06-20 17:15 OpenSoucre 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 题目很简单,只需要注意带空格的输入用getline即可#include #include #include #include #include using namespace std;int main(){ string str; getline(cin,str); set a; ... 阅读全文
posted @ 2014-06-20 17:11 OpenSoucre 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 由于题目告诉肯定至少存在一种解,故只需要根据条件遍历一下, vector makeExpression(int y) { vector res; for(int i = -1000; i =-1000 && k<=1000 && k!=0 && k!=1){ ... 阅读全文
posted @ 2014-06-19 21:11 OpenSoucre 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2014-06-19 17:17 OpenSoucre 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep... 阅读全文
posted @ 2014-06-19 15:45 OpenSoucre 阅读(148) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页