![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 80
binary_search
这个作者很懒,什么都没留下…
展开
-
leetcode:Palindrome Partitioning II
谨遵学长教导,开始刷算法题,从leetcode开始做起。可惜第一次就碰到了两个dp的问题Palindrome Partitioning II。。。第一次搞了半天,感觉像是可以建模为最短路径问题,思路不清晰,乱写竟然通过了judge small,在judge large的时候,最后一个测试例子没有通过,显示超时。不懂为什么,后来google了一下,发现原来是判断是不是回文也要用dp,艾。。后来就没有原创 2013-03-29 19:25:25 · 2226 阅读 · 0 评论 -
leetcode: Single Number (II)
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 using ext原创 2013-11-21 12:25:52 · 642 阅读 · 0 评论 -
leetcode: Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input原创 2013-11-22 16:04:43 · 971 阅读 · 0 评论 -
leetcode: Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.思路两个两个的比较,然后递归。class Solution {public: string longestCommonPrefix(vector &strs) { // IMPORT原创 2013-11-23 13:11:57 · 660 阅读 · 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 and sum原创 2013-11-23 18:51:13 · 491 阅读 · 0 评论 -
leetcode: 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 / \原创 2013-11-24 19:01:09 · 538 阅读 · 0 评论 -
leetcode: Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2013-11-26 18:53:54 · 477 阅读 · 0 评论 -
leetcode: Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2013-11-26 19:25:32 · 502 阅读 · 0 评论 -
leetcode: Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2013-11-26 19:48:59 · 515 阅读 · 0 评论 -
leetcode: Median of Two Sorted Arrays
There are two sorted arrays A and B 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)).思路本来觉得就是递归,怎么删减一些数字,然后保持问题为剩下一堆原创 2013-11-14 15:53:36 · 521 阅读 · 0 评论 -
经典排序算法
快速排序冒泡排序选择排序桶排序堆排序合并排序原创 2014-04-24 13:56:21 · 669 阅读 · 0 评论 -
经典排序算法2-堆排序及优先队列
堆排序以及用堆实现的优先队列#include #include #include #include #include #include #include using namespace std;#define RESET "\033[0m"#define BLACK "\033[30m" /* Black */#define RED "\原创 2014-04-24 15:32:15 · 607 阅读 · 0 评论 -
leetcode: Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路同样,注意4和9的处理就行了。仍然是从末位处理比较方便。class Solution {public: string intToRoman(int原创 2013-11-20 15:29:55 · 659 阅读 · 0 评论 -
leetcode: Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路很简单,注意4和9的处理就行了。另外,从末位开始计算比较好算,这样可以比较清楚的知道哪一位是阿拉伯数字的哪一位。class Solution {publi原创 2013-11-20 15:27:38 · 692 阅读 · 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, 0). Fin原创 2013-11-20 15:21:37 · 672 阅读 · 0 评论 -
leetcode:Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["a原创 2013-03-29 21:13:46 · 1461 阅读 · 0 评论 -
leetcode:Sqrt(x)
题目:Implement int sqrt(int x).Compute and return the square root of x.做这道题目,做的真拙计。一开始想到了《最优化理论》里面的类似于二分法的方法,结果竟然超时。十分不解,后来换成了牛顿切线法,表示貌似我实现的是有问题的,我实现没有使用浮点数,在某些输入的情况下是有死循环的。google了之后,结果让原创 2013-04-03 19:24:04 · 1046 阅读 · 0 评论 -
leetcode:Surrounded Regions
Problem: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,原创 2013-05-23 16:44:53 · 1254 阅读 · 0 评论 -
leetcode:Sum Root to Leaf Numbers
Problem: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.原创 2013-05-25 18:45:40 · 455 阅读 · 0 评论 -
leetcode: Two Sum
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, whe原创 2013-10-29 15:37:14 · 512 阅读 · 0 评论 -
排序算法--堆排序
由于不经常使用,之前学习看过的算法都给忘了。现在把他们写下来,记录下来,以方便以后查阅。本篇文章的代码即为堆排序的代码。堆排序代码主函数中是对输入文件中的序列进行排序,并将结果输出到一个文件中。这是一种形式类似于google codejam的测试方法。#include #include using namespace std;void aprint(int *arr,i原创 2013-10-29 13:37:08 · 494 阅读 · 0 评论 -
leetcode: Add Two Numbers
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 link原创 2013-11-16 16:51:00 · 665 阅读 · 0 评论 -
leetcode: 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, and there exists one unique longest palindromic substring.思路由于我做题没有按照顺序,前面原创 2013-11-16 19:23:14 · 641 阅读 · 0 评论 -
leetcode: ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2013-11-17 12:01:58 · 842 阅读 · 0 评论 -
leetcode: Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2013-11-16 15:44:48 · 755 阅读 · 0 评论 -
leetcode: Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2013-11-17 12:40:33 · 722 阅读 · 0 评论 -
leetcode: String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2013-11-17 18:34:09 · 777 阅读 · 0 评论 -
leetcode: Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2013-11-19 16:05:05 · 714 阅读 · 0 评论 -
深度优先遍历与树的前中后序遍历
深度优先遍历深度优先bian原创 2014-04-24 20:01:48 · 5279 阅读 · 0 评论