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

随笔分类 -  C++

上一页 1 2 3 4 下一页

 
C++有符号和无符号数的转换
摘要:本文转自:http://www.94cto.com/index/Article/content/id/59973.html 1.引例: 今天在做了一道关于有符号数和无符号数相互转换及其左移/右移的问题,被它们之间的转换原理和位移原理搞得头大了。真的很后悔本科的时候没有认真学习《计算机组成原理》/《计 阅读全文
posted @ 2016-02-28 17:00 LC凑热闹 阅读(3875) 评论(0) 推荐(0)
Leetcode题解(34)
摘要:113. Path Sum II 题目 分析: 主要考察二叉树深度优先遍历(DFS),递归调用当前节点的左右结点即可,代码如下(copy网上): 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * T 阅读全文
posted @ 2016-02-25 18:11 LC凑热闹 阅读(208) 评论(0) 推荐(0)
Leetcode题解(33)
摘要:113. Path Sum II 题目 分析: 主要考察二叉树深度优先遍历(DFS),递归调用当前节点的左右结点即可,代码如下(copy网上): 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * T 阅读全文
posted @ 2016-02-25 18:11 LC凑热闹 阅读(194) 评论(0) 推荐(0)
Leetcode题解(32)
摘要:107. Binary Tree Level Order Traversal II 题目 直接代码: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 阅读全文
posted @ 2016-02-24 15:47 LC凑热闹 阅读(197) 评论(0) 推荐(0)
Leetcode题解(31)
摘要:103. Binary Tree Zigzag Level Order Traversal 题目 分析: 广度优先遍历的应用。重点是掌握vector的reverse函数,一开始我忘记有这个函数了,琢磨半天都没弄出来,后来想起reverse函数,问题一下子就迎刃而解。 代码 1 /** 2 * Def 阅读全文
posted @ 2016-02-23 20:59 LC凑热闹 阅读(263) 评论(0) 推荐(0)
Leetcode题解(30)
摘要:98. Validate Binary Search Tree 题目 分析:BST按照中序遍历之后所得到的序列是一个递增序列,因此可以按照这个思路,先中序遍历,保存好遍历的结果,然后在遍历一遍这个序列。判断其是否递增 代码如下: 1 /** 2 * Definition for a binary t 阅读全文
posted @ 2016-02-03 13:42 LC凑热闹 阅读(323) 评论(0) 推荐(0)
Leetcode题解(29)
摘要:93. Restore IP Addresses 题目 分析:多重循环,判断小数点合适的位置 代码如下(copy网上) 1 class Solution { 2 public: 3 vector<string> restoreIpAddresses(string s) { 4 vector<stri 阅读全文
posted @ 2016-02-03 11:56 LC凑热闹 阅读(229) 评论(0) 推荐(0)
Leetcode题解(28)
摘要:90. Subsets II 题目 分析:代码如下 1 class Solution { 2 public: 3 vector<vector<int> > subsetsWithDup(vector<int> &S) { 4 vector<vector<int> > result; 5 map<ve 阅读全文
posted @ 2016-02-03 10:37 LC凑热闹 阅读(209) 评论(0) 推荐(0)
Leetcode题解(27)
摘要:86. Partition List 题目 分析:题目要求将链表划分为两部分,前半部分小于x,后半部分大于等于x,并且各个数之间的相对顺序不变。 解题思路是:从头开始扫描链表,找打第一个大于等于x的数current,然后从这个数开始,把current之后的小于x的数依次插在current前,大于等于 阅读全文
posted @ 2016-02-02 16:57 LC凑热闹 阅读(209) 评论(0) 推荐(0)
Leetcode题解(26)
摘要:80. Remove Duplicates from Sorted Array II 题目 分析:简单的操作,代码如下: 1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 int n = nums.s 阅读全文
posted @ 2016-02-02 15:31 LC凑热闹 阅读(180) 评论(0) 推荐(0)
Leetcode题解(25)
摘要:77. Combinations 题目 分析:求给定数字n,k的组合数,方法是采用深度搜索算法,代码如下(copy网上代码) 1 class Solution { 2 public: 3 void dfs77(vector<vector<int > > &ans, vector<int> suban 阅读全文
posted @ 2016-02-01 16:30 LC凑热闹 阅读(229) 评论(0) 推荐(0)
Leetcode题解(24)
摘要:73. Set Matrix Zeroes 分析:如果没有空间限制,这道题就很简单,但是要求空间复杂度为O(1),因此需要一些技巧。代码如下(copy网上的代码) class Solution { public: void setZeroes(vector<vector<int> > &matrix 阅读全文
posted @ 2016-02-01 15:22 LC凑热闹 阅读(193) 评论(0) 推荐(0)
Leetcode题解(23)
摘要:69. Sqrt(x) 题目 分析,题目实现求一个int数的平方根,最暴力的算法就是逐个遍历,从1开始到x,判断是否有一个数i,其中满足i*i<=x,并且(i+1)*(i+1)>x;这个算法发虽然简单,但是效率不高。其实,按照暴力算法的思想,我们可以联想到在一个已经排好序的数组中查找一个数,该数正好 阅读全文
posted @ 2016-02-01 12:44 LC凑热闹 阅读(158) 评论(0) 推荐(0)
Leetcode题解(22)
摘要:66. Plus One 题目 这题很简单,直接代码: 1 class Solution { 2 public: 3 vector<int> plusOne(vector<int> &digits) { 4 // IMPORTANT: Please reset any member data you 阅读全文
posted @ 2016-02-01 11:56 LC凑热闹 阅读(216) 评论(0) 推荐(0)
Leetcode题解(21)
摘要:62. Unique Paths 题目 分析: 机器人一共要走m+n-2步,现在举个例子类比,有一个m+n-2位的二进制数,现在要在其中的m位填0,其余各位填1,一共有C(m+n-2,m-1)种可能,如果0表示向下走,1表示向右走,这样就和题目意思一样了。 现在考虑最后一步的走法,要么向右走到达终点 阅读全文
posted @ 2016-01-30 16:11 LC凑热闹 阅读(254) 评论(0) 推荐(0)
Leetcode题解(20)
摘要:59. Spiral Matrix II 题目 这道题copy网上的代码 1 class Solution { 2 private: 3 int step[4][2]; 4 bool canUse[100][100]; 5 public: 6 void dfs(int dep, vector<vec 阅读全文
posted @ 2016-01-30 15:31 LC凑热闹 阅读(210) 评论(0) 推荐(0)
Leetcode题解(十九)
摘要:54、Spiral Matrix 题目: 题目意思很简单,就是螺旋式访问矩阵元素。也没有比较经典的算法可以解决此题,只需要模拟一下这个过程即可。 代码如下: 1 class Solution { 2 public: 3 vector<int> spiralOrder(vector<vector<in 阅读全文
posted @ 2016-01-30 15:13 LC凑热闹 阅读(169) 评论(0) 推荐(0)
Leetcode题解(十八)
摘要:51、N-Queens ---------------------------------------------------------------------------------分割线------------------------------------------------------ 阅读全文
posted @ 2016-01-30 13:43 LC凑热闹 阅读(205) 评论(0) 推荐(0)
Leetcode题解(十七)
摘要:48、Rotate Image 题目: 分析:题目意思很简单,就是将一个n*n的矩阵顺时针旋转90度。 这道题难度不大,按照旋转的过程走一遍即可。代码如下: 1 class Solution { 2 public: 3 void rotate(vector<vector<int>>& matrix) 阅读全文
posted @ 2016-01-30 11:22 LC凑热闹 阅读(197) 评论(0) 推荐(0)
Leetcode题解(十六)
摘要:44 ----------------------------------------------------------------分割线-------------------------------------------------------------------------------- 阅读全文
posted @ 2016-01-21 16:11 LC凑热闹 阅读(193) 评论(0) 推荐(0)
 

上一页 1 2 3 4 下一页

公告


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