算法
c1rew
这个作者很懒,什么都没留下…
展开
-
算法(字符串移动,单词翻转)
题目1:题目2:输入一个英文句子,番句子中单词的顺序,但单词内字符的顺序不变。句子中单词以空格符隔开。句子中标点符号和普通字母一样处理。例如输入“I am a student.”,则输出“student. a am I”。解决方法:先将整个句子翻转,再将其中的每个单词翻转参考:程序员编程艺术:第一章、左旋转字符串原创 2014-12-15 16:48:17 · 600 阅读 · 0 评论 -
[Leetcode]7.Reverse Integer
class Solution {public: int reverse(int x) { bool isPositive = true; if (x == INT_MIN || x == INT_MAX) return 0; if (x < 0) { isPositive = false;原创 2015-04-07 01:12:47 · 323 阅读 · 0 评论 -
[Leetcode] 27.Remove Element
class Solution {public: int removeElement(int A[], int n, int elem) { int j = 0; for (int i = 0; i < n; i++) { if(A[i] == elem) { continue;原创 2015-04-12 09:19:58 · 325 阅读 · 0 评论 -
[Leetcode] 100. Same Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solutio原创 2015-04-12 09:49:03 · 385 阅读 · 0 评论 -
[Leetcode] 189.Rotate Array
class Solution {public: void rotate(int nums[], int n, int k) { k %= n; reverse(nums, n-k, n-1); reverse(nums, 0, n-k-1); reverse(nums, 0, n-1); } void rever原创 2015-04-12 11:34:34 · 362 阅读 · 0 评论 -
[Leetcode] 1. Two Sum
class Solution {public: vector<int> twoSum(vector<int> &numbers, int target) { int vSize = numbers.size(); vector<int> vIndex; map<int,int> mapNum; int index;原创 2015-04-12 15:53:26 · 409 阅读 · 0 评论