心情还是有问题,保持每日更新,只能如此了。

Problem

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

Example:

Given binary tree {,,,#,#,,},

····
/ \ / \ Result return its level order traversal as: [
[],
[,],
[,]
]
Code /**
* 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:
int HeightOfTree(TreeNode* root) {
int result = ;
if (root == NULL) {
return result;
}
int left = HeightOfTree(root->left) + ;
int right = HeightOfTree(root->right) + ;
result = left > right ? left : right;
return result;
}
void calLevelOrder(TreeNode* root, int level, vector<vector<int> >& result) {
if (root == NULL) {
return;
}
result[level].push_back(root->val);
calLevelOrder(root->left, level + , result);
calLevelOrder(root->right, level + , result);
}
vector<vector<int> > levelOrder(TreeNode* root) {
vector<vector<int> > result;
vector<int> v;
if (root == NULL) {
return result;
}
int height = HeightOfTree(root);
for (int i = ; i < height; i++) {
result.push_back(v);
}
calLevelOrder(root, , result);
return result;
}
};
Problem1

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

Code

class Solution {
public:
string reverseString(string s) {
if (s.size() &lt;= ) {
return s;
}
int i = , j = s.size() - ;
char ch;
while (i &lt; j) {
ch = s[i];
s[i] = s[j];
s[j] = ch;
i++;
j--;
}
return s;
}
};
Problem2 Write a function that takes a string as input and reverse only the vowels of a string. Example : Given s = "hello", return "holle". Example : Given s = "leetcode", return "leotcede". Code class Solution {
public:
string reverseVowels(string s) {
if (s.size() &lt;= ) {
return s;
}
int i = , j = s.size() - ;
char ch;
while (i &lt; j) {
while(i &lt; j && s[i] != &#;a&#; && s[i] != &#;e&#; && s[i] != &#;i&#; && s[i] != &#;o&#; && s[i] != &#;u&#;
&& s[i] != &#;A&#; && s[i] != &#;E&#; && s[i] != &#;I&#; && s[i] != &#;O&#; && s[i] != &#;U&#;) {
i++;
}
while(i &lt; j && s[j] != &#;a&#; && s[j] != &#;e&#; && s[j] != &#;i&#; && s[j] != &#;o&#; && s[j] != &#;u&#;
&& s[j] != &#;A&#; && s[j] != &#;E&#; && s[j] != &#;I&#; && s[j] != &#;O&#; && s[j] != &#;U&#;) {
j--;
}
ch = s[i];
s[i] = s[j];
s[j] = ch;
i++;
j--;
}
return s;
}
};
说明 与上面同样的逻辑,只是出现特定的字符才交换位置

PS:存货快用完了。。。。

leetcode简单题目两道(4)的更多相关文章

  1. leetcode简单题目两道(2)

    Problem Given an integer, write a function to determine if it is a power of three. Follow up: Could ...

  2. leetcode简单题目两道(3)

    本来打算写redis的,时间上有点没顾过来,只能是又拿出点自己的存货了. Problem Given an array nums, write a function to move all 's to ...

  3. leetcode简单题目两道(5)

    Problem Given an integer (signed bits), write a function to check whether it . Example: Given num = ...

  4. leetcode简单题目两道(1)

    Problem: You are playing the following Nim Game with your friend: There is a heap of stones on the t ...

  5. CTF中关于XXE(XML外部实体注入)题目两道

    题目:UNCTF-Do you like xml? 链接:http://112.74.37.15:8008/ hint:weak password (弱密码) 1.观察后下载图片拖进WINHEX发现提 ...

  6. 两道面试题,带你解析Java类加载机制

    文章首发于[博客园-陈树义],点击跳转到原文<两道面试题,带你解析Java类加载机制> 在许多Java面试中,我们经常会看到关于Java类加载机制的考察,例如下面这道题: class Gr ...

  7. 【转】两道面试题,带你解析Java类加载机制(类初始化方法 和 对象初始化方法)

    本文转自 https://www.cnblogs.com/chanshuyi/p/the_java_class_load_mechamism.html 关键语句 我们只知道有一个构造方法,但实际上Ja ...

  8. 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester

    这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...

  9. 你所不知道的库存超限做法 服务器一般达到多少qps比较好[转] JAVA格物致知基础篇:你所不知道的返回码 深入了解EntityFramework Core 2.1延迟加载(Lazy Loading) EntityFramework 6.x和EntityFramework Core关系映射中导航属性必须是public? 藏在正则表达式里的陷阱 两道面试题,带你解析Java类加载机制

    你所不知道的库存超限做法 在互联网企业中,限购的做法,多种多样,有的别出心裁,有的因循守旧,但是种种做法皆想达到的目的,无外乎几种,商品卖的完,系统抗的住,库存不超限.虽然短短数语,却有着说不完,道不 ...

随机推荐

  1. 提问的智慧——其实你真的不会提问!(转)

    在黑客世界里,当提出一个技术问题时,你能得到怎样的回答?这取决于挖出答案的难度,同样取决于你提问的方法.本指南旨在帮助你提高发问技巧,以获取你最想要的答案.       首先你必须明白,黑客们只偏爱艰 ...

  2. 使用pscp/pslurp批量并发分发/回收文件

    pssh pssh -h ip文件 本地文件 远程目录或文件 pslurp pslurp -h ip文件 -L 本地目录 远程文件 本地文件名称

  3. 用jquery-table2excel,进行导出excel

    jquery-table2excel是一款可以将HTML表格的内容导出到微软Excel电子表格中的jQuery插件.该插件可以根据你的需要导出表格中的内容,不需要的行可以不导出. 它文件体积小,使用非 ...

  4. ES6——Symbol数据类型

    什么是 Symbol ? Symbol 表示独一无二的值,他是js中的 第七种数据类型. 基本的数据类型:null, undefined number boolean string symbol 引用 ...

  5. WP8.1StoreApp(WP8.1RT)---本地Toast

    WP7/8中的Toast是不能在前台弹出的. WP8.1StoreApp可以利用Win8中的方式: private void Toast(string title,string content) { ...

  6. ubuntu 关闭和开启防火墙

    1.关闭ubuntu的防火墙 ufw disable 2开启防火墙 ufw enable 3.卸载了iptables apt-get remove iptables 4.关闭ubuntu中的防火墙的其 ...

  7. leecode刷题(18)-- 报数

    leecode刷题(18)-- 报数 报数 描述: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 1112 ...

  8. jquery源码解析:jQuery数据缓存机制详解1

    jQuery中有三种添加数据的方法,$().attr(),$().prop(),$().data().但是前面两种是用来在元素上添加属性值的,只适合少量的数据,比如:title,class,name等 ...

  9. 使用java执行ffmpeg命令进行推流操作

    视频网站中提供的在线视频播放功能,播放的都是FLV格式的文件,它是Flash动画文件,可通过Flash制作的播放器来播放该文件.项目中用制作的player.swf播放器. 多媒体视频处理工具FFmpe ...

  10. Oracle的常用修改表及字段的语句

    单行注释:-- 多行注释:/* */ Oracle中修改表结构 增加字段     ALTER TABLE table_name ADD column_name data_type; 删除字段     ...