[LeetCode C实现]371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example:

Given a = 1 and b = 2, return 3.

Credits:

Special thanks to @fujiaozhu for adding this problem and creating all test cases.

第一次在leetcode上看到反对票比赞成票多这么多的题目。

C实现代码如下:

int getSum(int a,......

[LeetCode C 实现]538. Convert BST to Greater Tree

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

Input: The root of a Binary Search Tree like this:

5

/ \

2 13

Output: The root of a Greater Tree ......

[LeetCode C实现]230. Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

Note:

You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

Example 1:

Input: root = [3,1,4,null,2], k = 1

Output: 1

Example 2:

Input: root = [5,3,6,2,4,null,null,1], k ......

[LeetCode C 实现]144. Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes' values.

Input: [1,null,2,3]

1

\

2

/

3

Output: [1,2,3]

Follow up: Recursive solution is trivial, could you do it iteratively?

递归实现/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* struct Tree......

[LeetCode C实现]94. Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values.

Example:

Input: [1,null,2,3]

1

\

2

/

3

Output: [1,3,2]

Output:

Follow up: Recursive solution is trivial, could you do it iteratively?

通过这道leetcode中的题目我们将学习,二叉树(中序 后序 前序)遍历递归与非递归实现,算法采用C编写,在非递归算法中如果采用C++中的栈来实现,将会非常......

[LeetCode C实现]14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

Example 1:

Input: ["flower","flow","flight"]

Output: "fl"

Example 2:

Input: ["dog&q......

[LeetCode C 实现]345. Reverse Vowels of a String

Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:

Given s = "hello", return "holle".

Example 2:

Given s = "leetcode", return "leotcede".

Note:

The vowels does not include the letter "y".

......

[LeetCode C 实现]234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.

Follow up:

Could you do it in O(n) time and O(1) space?

题目描述比较简单:判断链表中的val组成的数字是否是回文数即形如12321 123321即是回文数。

如果题目中没有O(1) space的要求的话,那么可以把链表的值顺序读出放在数组中,然后进行判断。

一种比较巧妙的思路是:逆序(reverse)后半段,然后比较前后两段的值是否相同。

实现代码:

/**

* Definition for......

[LeetCode C 实现]20. Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets.

Open brackets must be closed in the ......

[LeetCode C实现] 160. Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

A: a1 → a2

c1 → c2 → c3

B: b1 → b2 → b3

begin to intersect at node c1.

Notes:

If the two linked lists have no interse......