qingcheng奕  

2014年2月14日

摘要: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/栈使用#include #include #include #includeusing namespace std;class Solution {public: int toNum(string str) { int sum = 0; int i = 0; int flagPositiveOrNegative = 1;; if(str[0] == '-') { ... 阅读全文
posted @ 2014-02-14 21:24 qingcheng奕 阅读(155) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/valid-parentheses/对栈的考察,看括号的使用方式是否合法。class Solution {public: bool isValid(string s) { if(s.empty() || s == "") return true; if(s.size()%2!= 0) return false; int i = 0; stack myStack; while(i!=s.size()) ... 阅读全文
posted @ 2014-02-14 20:48 qingcheng奕 阅读(167) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/implement-strstr/判断一个串是否为另一个串的子串比较简单的方法,复杂度为O(m*n),另外还可以用KMP时间复杂度为O(m+n),之前面试的时候遇到过。class Solution {public: bool isEqual(char *a,char *b) { char* chPointer = a; char* chPointer2 = b; while(*chPointer2!= '\0' && *chPointer!='\0' ) { ... 阅读全文
posted @ 2014-02-14 15:40 qingcheng奕 阅读(145) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/valid-palindrome/判断是否为回文串 bool isPalindrome(string s) { int i = 0,j = s.length() -1; int flag = 0; if(s=="") return true; while(i= '0'&&s[i]= '0'&&s[j]<='9') || s[j] == ' ') { if(j==0) ... 阅读全文
posted @ 2014-02-14 11:04 qingcheng奕 阅读(128) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/处理链表的范例#include using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if(head == NULL)... 阅读全文
posted @ 2014-02-14 10:08 qingcheng奕 阅读(148) 评论(0) 推荐(0) 编辑