-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution of day 1 question on leetcode
- Loading branch information
1 parent
f810623
commit 7cedd45
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Solution { | ||
public: | ||
bool canArrange(vector<int>& arr, int k) { | ||
int n = arr.size(); | ||
|
||
vector<int>result(k,0); | ||
|
||
for(int i=0 ; i<n; i++){ | ||
int rem = ((arr[i] % k) + k) % k; | ||
|
||
result[rem]++; | ||
} | ||
|
||
if(result[0] % 2 != 0) return false; | ||
|
||
for(int i = 1; i<= k/2 ; i++){ | ||
if(result[i] != result[k-i]){ | ||
return false; | ||
} | ||
} | ||
|
||
return true;; | ||
} | ||
}; |
Empty file.