![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法解题
文章平均质量分 73
周大侠真厉害
得加油了。
展开
-
strstr的实现与KMP
原题 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Update (2014-11-02): The signature of the function had been upda原创 2015-03-17 16:49:15 · 1955 阅读 · 0 评论 -
Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty原创 2015-06-12 15:05:50 · 439 阅读 · 0 评论 -
c++ 实现word ladder
leetcode的原题: Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be chang原创 2015-05-01 21:39:21 · 1503 阅读 · 1 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a原创 2015-04-20 16:55:21 · 317 阅读 · 0 评论 -
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原创 2015-04-14 21:24:48 · 471 阅读 · 0 评论 -
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. 题目的意思就是在一个矩阵中找到所有为零的点,然后把该点所在行与列都置为零。但是要求in place,就是原地置换。我理解的意思就是空间复杂度要求o(1)。 很水的一道题,只要遍历整个矩阵记原创 2015-04-06 18:26:53 · 767 阅读 · 0 评论 -
Insert Interval 插入间隙
先上题干,leetcode的原题: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their原创 2015-03-24 17:24:23 · 404 阅读 · 0 评论 -
八皇后问题
八皇后问题很老很经典了,一直有一点印象但没有好好的自己写过代码。 解决八皇后问题最关键的地方我认为应该是判断一个位置是否适合放入一个皇后。 有两种判断方法,先说最自然也是最容易想到的一种方法。 首先很容易得知每一行只能放一个皇后,可以用一个数组b[8]来表示八行每个皇后放在第几个位置。 要判断一个位置是否能放入一个新的皇后要做两个判断:前面几行有没有皇后放在原创 2015-03-09 17:49:02 · 319 阅读 · 0 评论 -
Pow的实现
就是实现一个简单的pow(double x, int n),直接一个个的乘当然太过naive,使用二分查找使得时间复杂度为o(lgn)。 话不多说,先上代码: int symbol = 1; double origx = x; if (n == 0 || x == 1.0) return symbol; if (n < 0) symbol *= -1; n = ab原创 2015-03-18 09:36:19 · 627 阅读 · 0 评论 -
Merge Intervals 这个应该叫合并间隙?
leetcode上的原题: Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 题意应该好理解,比如 1,3 与2,6都是被标记的范围,要求改为用1,6来表原创 2015-03-23 17:20:58 · 445 阅读 · 0 评论 -
Climbing Stairs爬楼梯啊爬楼梯(支持n step)
leetcode原题 You 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? 就是有个n阶的楼梯,原创 2015-03-30 15:32:16 · 715 阅读 · 0 评论 -
3Sum 好邪恶的题目啊。。嘿嘿
今天把刷了leecode上的TwoSum,感觉太水了干脆把threeSum也做了。 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of ze原创 2015-03-11 20:59:52 · 477 阅读 · 0 评论 -
poj3301三分法
题目大意:二维的坐标系中给出一些随机的点,把这些点都包含在内的最小正方形。 先考虑简单的情况:如果正方形的长宽裕坐标轴平行的话,我们只要找出x值y值的最小值与最大值(即找出最左最右最上最下的四个点),正方形的边长即为x最大值与x最小值的差或y的最大值与y最小值的差,因为要包含所有的点,取两者中更大的一个值。 但是正方形的长宽并不一定与坐标轴平行,所以要考虑正方形旋转的情况。但是原创 2015-09-20 17:28:17 · 605 阅读 · 0 评论