Skip to content

Commit 1692022

Browse files
authored
Add 1310_XOR_Queries_of_a_Subarray (qiyuangong#22)
* Add 206_Reverse_Linked_List CPP solution * Add 1310_XOR_Queries_of_a_Subarray Python Solution by @ruchit2801
1 parent 417ccfd commit 1692022

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cpp/206_Reverse_Linked_List.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
class Solution {
10+
public:
11+
ListNode* reverseList(ListNode* head) {
12+
if(head==NULL)return NULL;
13+
if(head->next==NULL) return head;
14+
ListNode* p=head;
15+
ListNode* c=head->next;
16+
head->next=NULL;
17+
while(c->next){
18+
ListNode* n = c->next;
19+
c->next=p;
20+
p=c;
21+
c=n;
22+
}
23+
c->next=p;
24+
return c;
25+
}
26+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
3+
pref = [0]
4+
for e in arr:
5+
pref.append(e ^ pref[-1])
6+
ans = []
7+
for [l, r] in queries:
8+
ans.append(pref[r+1] ^ pref[l])
9+
return ans
10+

0 commit comments

Comments
 (0)