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

2014年3月24日

【Leetcode】Count and Say
摘要: 题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of i 阅读全文
posted @ 2014-03-24 19:46 UsSam 阅读(129) 评论(0) 推荐(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.解题思路:我们首先来明确一下罗马数字与阿拉伯数字的换算规则:如果当前数字比前一个大,说明这一段的值应该是当前这个值减去上一个值,比如IV = 5 – 1;否则,将当前值加入到结果中,然后开始下一段记录,比如VI = 5 + 1, II=1+1。而罗马数字与阿拉伯数字对应变换是:I对应1,V对应5,X对应10,L对应50,C对应100,D对应500,M对应1000。因此,只需要从前 阅读全文
posted @ 2014-03-24 19:08 UsSam 阅读(108) 评论(0) 推荐(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) { int MinSize=INT_MAX; int MinIndex=0; if(strs.empty())r... 阅读全文
posted @ 2014-03-24 16:36 UsSam 阅读(141) 评论(0) 推荐(0)
 
【Leetcode】Add Binary
摘要: 题目:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".解题思路1:判断当前字符所表示的数字,产生输出和进位。缺点:程序比较复杂。代码1:class Solution {public: string addBinary(string a, string b) { char carry='0'; string c; if(a.empty())return b; if( 阅读全文
posted @ 2014-03-24 16:06 UsSam 阅读(109) 评论(0) 推荐(0)
 
【Leetcode】String to Integer
摘要: 题目:Implementatoito 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 cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are re 阅读全文
posted @ 2014-03-24 11:06 UsSam 阅读(123) 评论(0) 推荐(0)
 
 

公告


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