Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c9ba025

Browse files
Refine
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
1 parent b9dc8ac commit c9ba025

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

‎069_sqrt/sqrt.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ static double mySqrt(double x)
2525

2626
static double mySqrt(double n)
2727
{
28-
/* Solute the zero point of f(x) = 0 => x ^ 2 - n = 0 */
29-
/* f(x) = (x - x0)f'(x0) - f(x0) = 0 First order of Tylor series */
28+
/* Solute the zero point of f(x). Let F(x) = f(x) - n = 0 */
29+
/* then (x - x0)F'(x0) + F(x0) = 0 which is the first order of Tylor series */
3030
double x = 1.0;
3131
while (fabs(x * x - n) > 1e-8) {
3232
// x = x - (x * x - n) / (2 * x);

‎088_merge_sorted_array/merge_array.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4+
45
static void merge(int* nums1, int m, int* nums2, int n)
56
{
67
int i = m - 1, j = n - 1, k = nums1Size - 1;
7-
while (i >= 0 && j >= 0&&k >= 0) {
8+
while (i >= 0 && j >= 0) {
89
if (nums1[i] >= nums2[j]) {
910
nums1[k--] = nums1[i--];
1011
} else {
1112
nums1[k--] = nums2[j--];
1213
}
1314
}
1415

15-
if (i == -1) {
16-
while (j >= 0) {
17-
nums1[k--] = nums2[j--];
18-
}
16+
while (j >= 0) {
17+
nums1[k--] = nums2[j--];
1918
}
2019
}
2120

‎108_convert_sorted_array_to_binary_search_tree/bst_convert.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ struct TreeNode {
1010

1111
static struct TreeNode *partition(int *nums, int lo, int hi)
1212
{
13+
if (lo > hi) {
14+
return NULL;
15+
}
1316
int mid = lo + (hi - lo) / 2;
1417
struct TreeNode *node = malloc(sizeof(*node));
1518
node->val = nums[mid];
16-
node->left = mid>lo ? partition(nums, lo, mid - 1) : NULL;
17-
node->right = mid<hi ? partition(nums, mid + 1, hi) : NULL;
19+
node->left = partition(nums, lo, mid - 1);
20+
node->right = partition(nums, mid + 1, hi);
1821
return node;
1922
}
2023

2124
static struct TreeNode* sortedArrayToBST(int* nums, int numsSize)
2225
{
23-
if (numsSize == 0) {
24-
return NULL;
25-
}
2626
return partition(nums, 0, numsSize - 1);
2727
}
2828

‎112_path_sum/path_sum.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdlib.h>
33
#include <stdbool.h>
44

5+
56
struct TreeNode {
67
int val;
78
struct TreeNode *left;
@@ -11,8 +12,10 @@ struct TreeNode {
1112
static bool hasPathSum(struct TreeNode *root, int sum)
1213
{
1314
if (root == NULL) {
15+
/* Here is non leaf */
1416
return false;
1517
} else if (root->left == NULL && root->right == NULL && root->val == sum) {
18+
/* Here must be leaf */
1619
return true;
1720
} else {
1821
return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /