摘要:
杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; 1 class Solution { 2 public: 3 vector<int> getRow(int rowIndex) { 4 if(rowI 阅读全文
摘要:
二叉树的层次遍历 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) 阅读全文
摘要:
给定一个数n 求出n!的末尾0的个数。 n!的末尾0产生的原因其实是n! = x * 10^m 如果能将n!是2和5相乘,那么只要统计n!约数5的个数. 1 class Solution { 2 public: 3 int trailingZeroes(int n) { 4 int ans = 0; 阅读全文
摘要:
杨辉三角,即组合数 递推 1 class Solution { 2 vector<vector<int>> v; 3 public: 4 Solution() { 5 for(int i = 0; i < 50; ++i){ 6 vector<int> t(i+1,1); 7 for(int j = 阅读全文
摘要:
题意让大数加1 我的做法是先让个位+1,再倒置digits,然后进位,最后倒置digits,得到答案。 1 class Solution { 2 public: 3 vector<int> plusOne(vector<int> &digits) { 4 digits[digits.size() - 阅读全文
摘要:
题目本身是去重 由于我很懒,所以用了STL库里的unique函数来去重,小伙伴们可以考虑自己实现去重的函数,其实并不复杂。 1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 return unique 阅读全文
摘要:
和remove zero类似的方法完成该题 1 class Solution { 2 public: 3 int removeElement(vector<int>& nums, int val) { 4 vector<int>::size_type j = 0; 5 for(vector<int> 阅读全文
摘要:
1.Shell脚本是解释型的语言。 2.Shell脚本建立的基本步骤: 3.Shell脚本文件的第一行一般可以是:"#! 路径名 -(选项)", 为了要使Shell脚本有移植性,请满足下列要求: 1)Length(第一行)<64 2)路径名要完整 3)选项不要有空格 4.Shell脚本的命令类型:内 阅读全文
摘要:
题意是倒过来层次遍历二叉树 下面我介绍下BFS的基本框架,所有的BFS都是这样写的 struct Nodetype { int d;//层数即遍历深度 KeyType m;//相应的节点值 } queue<Nodetype> q; q.push(firstnode); while(!q.empty( 阅读全文
摘要:
判断一棵树是否自对称 可以回忆我们做过的Leetcode 100 Same Tree 二叉树和Leetcode 226 Invert Binary Tree 二叉树 先可以将左子树进行Invert Binary Tree,然后用Same Tree比较左右子树 而我的做法是改下Same Tree的函数 阅读全文