I have finished the problems in this contest. However, I cannot find my code in the contest page today. Who knows how to find the code in contest?
W
wcwswswws
@wcwswswws
1
Reputation
3
Posts
85
Profile views
0
Followers
0
Following
Posts made by wcwswswws

Where can find my code in this contest?

TLE in {3,2,0,4}, tail connects to node index 1
Here is my code:
/** * Definition for singlylinked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *checkCircle(ListNode *h) { if (h>next==NULL) return NULL; if (h>next==h) return h; ListNode *tmp=h>next; h>next=h; return checkCircle(tmp); } ListNode *detectCycle(ListNode *head) { if (head==NULL) return NULL; return checkCircle(head); } };
It will change the next to point to itself, and the program will write node when it finds the node which next points to itself. Please help.

A strange problem.
The following code can get Accepted:
class Solution { public: int removeDuplicates(int A[], int n) { int m=0; if (n==0) return 0; for (int i=0;i<n;i++) { int j=i; while ((i+1<n)&&(A[i+1]==A[i])) i++; if (i!=j) m+=2; else m++; } int k=0; for (int i=0;i<n;i++) { int j=i; while ((i+1<n)&&(A[i+1]==A[i])) i++; if (i!=j) {A[k]=A[k+1]=A[j];k+=2;} else A[k++]=A[j]; } //free(A+m); return m; } };`
But the following code would get RE
class Solution { public: int removeDuplicates(int A[], int n) { int m=0; if (n==0) return 0; for (int i=0;i<n;i++) { int j=i; while ((i+1<n)&&(A[i+1]==A[i])) i++; if (i!=j) m+=2; else m++; } int *B=(int*)malloc(m*sizeof(int)); int k=0; for (int i=0;i<n;i++) { int j=i; while ((i+1<n)&&(A[i+1]==A[i])) i++; if (i!=j) {B[k]=B[k+1]=A[j];k+=2;} else B[k++]=A[j]; } free(A); A=B; return m; } };
The difference is whether using the extra array B. Please help.