Leetcode 109
//这种也是空间复杂度为O(K)的解法,就是边界有点难写
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res;
res.push_back();
if(rowIndex == ) return res;
res.push_back();
if(rowIndex == ) return res;
for(int i=;i <= rowIndex;i++){
res.push_back();
int a = res[];
int b = res[];
for(int j=;j < i;j++){
res[j] = a+b;
a = b;
b = res[j+];
}
res[i] = ;
}
return res;
}
};
Leetcode 109的更多相关文章
- LeetCode 109——有序链表转化二叉搜索树
1. 题目 2. 解答 2.1. 方法一 在 LeetCode 108--将有序数组转化为二叉搜索树 中,我们已经实现了将有序数组转化为二叉搜索树.因此,这里,我们可以先遍历一遍链表,将节点的数据存入 ...
- [LeetCode] 109. Convert Sorted List to Binary Search Tree 把有序链表转成二叉搜索树
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- [LeetCode] 109. 有序链表转换二叉搜索树
题目链接 : https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree/ 题目描述: 给定一个单链表,其中的 ...
- Java实现 LeetCode 109 有序链表转换二叉搜索树
109. 有序链表转换二叉搜索树 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. ...
- leetcode 108 和leetcode 109 II
//感想:没啥上篇写完了 //思路:对于这道题109来说,就是数组变成了链表,其他没有变,我觉得非常不解,因为我想到的依旧是找中点,用快慢指针来找, 找到以后将链表分成两半,继续递归的去找,我就觉得这 ...
- leetcode 109 Convert Sorted List to Binary Search Tree ----- java
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- Leetcode#109 Convert Sorted List to Binary Search Tree
原题地址 跟Convert Sorted Array to Binary Search Tree(参见这篇文章)类似,只不过用list就不能随机访问了. 代码: TreeNode *buildBST( ...
- [LeetCode 109] - 将已排序链表转换为二叉搜索树 (Convert Sorted List to Binary Search Tree)
问题 给出一个元素以递增序列排序的单链表,将其转换为一棵高度平衡的二叉搜索树. 初始思路 二叉搜索树高度平衡,意味着左右子树的高度要平衡.根据二叉树左子树节点小于根节点,右子树节点大于根节点的性质:我 ...
- Java for LeetCode 109 Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
随机推荐
- Python GIL(Global Interpreter Lock)
一.介绍 In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threa ...
- javascript创建函数的20种方式汇总
http://www.jb51.net/article/68285.htm 工作中常常会创建一个函数来解决一些需求问题,以下是个人在工作中总结出来的创建函数20种方式,你知道多少? function ...
- 2、ansilbe常用模块详解及inventory介绍
Ansible ansible格式: ansible <host-pattern> [-f forks] [-m module_name] [-a args] args: 用法 key=v ...
- SqlParameter 多个参数动态拼接解决参数化问题
多个参数化是固定比较easy,多个动态的就有点...工作中遇到的问题整理下来分享 ,上代码 SqlParameter[] param = new SqlParameter[] { }; List< ...
- Node前后端分离基本概括
首先从一个重要的概念“模板”说起. 广义上来说,web中的模板就是填充数据后可以生成文件的页面. 严格意义上来说,应该是模板引擎利用特定格式的文件和所提供的数据编译生成页面.模板大致分为前端模板(如e ...
- 【BZOJ】3142: [Hnoi2013]数列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3142 12年也有一个组合数学...(这几年的画风啊.... 考虑直接去做:DP? DP+容 ...
- CPU核数和load average的关系
在前面的文章<Linux系统监控——top命令>中我简单提到了,判断load average的数值到底大不大的判断依据,就是数值除以CPU核数,大于5,就说明超负荷运转了.——这里其实不太 ...
- mt19937 -- 高质量随机数
优点:产生速度快, 周期大 用法: #include<bits/stdc++.h> using namespace std; int main() { mt19937 mt_rand(ti ...
- lua --- 函数的本质
1.lua中的函数是带有此法界定的第一类值. 2.创建一个函数的过程,本质上就是一个创建赋值语句的过程. 常见的创建函数的过程: function fun() print("Hello wo ...
- nginx反向代理实例
通过一个例子演示一下nginx是如何代理服务的,并且讲一下nginx.conf的关于server模块和location模块的配置 server模块:配置虚拟主机的相关参数,一个http中可以有多个se ...