![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeedCode
韩韩韩韩韩美丽
这个作者很懒,什么都没留下…
展开
-
LeetCode删除链表的倒数第n个结点
1.首先遍历一遍链表,用count计数记录一共有多少个结点2.第二遍便利链表,用count1找到删除结点的位置3.删除结点/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ...原创 2018-06-26 20:54:22 · 109 阅读 · 0 评论 -
LeetCode 两数之和(无序版)
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ...原创 2018-07-19 09:42:09 · 170 阅读 · 0 评论 -
LeetCode 平衡二叉树 110
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node never diff...原创 2018-07-25 10:05:39 · 148 阅读 · 0 评论 -
LeetCode 路径总和112
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no children.Example:...原创 2018-07-25 11:01:51 · 251 阅读 · 0 评论 -
LeetCode 二叉树路径257
Given a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: All ...原创 2018-07-25 18:01:09 · 210 阅读 · 0 评论 -
LeetCode 有效的括号
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...原创 2018-07-20 16:05:35 · 178 阅读 · 0 评论 -
LeetCode count and say 38
count-and-say序列是整数序列,前五个术语如下:1. 12. 113. 214. 12115. 1112211作为"one 1"或读出11。11作为"two 1s"或读出21。21被读出"one 2,然后one 1"或1211。给定整数n,生成count-and-say序列的第n项。注意:整数序列的每个术语将表示为一个字符串。例1:输入: 1 输出:...原创 2018-07-29 12:36:47 · 112 阅读 · 0 评论 -
LeetCode Merge Two Sorted Lists21
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2018-07-29 13:26:07 · 103 阅读 · 0 评论 -
LeetCode Merge Sorted Array 88
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may assu...原创 2018-07-29 14:43:25 · 160 阅读 · 0 评论 -
LeetCode Contains Duplicate217
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element i...原创 2018-07-29 15:23:24 · 141 阅读 · 0 评论 -
LeetCode First Bad Version278
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the...原创 2018-07-29 16:02:21 · 170 阅读 · 0 评论 -
LeetCode Kth Smallest Element in a Sorted Matrix378
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not t...原创 2018-07-29 19:38:38 · 196 阅读 · 0 评论 -
LeetCode 两个排序数组的中位数4
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3...原创 2018-07-22 20:04:24 · 144 阅读 · 0 评论 -
LeetCode 搜索插入位置 35
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array....原创 2018-07-22 20:06:15 · 142 阅读 · 0 评论 -
LeetCode 相同的树100
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example ...原创 2018-07-23 09:29:56 · 218 阅读 · 0 评论 -
LeetCode 二进制搜索树的最低共同祖先235
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between ...原创 2018-07-24 17:25:33 · 285 阅读 · 0 评论 -
LeetCode 二叉树的最小深度 111
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no childre...原创 2018-07-24 16:46:18 · 151 阅读 · 0 评论 -
LeetCode交换链表相邻结点
不对结点的val值作改动,而是交换结点增加虚拟头节点减少代码量/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* swapPairs(struct ListNode* ...原创 2018-06-26 21:06:19 · 150 阅读 · 0 评论 -
LeetCode删除排序链表中的重复元素
1.判断val值是否相等2.相等时删除重复元素/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* deleteDuplicates(struct ListNode* ...原创 2018-06-26 21:18:28 · 92 阅读 · 0 评论 -
LeetCode环形链表
给定一个链表,判断链表中是否有环。进阶:你能否不使用额外空间解决此题?思路:1.设置快慢指针,快指针每次走两步,慢指针每次走一步2.若两指针相遇,有环存在/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; ...原创 2018-06-26 21:23:40 · 402 阅读 · 0 评论 -
LeetCode相交链表
1.分别计算A、B链表的长度 countA、countB2.求A、B链表的差值index = abs(countA - countB),哪个链表长哪个链表先走index步3.A、B链表同时走,若走到相同结点,说明有相交结点/** * Definition for singly-linked list. * struct ListNode { * int va...原创 2018-06-26 21:30:03 · 131 阅读 · 0 评论 -
LeetCode快乐数
思路:1.快乐数可以用链表判断环实现2.每个数字是链表的一个结点3.运算一次,指向next4.判断是否有环,有环则证明是快乐数int next_num(int x){ int ret = 0,temp; while(x){ temp = x % 10; ret += temp *temp; x /= 10...原创 2018-06-26 21:36:12 · 225 阅读 · 0 评论 -
LeetCode删除链表中的结点
1.增加虚拟头节点,存在头节点的删改时操作简单2.设置当前结点current_node,若current_node->next ->val = val,删除current_node->next,否则后移 /** * Definition for singly-linked list. * struct ListNode { * int val; ...原创 2018-06-26 21:44:30 · 86 阅读 · 0 评论 -
LeetCode反转链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* reverseList(struct ListNode* head) { struct ListNode * ...原创 2018-06-26 21:58:25 · 429 阅读 · 0 评论 -
LeetCode回文链表
1.设置快指针fast慢指针slow找到链表的中间结点2.两个指针同时从头节点和中间结点的next结点遍历3.val值相同就是回文链表/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */b...原创 2018-06-27 09:52:50 · 211 阅读 · 0 评论 -
LeetCode 对称树 101
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3B...原创 2018-07-23 10:47:59 · 168 阅读 · 0 评论 -
LeetCode 树的最大深度104
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no childre...原创 2018-07-23 15:04:33 · 148 阅读 · 0 评论 -
LeetCode两数之和(有序版)
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers su...原创 2018-07-18 13:03:32 · 148 阅读 · 0 评论 -
LeetCode 没有重复字符的最长子串
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with...原创 2018-07-18 14:37:27 · 135 阅读 · 0 评论 -
LeetCode 两书之和(无序版)
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ...原创 2018-07-19 09:18:10 · 189 阅读 · 0 评论 -
LeetCode 反转二叉树 226
Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1思路1.如果树的根为空,直接返回NULL即可;2.当根的左子树或者右子树存在的时候,将左...原创 2018-07-24 16:29:06 · 141 阅读 · 0 评论 -
Two Sum II
÷Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers...原创 2018-07-31 10:46:34 · 150 阅读 · 0 评论