会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
SprayT
博客园
首页
新随笔
联系
订阅
管理
2015年5月13日
Reverse Linked List
摘要: /*反转链表*//** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {...
阅读全文
posted @ 2015-05-13 22:14 SprayT
阅读(66)
评论(0)
推荐(0)
2015年4月26日
Sqrt(x)
摘要: /*用牛顿迭代法求x的平方根*/class Solution {public: int mySqrt(int x) { double res = 1.0; while(fabs(res*res-x)>1e-6){ res = (res+x/re...
阅读全文
posted @ 2015-04-26 19:34 SprayT
阅读(95)
评论(0)
推荐(0)
2015年4月23日
Convert Sorted Array to Binary Search Tree
摘要: /* 题意:把一个有序的数组转化成平衡二叉树 解法:递归*//** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; *...
阅读全文
posted @ 2015-04-23 22:42 SprayT
阅读(115)
评论(0)
推荐(0)
Remove Linked List Elements
摘要: /* 题意:给一个链表以及一个val值要去除链表中与val值相等的节点 解法:给链表加一个头结点因为可能开始第一个节点值就与val值相等 方便操作,然后循环删除就好*//** * Definition for singly-linked list. * struct ListNod...
阅读全文
posted @ 2015-04-23 21:21 SprayT
阅读(105)
评论(0)
推荐(0)
Happy Number
摘要: /* 题意:判断一个数是不是happy数(用这个数每一位的平方的和代替这个数, 不断重复这个过程,如果最后这个数是1,那么这个数就是happy数) 解法:用map容器映射一下,判断当前数是否在前面出现过,如果出现过那么 这个数就不是happy数,不过这样子的空间复杂度太高*/...
阅读全文
posted @ 2015-04-23 20:44 SprayT
阅读(134)
评论(0)
推荐(0)
2015年4月20日
Length of Last Word
摘要: /* 题意:求字符串的最后一个单词(不含空字符的) 解法:从后往前扫,先排除空字符,然后统计*/class Solution {public: int lengthOfLastWord(string s) { int res = 0; int i = s...
阅读全文
posted @ 2015-04-20 21:18 SprayT
阅读(78)
评论(0)
推荐(0)
Pow(x, n)
摘要: /* 题意:实现pow(x,n)函数 坑: 1>要用矩阵快速幂做 2>n可能为负数 3>n可能去INT_MIN所以需要类型转换*/class Solution {public: double pow(double x, int n) { d...
阅读全文
posted @ 2015-04-20 21:06 SprayT
阅读(118)
评论(0)
推荐(0)
Rotate Image
摘要: /* 题意:将一个矩阵顺时针旋转90度 解法:画个图,4个一组交换,实际交换只需要交换左上角的一个小矩形matrix[n/2][(n+1)/2];*/class Solution {public: void rotate(vector > &matrix) { int...
阅读全文
posted @ 2015-04-20 20:47 SprayT
阅读(77)
评论(0)
推荐(0)
Permutations
摘要: /* 题意:给一个集合,求所有的排列 做法:*/class Solution {public: vector >res;int count ; void dfs(int A[],vectornum,int n,int cur){ if(cur == n){//找...
阅读全文
posted @ 2015-04-20 20:08 SprayT
阅读(140)
评论(0)
推荐(0)
2015年4月18日
Integer to Roman
摘要: /* 题意:把阿拉伯数字转换成罗马数字 解法:直接暴力枚举了。*/class Solution {public: int power(int k){ int res = 1; for(int i = 0 ; i < k ; i++) res*=10; ...
阅读全文
posted @ 2015-04-18 21:25 SprayT
阅读(135)
评论(0)
推荐(0)
下一页
公告