![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 57
Kent-
这个作者很懒,什么都没留下…
展开
-
LeetCode:求两个整数的汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.该题即求两个整数的汉明距离,原创 2017-02-23 20:11:27 · 3961 阅读 · 0 评论 -
LeetCode:Rotate Image
You are given an n*n 2D matrix representing an image.Rotate the image by 90 degrees(clockwise).Follow up: Could you do this in-place?解题思路:暴力法:从外到内一圈一圈地转,不过这个方法效率太低,比较慢。分析法:首先沿着副对角线翻转一次,然后沿着水原创 2017-06-03 09:19:48 · 222 阅读 · 0 评论 -
LeetCode:Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2.(each operation is counted as 1step.)You have the following 3 operations permitted on word:1、In原创 2017-06-19 17:08:46 · 216 阅读 · 0 评论 -
LeetCode:Reorder List
Given a singly linked list L : L0 -> L1 -> ...Ln-1 -> Ln, reorder it to: L0 -> Ln ->L1 ->Ln-1 -> L2 -> Ln-2 ->....You must do this in-place without altering the nodes' values.For example, Given {1原创 2017-06-12 10:44:47 · 169 阅读 · 0 评论 -
LeetCode:Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2017-06-23 21:23:34 · 162 阅读 · 0 评论 -
LeetCode: Number of Islands
题目描述:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. Y原创 2017-06-25 21:02:07 · 253 阅读 · 0 评论 -
LeetCode: Kth Largest Element in Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.原创 2017-06-26 16:09:17 · 223 阅读 · 0 评论 -
LeetCode:Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in原创 2017-06-26 16:54:18 · 249 阅读 · 0 评论 -
LeetCode:Convert Sorted List to Binary Search Tr
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.给出一个单链表,结点是按元素递增的顺序排序,把链表转换成高度平衡的二叉搜索树解题分析:由于链表是按节结点的值递增排序的,因此可以使用双指针,一个快一个慢,原创 2017-06-26 19:31:59 · 275 阅读 · 0 评论 -
LeetCode: Path Sum
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.For example:Given the below binary tree and sum原创 2017-06-26 19:36:24 · 206 阅读 · 0 评论 -
LeetCode:Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2017-06-26 19:43:10 · 231 阅读 · 0 评论 -
LeetCode:Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =原创 2017-06-26 21:41:05 · 195 阅读 · 0 评论 -
LeetCode:Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1原创 2017-05-28 13:47:26 · 252 阅读 · 0 评论 -
LeetCode: Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of原创 2017-05-08 23:35:37 · 232 阅读 · 0 评论 -
LeetCode: Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with c原创 2017-05-25 10:59:15 · 187 阅读 · 0 评论 -
LeetCode:求二叉树的深度
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.二叉树的深度定义为根节点到距离根节点最远的叶子节点之间节点的数量。原创 2017-03-04 23:21:08 · 448 阅读 · 0 评论 -
LeetCode:反转二叉树
解题思路: 要对一棵二叉树进行反转操作,则必须对其遍历,考虑使用先序遍历的方法,则先遍历根节点,接着对其左右孩子节点进行反转,再递归对以其左右孩子节点为根节点的子树进行反转操作,最终完成整棵二叉树的反转。需注意的点:所传根节点可能为0,即改树为空树,则应该作特殊处理,否则当取其左右孩子的时候会出现空指针异常。代码如下:/** * Definition for a binary tre原创 2017-03-05 22:04:23 · 580 阅读 · 0 评论 -
LeetCode:3Sum
描述Given an arrayS ofn integers, are there elementsa,b,c inS such thata+b+c= 0? Find all uniquetriplets in the array which gives the sum of zero.Note:• Elements in a triplet (a, b, c)原创 2017-03-20 10:22:48 · 263 阅读 · 0 评论 -
LeetCode:Two Sum
描述:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target,w原创 2017-03-11 23:22:10 · 243 阅读 · 0 评论 -
LeetCode:Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. 给出一个整型数组,其中除了一个元素之外,其他元素均出现两次,要求找出这个只出原创 2017-03-25 23:19:10 · 414 阅读 · 0 评论 -
LeetCode:Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2017-04-02 23:02:58 · 373 阅读 · 0 评论 -
LeetCode:Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2017-04-29 18:20:29 · 224 阅读 · 0 评论 -
LeetCode: Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2017-04-15 13:58:17 · 201 阅读 · 0 评论 -
LeetCode:Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in原创 2017-04-15 19:05:08 · 253 阅读 · 0 评论 -
LeetCode: Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2017-04-23 15:31:41 · 196 阅读 · 0 评论 -
LeetCode:Contains Duplicate
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原创 2017-05-14 20:15:42 · 186 阅读 · 0 评论 -
LeetCode:Best Time to Buy and Sell Stock
描述 Say you have an array for which the i-th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction(ie, buy one and sell one share of t原创 2017-06-28 14:15:46 · 253 阅读 · 0 评论