fork download
  1. /**
  2.  * Definition for singly-linked list.
  3.  * struct ListNode {
  4.  * int val;
  5.  * ListNode *next;
  6.  * ListNode(int x) : val(x), next(NULL) {}
  7.  * };
  8.  */
  9. ListNode* Solution::reverseBetween(ListNode* A, int B, int C) {
  10. int m = B, n = C, N = 0;
  11.  
  12. ListNode *a = A;
  13. while(a != 0){
  14. N++;
  15. a = a->next;
  16. }
  17.  
  18.  
  19. ListNode **nodeAtIdx = new ListNode *[N];
  20. a = A;
  21. for(int i = 0; i < N; i++){
  22. nodeAtIdx[i] = a;
  23. a = a->next;
  24. cout << "node" << endl;
  25. }
  26.  
  27. int j = 0;
  28. for(int i = m - 1; i < (m + n) / 2; i++, j++){
  29. a = nodeAtIdx[i];
  30. ListNode *b = nodeAtIdx[n - j - 1];
  31.  
  32. cout << "i: " << i << endl;
  33. cout << "a: " << a->val << endl;
  34. cout << "b: " << b->val << endl;
  35.  
  36. int tmp = a->val;
  37. a->val = b->val;
  38. b->val = tmp;
  39. }
  40.  
  41. return A;
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:1: error: ‘ListNode’ does not name a type
 ListNode* Solution::reverseBetween(ListNode* A, int B, int C) {
 ^~~~~~~~
stdout
Standard output is empty