mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Merge branch 'master' into master
This commit is contained in:
commit
f5000f2f96
@ -10,7 +10,9 @@ LeetCode
|
|||||||
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [C](./src/2.c)|Medium|
|
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [C](./src/2.c)|Medium|
|
||||||
|3|[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [C](./src/3.c)|Medium|
|
|3|[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [C](./src/3.c)|Medium|
|
||||||
|4|[Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [C](./src/4.c)|Hard|
|
|4|[Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [C](./src/4.c)|Hard|
|
||||||
|
|7|[Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [C](./src/7.c)|Easy|
|
||||||
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [C](./src/8.c)|Medium|
|
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [C](./src/8.c)|Medium|
|
||||||
|
|9|[Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [C](./src/9.c)|Easy|
|
||||||
|12|[Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c)|Medium|
|
|12|[Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c)|Medium|
|
||||||
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [C](./src/13.c)|Easy|
|
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [C](./src/13.c)|Easy|
|
||||||
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [C](./src/20.c)|Easy|
|
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [C](./src/20.c)|Easy|
|
||||||
|
13
leetcode/src/7.c
Normal file
13
leetcode/src/7.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
int reverse(int x){
|
||||||
|
int rev = 0;
|
||||||
|
while (x != 0) {
|
||||||
|
int pop = x % 10;
|
||||||
|
x /= 10;
|
||||||
|
if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7)) return 0;
|
||||||
|
if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)) return 0;
|
||||||
|
rev = rev * 10 + pop;
|
||||||
|
}
|
||||||
|
return rev;
|
||||||
|
}
|
13
leetcode/src/9.c
Normal file
13
leetcode/src/9.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
bool isPalindrome(int x){
|
||||||
|
if(x < 0 || (x % 10 == 0 && x != 0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int revertedNumber = 0;
|
||||||
|
while(x > revertedNumber) {
|
||||||
|
revertedNumber = revertedNumber * 10 + x % 10;
|
||||||
|
x /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x == revertedNumber || x == revertedNumber/10;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user