qingcheng奕  
02 2014 档案
  • Python学习笔记
    摘要:输入 str1 = raw_input("Plz input a string:")输出 print(str1)print(5)print(12.5)print('H')print('wwww' )print x , y , zhelp(raw_input)变量:可变化数据的程序标识符,指向某个数据单元,通过赋值可以改变其指向(而不是上一个单元里的数据),指向内存单元的变,类似C中的指针。不分数据类型,指向什么样的就算是什么类型的变量。id(x)打出x指向的单元的地址字符函数库:help(str) s = "Python" 阅读全文
    posted @ 2014-02-21 10:40 qingcheng奕 阅读(317) 评论(0) 推荐(0)
  • LeetCode OJ--Binary Tree Level Order Traversal II
    摘要:http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/树的层序遍历,和上一道题相比,对结果做一个顺序调整 reverse()/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {p... 阅读全文
    posted @ 2014-02-15 12:46 qingcheng奕 阅读(148) 评论(0) 推荐(0)
  • LeetCode OJ--Binary Tree Level Order Traversal
    摘要:http://oj.leetcode.com/problems/binary-tree-level-order-traversal/树的层序遍历,使用队列由于树不是满的,还要分出每一层来,刚开始给缺少的节点用dummy节点代替,结果超时了。vector > levelOrder(TreeNode *root) { vector > ans; if(root == NULL) return ans; int num = 1,num2 = 1; queue myQueue; myQueue.push(roo... 阅读全文
    posted @ 2014-02-15 12:27 qingcheng奕 阅读(155) 评论(0) 推荐(0)
  • LeetCode OJ--Binary Tree Postorder Traversal
    摘要:http://oj.leetcode.com/problems/binary-tree-postorder-traversal/树的后序遍历,可以使用递归,也可以使用栈,下面是栈的实现代码#include #include #include using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution {public: vec... 阅读全文
    posted @ 2014-02-15 11:08 qingcheng奕 阅读(155) 评论(0) 推荐(0)
  • LeetCode OJ--Binary Tree Preorder Traversal
    摘要:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/二叉树的先跟遍历,写的是递归版本,也可以使用stack来进行,替代了递归函数。class Solution {public: void preOrder(TreeNode *root,vector &ans) { ans.push_back(root->val); if(root->left) preOrder(root->left,ans); if(root->right) pr... 阅读全文
    posted @ 2014-02-15 09:48 qingcheng奕 阅读(134) 评论(0) 推荐(0)
  • LeetCode OJ--Evaluate Reverse Polish Notation
    摘要: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奕 阅读(161) 评论(0) 推荐(0)
  • LeetCode OJ--Valid Parentheses
    摘要: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奕 阅读(172) 评论(0) 推荐(0)
  • LeetCode OJ--Implement strStr()
    摘要: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奕 阅读(152) 评论(0) 推荐(0)
  • LeetCode OJ--Valid Palindrome
    摘要: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奕 阅读(133) 评论(0) 推荐(0)
  • LeetCode OJ--Remove Duplicates from Sorted List II *
    摘要: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奕 阅读(154) 评论(0) 推荐(0)
  • LeetCode OJ--Partition List
    摘要:http://oj.leetcode.com/problems/partition-list/链表的处理#include using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: ListNode *partition(ListNode *head, int x) { ListNode *head1 = NULL,*head2 = NULL,*tai... 阅读全文
    posted @ 2014-02-13 22:17 qingcheng奕 阅读(144) 评论(0) 推荐(0)
  • LeetCode OJ--Reverse Linked List II
    摘要:http://oj.leetcode.com/problems/reverse-linked-list-ii/链表的操作#include using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { ListNode dummy(-1); ... 阅读全文
    posted @ 2014-02-13 17:57 qingcheng奕 阅读(143) 评论(0) 推荐(0)
  • LeetCode OJ--3Sum **
    摘要:http://oj.leetcode.com/problems/3sum/找出三个数的和是0的元组.class Solution {public: vector > threeSum(vector &num) { vector > ans; if(num.size()0) break; if(num[i]+num[j]+num[num.size()-1] onePiece; onePiece.push_back(num[... 阅读全文
    posted @ 2014-02-13 13:27 qingcheng奕 阅读(321) 评论(0) 推荐(0)
  • LeetCode OJ--Search in Rotated Sorted Array II
    摘要:http://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/如果在数组中有重复的元素,则不一定说必定前面或者后面的一半是有序的,所以有个while循环的处理。#include using namespace std; class Solution {public: bool binarySearch(int A[],int target,int begin,int end) { int mid = (begin+end)/2; if(target == A[mid]) ... 阅读全文
    posted @ 2014-02-12 17:33 qingcheng奕 阅读(138) 评论(0) 推荐(0)
  • LeetCode OJ--Search in Rotated Sorted Array
    摘要:http://oj.leetcode.com/problems/search-in-rotated-sorted-array/转换了一次的有序数组,进行类似二分查找。从begin到mid和从mid到end,二者中肯定有一个是有序的。#include using namespace std; class Solution {public: int binarySearch(int A[],int target,int begin,int end) { int mid = (begin+end)/2; if(target == A[mid]) ... 阅读全文
    posted @ 2014-02-12 16:39 qingcheng奕 阅读(122) 评论(0) 推荐(0)
  • LeetCode OJ--Remove Duplicates from Sorted Array II
    摘要:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/要求可以用重复元素,但是最大重复次数为两次。#include using namespace std;class Solution {public: int removeDuplicates(int A[], int n) { if(n == 0) return 0; if(n == 1) return 1; int times = 1; int p... 阅读全文
    posted @ 2014-02-12 15:01 qingcheng奕 阅读(128) 评论(0) 推荐(0)
  • LeetCode OJ--Remove Duplicates from Sorted Array
    摘要:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/删除数组中的重复元素,要求为原地算法。进行一遍遍历,记录下一个可用位置,也就是用来存储不重复元素的位置。class Solution {public: int removeDuplicates(int A[], int n) { if(n == 0) return 0; if(n == 1) return 1; int preOne = A[0]; int... 阅读全文
    posted @ 2014-02-12 14:41 qingcheng奕 阅读(128) 评论(0) 推荐(0)