比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,只要注意各种极端情况即可,不明白通过率为什么只有13%。
#include
#include
using namespace std;
class Solution {
public:
void reverseWords(string &s) {
char* cstr = new char[s.size()+1];
...
分类:
其他好文 时间:
2014-06-05 03:45:47
阅读次数:
221
计算逆波兰表达式,了解更多关于逆波兰表达式请点击。
计算逆波兰表达式这是个很典型的栈应用的例子。
解题方法就是用栈来处理,需要注意的是本题输入给的是字符串数组,所以需要在字符串和整数之间有个转换。...
分类:
其他好文 时间:
2014-06-04 14:06:18
阅读次数:
318
Emag eht htiw Em PlehDescriptionThis problem is
a reverse case of the problem 2996. You are given the output of the problem H
and your task is to find...
分类:
其他好文 时间:
2014-06-03 15:33:20
阅读次数:
347
原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/题意:Given
an input string, reverse the string word by word.For example,Given s = "the s...
分类:
编程语言 时间:
2014-06-03 11:13:36
阅读次数:
258
Reverse Words in a String
Total Accepted: 15012 Total
Submissions: 108513My Submissions
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",...
分类:
其他好文 时间:
2014-06-02 05:34:14
阅读次数:
214
递归一下
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
Li...
分类:
其他好文 时间:
2014-06-01 17:35:40
阅读次数:
406
You are given two linked lists representing two
non-negative numbers. The digits are stored in reverse order and each of their
nodes contain a single ...
分类:
其他好文 时间:
2014-06-01 17:05:44
阅读次数:
296
【题目】
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
【题意】
...
分类:
其他好文 时间:
2014-06-01 15:08:34
阅读次数:
237
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is...
分类:
其他好文 时间:
2014-06-01 09:05:42
阅读次数:
271