mirror of
https://github.com/TheAlgorithms/C
synced 2025-02-10 18:44:28 +03:00
Adding leetcode Rotate Array (189.c) and Count Primes (204.c)
This commit is contained in:
parent
11ea4be19f
commit
2ec2f92284
@ -36,9 +36,11 @@ LeetCode
|
||||
|160|[Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) | [C](./src/160.c)|Easy|
|
||||
|169|[Majority Element](https://leetcode.com/problems/majority-element/) | [C](./src/169.c)|Easy|
|
||||
|173|[Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/) | [C](./src/173.c)|Medium|
|
||||
|189|[Rotate Array](https://leetcode.com/problems/rotate-array) | [C](./src/189.c)|Easy|
|
||||
|190|[Reverse Bits](https://leetcode.com/problems/reverse-bits/) | [C](./src/190.c)|Easy|
|
||||
|191|[Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) | [C](./src/191.c)|Easy|
|
||||
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/) | [C](./src/203.c)|Easy|
|
||||
|204|[Count Primes](https://leetcode.com/problems/count-primes) | [C](./src/204.c)|Easy|
|
||||
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | [C](./src/206.c)|Easy|
|
||||
|215|[Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | [C](./src/215.c)|Medium|
|
||||
|217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [C](./src/217.c)|Easy|
|
||||
|
11
leetcode/src/189.c
Normal file
11
leetcode/src/189.c
Normal file
@ -0,0 +1,11 @@
|
||||
void rotate(int* nums, int numsSize, int k){
|
||||
for(int i = 1; i <= k; i++){
|
||||
int j;
|
||||
int lastElement;
|
||||
lastElement = nums[numsSize - 1];
|
||||
for(j = numsSize - 1; j > 0; j--){
|
||||
nums[j] = nums[j - 1];
|
||||
}
|
||||
nums[0] = lastElement;
|
||||
}
|
||||
}
|
16
leetcode/src/204.c
Normal file
16
leetcode/src/204.c
Normal file
@ -0,0 +1,16 @@
|
||||
int countPrimes(int n){
|
||||
int count = 0;
|
||||
int isPrime;
|
||||
for (int i = 2; i <= n; i++){
|
||||
isPrime = 1;
|
||||
for(int j = 2; j < i; j++){
|
||||
if(i % j == 0){
|
||||
isPrime = 0;
|
||||
}
|
||||
}
|
||||
if(isPrime == 1){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user