题目:

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. JUnit报错 java.lang.Exception:No tests found matching

    将 @RunWith(SpringRunner.class)@SpringBootTestpublic class BusinessTest { @Test public void getList() ...

  2. 【JUC】JDK1.8源码分析之CyclicBarrier

    一.前言 有了前面分析的基础,现在,接着分析CyclicBarrier源码,CyclicBarrier类在进行多线程编程时使用很多,比如,你希望创建一组任务,它们并行执行工作,然后在进行下一个步骤之前 ...

  3. AWT和Swing的关系

    1.AWT和Swing都是java中的包. 2.AWT(Abstract Window Toolkit):抽象窗口工具包,早期编写图形界面应用程序的包,AWT是通过调用操作系统的native方法实现的 ...

  4. 逆向安全基础之IDA使用简介

    转载:http://m.blog.csdn.net/ilnature2008/article/details/54912854 IDA简介 IDA是业界一个功能十分强大的反汇编工具,是安全渗透人员进行 ...

  5. [C++]埃拉托色尼算法

     /* 埃拉托色尼算法  问题描述:定义一个正整数n,求0-n范围以内的所有质数  @date 2017-03-06 @author Johnny Zen   */  #include<iost ...

  6. c#将前端传来的Json解析成对象

    描述:因工作中需要将C#中的Json字符串转换为对象,对此记录下. 解决办法: 1.前端传过来的Json字符串,OrderAppModuleJson即前端传递到后端的Json字符串 string st ...

  7. python 入门基础24 元类、单例模式

    内容目录: 一.元类 二.单例模式 一.元类 1 什么是元类: 源自一句话:在python中,一切皆对象,而对象都是由类实例化得到的 class OldboyTeacher: def __init__ ...

  8. 文加图, 理解Http请求与响应

    1. http请求和响应步骤 在讲解OkHttp之前, 我们首先来个高清大图, 看下http请求的整个步骤, 有个整体概念.  2. http每一步详细内容 在一次完整的HTTP通信过程中, Web浏 ...

  9. vlc-android 的编译过程

    参考官方文档:https://wiki.videolan.org/AndroidCompile#Get_VLC_Source 值得注意的的地方: 1.切记安装以下工具 sudo apt-get ins ...

  10. 【vim】缩写 :ab [缩写] [要替换的文字]

    一个很可能是最令人印象深刻的窍门是你可以在 Vim 中定义缩写,它可以实时地把你输入的东西替换为另外的东西.语法格式如下: :ab [缩写] [要替换的文字] 一个通用的例子是: :ab asap a ...