50. Pow(x, n) (中等)

    double myPow(double x, int n) {
double ans = ;
unsigned long long p;
if (n < ) {
p = -n;
x = / x;
} else {
p = n;
}
while (p) {
if (p & )
ans *= x;
x *= x;
p >>= ;
}
return ans;
}

96. Unique Binary Search Trees(很快)

 class Solution {
public:
int numTrees(int n) {
long ans=;
for(int i=n+;i<=*n;i++)
ans = i*ans/(i-n);
return ans/(n+);
}
};

94. Binary Tree Inorder Traversal(很快)

 /**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
stack<TreeNode*> s;
vector<int> res;
if(root==NULL) return res;
TreeNode* p=root;
while(!s.empty()||p){
if(p){
s.push(p);
p=p->left;
}
else{
p=s.top();
s.pop();
res.push_back(p->val);
p=p->right;
}
}
return res;
}
};
 /**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> res;
vector<int> inorderTraversal(TreeNode* root) {
if(!root) return res;
inorderTraversal(root->left);
res.push_back(root->val);
inorderTraversal(root->right);
return res;
}
};
 89. Gray Code(很快)
 class Solution {
public:
vector<int> grayCode(int n) {
int len = << n;
vector<int> res(len,);
for(int i = ;i != len;++i){
res[i] =i ^ (i >> );
}
return res;
}
};

最新文章

  1. for 循环打印图形
  2. ReactNative新手学习之路01-创建项目开始
  3. Bootstrap简介
  4. Printf()输出格式控制(转)
  5. Codeforces 749D:Leaving Auction(set+二分)
  6. .net 获取当前周及根据年和周获取起始结束时间
  7. ldconfig deferred processing now taking place
  8. MongoDB源码概述——内存管理和存储引擎
  9. Odoo constraints 使用教程
  10. 64位操作系统下用Microsoft.Jet.OLEDB.4.0出现未注册错误
  11. ThinkPHP中处理验证码不显示问题
  12. EularProject 43: 带条件约束的排列组合挑选问题
  13. 基于开源CA系统ejbca community 6.3.1.1构建私有CA管理数字证书
  14. 通用查询设计思想(2)- 基于ADO.Net的设计
  15. 魅族5.0以上设备(亲测有效)激活Xposed框架的流程
  16. JavaScript 基本包装类型,包装对象
  17. hadoop:如何运行自带wordcount
  18. php 设置中文 cookie, js获取
  19. #C++初学记录(算法3)
  20. asp.net mvc发送邮件

热门文章

  1. nohup top &amp; 问题: top: failed tty get
  2. 数电——全减器分析(用74HC138设计提示)
  3. Python中续行符的注意事项
  4. linux输入密码的实现
  5. 排查bug的步骤
  6. delphi query阻塞执行 长时间执行sql的解决办法
  7. day08-MySQl创建用户和授权
  8. 爬虫--requests模块高级(代理和cookie操作)
  9. GCD 常用API 总结
  10. JSP基本_JSPの構成要素、アクション、ディレクティブ