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 代码效 ...
随机推荐
- javascript 模拟日历
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mybatis在控制台打印sql语句
1:mybatis-config.xml中配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTY ...
- error: control may reach end of non-void function [-Werror,-Wreturn-type]
编译出现如下错误 error: control may reach end of non-void function [-Werror,-Wreturn-type] 这个错误可能和编译器有关(在相同代 ...
- Java SE之 Eclipse错误: 找不到或无法加载主类或项目无法编译10种解决大法!【摘抄】
声明一下:此BUG确实经常困扰我许久,今日遇到很强大的一套解决办法,又怕原博主的网页以后查找不到,故此摘抄copy一份,望得各方侵权一事而谅解. 传送门先行送上:http://blog.csdn.ne ...
- 第5月第7天 php slim
1. <?php require 'Slim/Slim.php'; require 'DBManagement.php'; \Slim\Slim::registerAutoloader(); $ ...
- sonarqube6.7安装
1.下载sonarhttps://www.sonarqube.org/#downloads 2.配置JDK1.8 3.centOS默认mysql版本为mariaDB直接安装yum install my ...
- snmp 发送类型ASN_OBJECT_ID
参考链接: http://blog.csdn.net/yin138/article/details/50388878 ,,,,,,,,,}; int ret = snmp_set_var_typed_ ...
- plist反序列化
// // ViewController.m // 03-plist文件的一个反序列化 // // Created by jerry on 15/9/28. // Copyright (c) ...
- Struts通配符映射
- Linux MMC framework2:基本组件之core
1.前言 本文主要core组件的主要流程,在介绍的过程中,将详细说明和core相关的流程,涉及到其它组件的详细流程再在相关文章中说明. 2.主要数据结构和API TODO 3. 主要流程 3.1 mm ...