题目:

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#)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. LeetCode 345. Reverse Vowels of a String(双指针)

    题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...

  4. 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 ...

  5. 【LeetCode】150. Evaluate Reverse Polish Notation 解题报告(Python)

    [LeetCode]150. Evaluate Reverse Polish Notation 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/ ...

  6. LeetCode刷题总结-数组篇(下)

    本期讲O(n)类型问题,共14题.3道简单题,9道中等题,2道困难题.数组篇共归纳总结了50题,本篇是数组篇的最后一篇.其他三个篇章可参考: LeetCode刷题总结-数组篇(上),子数组问题(共17 ...

  7. Swift2.0 中的String(二):基本操作

    Swift中的字符串,第二篇,基本操作.其他的几篇传送门(GitHub打不开链接的同学请自行把地址github改成gitcafe,或者直接去归档里找:-P): Swift2.0 中的String(一) ...

  8. LeetCode刷题总结-数组篇(上)

    数组是算法中最常用的一种数据结构,也是面试中最常考的考点.在LeetCode题库中,标记为数组类型的习题到目前为止,已累计到了202题.然而,这202道习题并不是每道题只标记为数组一个考点,大部分习题 ...

  9. Leetcode 943. Find the Shortest Superstring(DP)

    题目来源:https://leetcode.com/problems/find-the-shortest-superstring/description/ 标记难度:Hard 提交次数:3/4 代码效 ...

随机推荐

  1. 函数和常用模块【day06】:configparser模块(七)

    本节内容 1.简述 2.配置文件格式 3.创建配置文件 4.读取配置文件 5.增删该查语法 一.简述 在很多情况下,我们都需要修改配置文件,但是,有些配置文件,如mysql数据库的配置文件怎么修改呢? ...

  2. 百度编辑器 Ueditor 如何增加模板 ?

    模板文件在这里: dialogs/template/config.js 参见:http://t.mreald.com/191 .

  3. C#窗口防止闪烁两种方法

    public class PaintIncrease { public static void SetDoubleBuffered(object obj) { Type type = obj.GetT ...

  4. 尚硅谷spring_boot课堂笔记

    尚硅谷spring_boot课堂笔记

  5. MIPS指令学习二

    1.MIPS寻址方式 MIPS架构的寻址模式有寄存器寻址.立即数寻址.寄存器相对寻址和PC相对寻址4种,其中寄存器相对寻址.PC相对寻址介绍如下: 1.1.寄存器相对寻址 这种寻址模式主要被加载/存储 ...

  6. java 多线程断点下载功能

    import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.Rand ...

  7. WEB 服务器 加速缓存比较

    Nginx 相对 Apache httpd 的优点: - 轻量级,同样起web 服务,比apache 占用更少的内存及资源 - 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的 ...

  8. QToolButton按钮

    继承 QAbstractButton QToolButton是与工具操作相关的按钮,通常和QToolBar搭配使用.QToolButton一般不用来显示文本,而显示图标QIcon 需要  from P ...

  9. 安卓中location.href或者location.reload 不起作用

    链接:https://www.cnblogs.com/joshua317/p/6163471.html 在移动wap中,经常会使用window.location.href去跳转页面,这个方法在绝大多数 ...

  10. Java9都快发布了,Java8的十大新特性你了解多少呢?

    Java 9预计将于今年9月份发布,这是否会是一次里程碑式的版本,我们拭目以待.今天,我们先来复习一下2014年发布的Java 8的十大新特性. Java 8可谓是自Java 5以来最具革命性的版本了 ...