摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.class Solution {public: int removeElement(int A[], int n, int elem) { // Start typing your C/C++ so... 阅读全文
posted @ 2013-05-18 17:51 NinaGood 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 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-/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} 阅读全文
posted @ 2013-05-18 16:31 NinaGood 阅读(119) 评论(0) 推荐(0) 编辑
摘要: #include<stack>class Solution {public: bool isValid(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = s.size(); if( len == 0 ) { return false; } stack<char> my_sta... 阅读全文
posted @ 2013-05-18 14:37 NinaGood 阅读(600) 评论(0) 推荐(0) 编辑
摘要: void function( int a[],int N){ int * s = new int[N+1]; int * t = new int[N+1]; int * p = new int[N]; s[0]=t[N]=1; for(int i =1; i < N+1 ; i++ ) { s[i]=s[i-1]*a[i-1]; } for( int i =N-1; i>=0; --i) { t[i] = a[i]*t[i+1]; } p[0]=t[1]; for( int i = 1; i < N ; i++) { p[i]=s[i-1]*t[i+1]; } int max 阅读全文
posted @ 2013-05-15 09:10 NinaGood 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 思路:首先按顺序将数组中相邻的两个数分在同一组中(这只是概念上的分组,无需做任何事)。然后可以利用两个变量Max和Min来存储当前的最大值和最小值。同一组的两个数比较之后,不再调整顺序,而是将其中的较小的数与当前的Min来比较,如果比Min小的话更新Min,将其中较大的数与Max 比较,如果比Max大的话更新Max。void Max_Min( int a[],int n){ int Max,Min; int i=0,j=1; if( a[i] < a[j]) { Min = a[i]; Max=a[j]; } else { Min=a[j]; Max=a[i]; } i += 2; .. 阅读全文
posted @ 2013-05-14 20:08 NinaGood 阅读(243) 评论(0) 推荐(0) 编辑
摘要: void merge(int A[], int m, int B[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int i,j; if( m==0 && n!=0 ) { for(int k = 0; k < n; k++ ) { A[k]=B[k]; } ... 阅读全文
posted @ 2013-05-13 21:54 NinaGood 阅读(268) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below // DO NOT wr... 阅读全文
posted @ 2013-05-12 21:32 NinaGood 阅读(132) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int atoi(const char *str) { // Start typing your C/C++ solution below // DO NOT write int main() function int flag = 0; int plus=0; bool tozero=false; int sum = 0; int sum_num=0; for( const char *p = str; *p != '\0'... 阅读全文
posted @ 2013-05-09 15:24 NinaGood 阅读(178) 评论(0) 推荐(0) 编辑
摘要: http://chuanwang66.iteye.com/blog/1704942 阅读全文
posted @ 2013-05-03 20:50 NinaGood 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 内存泄露:内存泄漏(memory leak)指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况。内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,失去了对该段内存的控制,因而造成了内存的浪费。简单例子:#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>int main(){ _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_ST 阅读全文
posted @ 2013-04-20 13:29 NinaGood 阅读(219) 评论(0) 推荐(0) 编辑