LintCode刷题小记491】的更多相关文章

题目: 判断一个正整数是不是回文数. 回文数的定义是,将这个数反转之后,得到的数仍然是同一个数. 样例: 11, 121, 1, 12321 这些是回文数. 23, 32, 1232 这些不是回文数. 分析: 回文数就是反转后和自身一样,可利用java中StringBuffer中reverse()这一函数进行操作. 下面给出代码: public class Solution { /** * @param num a positive number * @return true if it's a…
博主之前在学习 python 的数据结构与算法的基础知识,用的是<problem-solving-with-algorithms-and-data-structure-using-python> .但是仅仅看书对于知识的理解不够深入.于是选择了 lintcode 刷题,本篇博客即为最近做的算法题的一则小结. lintcode 的界面非常干净,还有中文版本的.博主的刷题的顺序为从入门开始,逐步深入,并不集中刷某块的题目.入门的8道题目都刷了,从简单开始优先做热点题(热点不分优先级). 一 矩阵…
最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. Longest Palindrome 给出一个包含大小写字母的字符串.求出由这些字母构成的最长的回文串的长度是多少. 数据是大小写敏感的,也就是说,"Aa" 并不会被认为是一个回文串 输入 : s = "abccccdd" 输出 : 7 说明 : 一种可以构建出来的最长回…
标签:动态规划 题目描述: Given two strings, find the longest common subsequence (LCS). Your code should return the length of LCS. 解题思路: 这一题是非常经典的动态规划问题,在解题思路上可以按照经典的动态规划的解法,这是在系统学习动态规划之后第一个解决的LintCode上的问题: 1.子问题划分 给出两个字符串的A,B,两个字符串长度分别为lenA,lenB,求出两个字符串的LCS: 这划…
1. 2019.4.27 agc016d 一道很坑的题. 首先判无解,求出异或值后排个序就可以. 然后直接让\(a_i\rightarrow b_i\)并查集维护,注意离散化和判重,答案加上联通块个数即可,注意细节即可.…
本篇博客对最近做的链表的算法题做个简单的小结,主要描述题目和提供解题思路,具体代码见我的 github:https://github.com/MUSK1881/lintcode-by-python 36. 翻转链表 II(中等) 描述 翻转链表中第m个节点到第n个节点的部分 样例 给出链表1->2->3->4->5->null, m = 2 和n = 4,返回1->4->3->2->5->null 思路 新建链表头,在第 m 个节点前打断,在第…
题目:两个字符串是变位词 题目难度:简单 题目描述: 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 解题思路: C++:引入哈希的思维,这道题就迎刃而解了. C++ Code: class Solution {public:    /**     * @param s: The first string     * @param b: The second string     * @return true or false     */ …
标签: 动态规划 题目描述: There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.…
标签: 动态规划 描述: Find the contiguous subarray within an array (containing at least one number) which has the largest product.   For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest product = 6. 解题思路: 前面几道题有点儿过分依赖答案了,后面还是…
标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. Example For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Return 4. 解题思路: 1.这一题明显使用动态规划来解题,…