会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
SprayT
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
···
17
下一页
2015年4月18日
Roman to Integer
摘要: /* 题意:罗马数字转换成阿拉伯数字 解法:用map映射一下,判断当前字母是否比下一个小,是的话ans加上下一字母的值-当前字母的值, 否则的话直接加上当前字母的值。*/class Solution {public: int romanToInt(string s) { ...
阅读全文
posted @ 2015-04-18 20:30 SprayT
阅读(105)
评论(0)
推荐(0)
2015年4月16日
Combinations
摘要: /*题意:给两个数n,和k,求1-n的组合情况解法:递归求解*/class Solution {public: vector >res; int count; void Comb(int A[],int n,int k,int step){ if(step == k)...
阅读全文
posted @ 2015-04-16 17:35 SprayT
阅读(132)
评论(0)
推荐(0)
2015年4月15日
Pascal's Triangle II
摘要: /* 给一个k,返回第k行的杨辉三角 类似动态规划由于只要返回某一行,所以只要用一维维护即可*/class Solution {public: vector getRow(int rowIndex) { vectorres(rowIndex+1,0); ...
阅读全文
posted @ 2015-04-15 21:36 SprayT
阅读(96)
评论(0)
推荐(0)
Pascal's Triangle
摘要: /*杨辉三角的简单应用 res[i][j] = res[i-1][j]+res[i-1][j-1](j>0&&j > generate(int numRows) { vector >res; for(int i = 0 ; i ()); for(in...
阅读全文
posted @ 2015-04-15 21:07 SprayT
阅读(109)
评论(0)
推荐(0)
Single Number II
摘要: /* 题意:给一个整数数组,每一个元素出现三次,只有一个元素出现一次,找出那个数(target数) 解法:用位运算做,统计整个数组每一位1的个数,然后对3取模,因为如果在第i位target数为0, 那么bit%3就为0,否则为1,对bit进行左移操作,然后直接累加结果。*/clas...
阅读全文
posted @ 2015-04-15 19:17 SprayT
阅读(141)
评论(0)
推荐(0)
2015年4月14日
Valid Parentheses
摘要: /*判断括号匹配问题,用一个栈保存判断即可*/class Solution {public: bool isValid(string s) { int len = s.length(); stacks1; for(int i = 0 ; i < len...
阅读全文
posted @ 2015-04-14 20:13 SprayT
阅读(99)
评论(0)
推荐(0)
Valid Palindrome
摘要: /*判断一个字符串是否是回文串(只包括数字和字母并且不区分大小写)*/class Solution {public: bool isAlphanumeric(char ch){ if((ch>='0' && ch='a' && ch='A' && ch<='Z') return ...
阅读全文
posted @ 2015-04-14 19:28 SprayT
阅读(98)
评论(0)
推荐(0)
Valid Sudoku
摘要: /*给一个不完整的数独,'.'代表为空判断数独是否合法*/public class Solution { public boolean check1(char[][] board){ for(int i = 0 ; i < 9 ; i ++){ int[] ...
阅读全文
posted @ 2015-04-14 15:05 SprayT
阅读(88)
评论(0)
推荐(0)
2015年4月12日
Add Binary
摘要: /*两个二进制相加,求和*/class Solution {public: string addBinary(string a, string b) { string ans=""; int i = a.length() -1,j = b.length() -1; ...
阅读全文
posted @ 2015-04-12 15:12 SprayT
阅读(113)
评论(0)
推荐(0)
2015年4月11日
Minimum Path Sum
摘要: /*比较简单的动态规划*/class Solution {public: int minPathSum(vector > &grid) { int row = grid.size(); int col = grid[0].size(); for(int...
阅读全文
posted @ 2015-04-11 15:17 SprayT
阅读(108)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
···
17
下一页
公告