LeetCode | Reverse Words in a String(C#)
题目:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
代码:
public static string reverseWords(string str)
{
string reverStr = "";
int count = ;
Stack stack1 = new Stack();
Stack stack2 = new Stack();
foreach (var item in str)
{
if(item==' ')
{
stack1.Push(item);
count = stack1.Count;
for (int i = ; i < count; i++)
{
stack2.Push(stack1.Pop());
}
}
else
{
stack1.Push(item);
}
}
stack2.Push(' ');
count = stack1.Count;
for (int i = ; i < count; i++)
{
stack2.Push(stack1.Pop());
}
count = stack2.Count - ;
for (int i = ; i < count; i++)
{
reverStr = reverStr + stack2.Pop().ToString();
}
return reverStr;
}
LeetCode | Reverse Words in a String(C#)的更多相关文章
- leetcode345——Reverse Vowels of a String(C++)
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- 345. Reverse Vowels of a String(C++)
345. Reverse Vowels of a String Write a function that takes a string as input and reverse only the v ...
- LeetCode 345. Reverse Vowels of a String(双指针)
题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...
- LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation
LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation Evaluate the value of an arithm ...
- 【LeetCode】150. Evaluate Reverse Polish Notation 解题报告(Python)
[LeetCode]150. Evaluate Reverse Polish Notation 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/ ...
- LeetCode刷题总结-数组篇(下)
本期讲O(n)类型问题,共14题.3道简单题,9道中等题,2道困难题.数组篇共归纳总结了50题,本篇是数组篇的最后一篇.其他三个篇章可参考: LeetCode刷题总结-数组篇(上),子数组问题(共17 ...
- Swift2.0 中的String(二):基本操作
Swift中的字符串,第二篇,基本操作.其他的几篇传送门(GitHub打不开链接的同学请自行把地址github改成gitcafe,或者直接去归档里找:-P): Swift2.0 中的String(一) ...
- LeetCode刷题总结-数组篇(上)
数组是算法中最常用的一种数据结构,也是面试中最常考的考点.在LeetCode题库中,标记为数组类型的习题到目前为止,已累计到了202题.然而,这202道习题并不是每道题只标记为数组一个考点,大部分习题 ...
- Leetcode 943. Find the Shortest Superstring(DP)
题目来源:https://leetcode.com/problems/find-the-shortest-superstring/description/ 标记难度:Hard 提交次数:3/4 代码效 ...
随机推荐
- H3C交换机端口安全技术之端口隔离的应用
H3C交换机端口安全技术---端口隔离的应用 相信大家所在公司都会有财务部门,普通员工和领导,网络工程师在配置的时候为了安全考虑,会用一些硬件上自身支持的功能区做一些安全措施.为了方便说明需求,我特意 ...
- Oracle——环比增长率
首先,了解什么是:环比增长率? 环比增长率=(本期数-上期数)÷上期数×100% 如:2014年2月的工资为:5000,2014年1月的工资为4000,则2月份的环比增长率为: (5000-4000) ...
- string字符串js操作
String 对象方法 方法 描述 anchor() 创建 HTML 锚. big() 用大号字体显示字符串. blink() 显示闪动字符串. bold() 使用粗体显示字符串. charAt() ...
- Mac下压力测试工具siege
安装: brew install siege 用法: siege -c 并发数 -t 运行测试时间 URL 如: siege -c 1000 -t 5S URL 这里要注意的是-t后面的时间要带单位, ...
- D - Maximizing Advertising
题目链接:https://cn.vjudge.net/contest/250168#problem/D 题目大意:给你一些点的坐标,这些点属于两个帮派,让你将这些点分进两个不能重叠的矩形中,问你最多两 ...
- web前端最全各类资源
链接:http://www.sohu.com/a/157593700_132276
- SpringMVC与Struts不同(五)
springmvc与struts2不同 1.springmvc的入口是一个servlet即前端控制器,而struts2入口是一个filter过滤器. 2.springmvc是基于方法开发(一个url对 ...
- SpringBoot拦截器的注册
(1).编写拦截器 package cn.coreqi.config; import org.springframework.util.StringUtils; import org.springfr ...
- C++学习2--坦克大战编写-前置知识
基础班学习的这一个多月里的前三周讲解基础的语法,最后一周需要做坦克大战的项目巩固提高自己掌握的语法知识.这个系列博文主要是为了把学习过程中的知识点总结并记录下来: 开发语言与开发工具:C++,VS20 ...
- MR室内室外用户区分
mro_view_details_year中v3字段 1:室外用户 0:室内用户 主小区是室内站 主小区信号>-90dBm ==> 室内 主小区信号>-100dBm &&am ...