• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LC凑热闹
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

随笔分类 -  算法

上一页 1 2 3 4 下一页

 
Leetcode题解(七)
摘要:24、Swap Nodes in Pairs题目看到此题,第一想法是利用两个指针,分别将其所指向的节点的value交换。然后同时向后移动2个节点,代码如下: 1 struct ListNode { 2 int val; 3 ListNode *next; 4 Li... 阅读全文
posted @ 2015-12-07 15:09 LC凑热闹 阅读(218) 评论(0) 推荐(0)
Leetcode题解(六)
摘要:21、Merge Two Sorted Lists题目直接上代码:class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode *helper=new ListNode... 阅读全文
posted @ 2015-12-03 18:50 LC凑热闹 阅读(181) 评论(0) 推荐(0)
Leetcode题解(五)
摘要:17、Letter Combinations of a Phone Number题目针对输入的数字串,每一个数字都对应对个字符可以选择。因此可以直接采用递归的思想,依次遍历数字串的每一个数字,处理到当前数字时,余下的数字可以看出一个规模更小的子串来处理,这正符合递归的思想,将问题逐步化小。代码如下:... 阅读全文
posted @ 2015-12-02 19:58 LC凑热闹 阅读(225) 评论(0) 推荐(0)
Leetcode题解(四)
摘要:12/13、Integer to Roman/RomantoInteger题目罗马数字规则:符号IVXLCDM数字1510501005001000代码如下: 1 class Solution { 2 public: 3 string intToRoman(int num) { 4 ... 阅读全文
posted @ 2015-12-01 20:45 LC凑热闹 阅读(265) 评论(0) 推荐(0)
Leetcode题解(三)
摘要:8、String to Integer (atoi)题目这道题目关键是要考虑清楚各种输入用例。针对每一种情况,函数都能处理,也就是函数鲁棒性很高。代码如下: 1 class Solution { 2 public: 3 int myAtoi(string str) { 4 i... 阅读全文
posted @ 2015-11-30 20:51 LC凑热闹 阅读(206) 评论(0) 推荐(0)
Leetcode题解(二)
摘要:4、Median of Two Sorted Arrays(*)题目题目要求找到两个排序数组的中位数。中位数的定义:当n为奇数时,median = array[n/2];当n为偶数时,median = (array[n/2]+array[n/2+1])/2.暴力算法,两个数组归并排序,对合并的数组求... 阅读全文
posted @ 2015-11-28 14:11 LC凑热闹 阅读(190) 评论(0) 推荐(0)
腾讯2016编程笔试题
摘要:1、在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同,则称这种编码为格雷码(Gray Code)。请编写一个函数,使用递归方法生成N位的格雷码,并且保证这个函数的健壮性。 首先的搞清楚格雷码是什么,百度百科 生成格雷码的方法很多,百科中提到几种生成格雷码的方法,其中包括如下几种: ①递归法 阅读全文
posted @ 2015-09-09 21:52 LC凑热闹 阅读(1747) 评论(0) 推荐(0)
剑指offer(一)
摘要:面试题3:二维数组中查找题目描述: 在一个二维数组中,每一行都按照从左往右递增地顺序排序,每一列都按照从上往下递增的顺序排序。请完成一个函数,输入这样的一个数组和一个整数,判断数组中是否存在该整数。算法一:直接查找,即采取遍历数组的方法;算法二:从数组右上角开始比较;算法三:从数组左下角开始比较;算... 阅读全文
posted @ 2015-07-15 20:36 LC凑热闹 阅读(262) 评论(0) 推荐(0)
Leetcode题解(一)
摘要:1、Two Sum题目此题第一解题思路,就是最常见的方法,两个指针嵌套遍历数组,依次判断当前指针所指向的值是否满足条件。代码如下; 1 class Solution { 2 public: 3 vector twoSum(vector& nums, int target) { 4 ... 阅读全文
posted @ 2015-07-06 20:18 LC凑热闹 阅读(399) 评论(0) 推荐(0)
回文字符序列
摘要:转载http://blog.csdn.net/u014800748/article/details/451484411、问题描述描述给定字符串,求它的回文子序列个数。回文子序列反转字符顺序后仍然与原序列相同。例如字符串aba中,回文子序列为"a", "a", "aa", "b", "aba",共5个... 阅读全文
posted @ 2015-04-22 21:55 LC凑热闹 阅读(280) 评论(0) 推荐(0)
动态规划求一个序列的最长回文子序列(Longest Palindromic Substring )
摘要:1、问题描述给定一个字符串(序列),求该序列的最长的回文子序列。2、分析需要理解的几个概念:---回文---子序列---子串http://www.cnblogs.com/LCCRNblog/p/4321398.html这一篇文章描述了利用动态规划求解两个序列的最长公共子序列(Longest Comm... 阅读全文
posted @ 2015-04-21 12:45 LC凑热闹 阅读(869) 评论(0) 推荐(0)
统计闰年2月29日天数
摘要:1.问题描述描述给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。只有闰年有2月29日,满足以下一个条件的年份为闰年:1. 年份能被4整除但不能被100整除2. 年份能被400整除输入第一行为一个整数T,表示数据组数。之后每组数据包含两行。每一行格式为"month day, yea... 阅读全文
posted @ 2015-04-19 16:15 LC凑热闹 阅读(664) 评论(0) 推荐(0)
Leetcode 172 Factorial Trailing Zeroes
摘要:1、题目要求Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.题目意思是求n的阶乘后面末尾0的个数,并且时间... 阅读全文
posted @ 2015-04-04 16:44 LC凑热闹 阅读(213) 评论(0) 推荐(0)
Leetcode 199 Binary Tree Right Side View
摘要:1.题目要求Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom.For ... 阅读全文
posted @ 2015-04-04 15:15 LC凑热闹 阅读(540) 评论(0) 推荐(0)
Leetcode 198 House Robber
摘要:1.题目要求You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopp... 阅读全文
posted @ 2015-04-04 13:59 LC凑热闹 阅读(318) 评论(0) 推荐(0)
Leetcode 15 3sum
摘要:1.题目要求Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:... 阅读全文
posted @ 2015-03-31 22:58 LC凑热闹 阅读(183) 评论(0) 推荐(0)
Leetcode 3 Longest Substring Without Repeating Characters
摘要:1.题目要求Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating lett... 阅读全文
posted @ 2015-03-29 17:11 LC凑热闹 阅读(174) 评论(0) 推荐(0)
Leetcode 4 Median of Two Sorted Arrays
摘要:1.题目要求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 shou... 阅读全文
posted @ 2015-03-27 15:08 LC凑热闹 阅读(170) 评论(0) 推荐(0)
Leetcode 1 Two Sum
摘要:1.题目要求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 ... 阅读全文
posted @ 2015-03-26 16:43 LC凑热闹 阅读(188) 评论(0) 推荐(0)
面试算法题:16个数,最多用20次比较,找出第二大的数?
摘要:这道题最笨的方法就是先从16个数中选出最大的数,然后再从剩下的15个数中选出最大数就可得到答案,因此,需要15+14=29次比较。既然这道题要求在20次比较之内就能找出第二大的数,那我们就想能简单的方法。假设16个数中最大的是A,第二大的是B。首先将16个数两两进行比较,较大者胜出,然后再在胜出者中... 阅读全文
posted @ 2015-03-20 22:07 LC凑热闹 阅读(1014) 评论(0) 推荐(0)
 

上一页 1 2 3 4 下一页

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3