![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 69
Appletable
这个作者很懒,什么都没留下…
展开
-
LeetCode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-02-11 22:25:05 · 245 阅读 · 0 评论 -
LeetCode 328. 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原创 2016-03-07 09:26:33 · 339 阅读 · 0 评论 -
LeetCode 35. Search Insert Position
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.原创 2016-03-07 10:42:40 · 507 阅读 · 0 评论 -
LeetCode 278. First Bad Version
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原创 2016-03-07 15:23:14 · 349 阅读 · 0 评论 -
LeetCode 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2016-03-07 18:33:22 · 316 阅读 · 0 评论 -
LeetCode 144. Binary Tree Preorder Traversal
LeetCode,Binary Tree Preorder Traversal,迭代,两种形式,堆栈原创 2016-02-22 00:07:07 · 255 阅读 · 0 评论 -
LeetCode 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive solutio原创 2016-02-22 19:04:49 · 227 阅读 · 0 评论 -
LeetCode 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le原创 2016-02-24 22:48:45 · 277 阅读 · 0 评论 -
LeetCode 206. Reverse Linked List
Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 分析:单链表翻转问题:迭代和递归两种做法 代码一:递归 /** * Definition for singly-linked li原创 2016-02-25 22:17:03 · 291 阅读 · 0 评论 -
LeetCode 12. Integer to Roman & 13. Roman to Integer
罗马数字,数字变换,LeetCode原创 2016-02-27 13:21:20 · 333 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 分析:可以将结点存入数组中,此方法需要额外的空间,也可以用双指针,快慢指针同时向前跑,如果跑到结尾,就没环,如果被套圈,证明有环。 代码: /** * Def原创 2016-03-12 21:51:28 · 344 阅读 · 0 评论 -
LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
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 betw原创 2016-02-28 11:48:30 · 393 阅读 · 0 评论 -
LeetCode 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. 分析:不使用“+”“-”等符号来进行加法运算。一般情况下是可以用位运算来解决。 先来看一位二进制加法 1原创 2016-06-30 11:46:26 · 539 阅读 · 0 评论 -
LeetCode 202. Happy Number & 263. Ugly Number
202. Happy Number Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by原创 2016-07-03 22:01:03 · 611 阅读 · 0 评论 -
LeetCode 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm shoul原创 2016-02-20 16:10:24 · 286 阅读 · 0 评论 -
LeetCode 319. Bulb Switcher
LeetCode,开灯问题,Bulb Switcher,多解原创 2016-02-20 09:13:44 · 256 阅读 · 0 评论 -
LeetCode 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2016-02-12 15:10:24 · 215 阅读 · 0 评论 -
LeetCode 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 分析:又是二叉树的问题,很多二叉树的问题可以用递归算法来解决。先判断当前结点是否为空,此为递归的出口;接下来交换左孩子和右孩子的位置,分别以左孩子原创 2016-02-12 20:35:09 · 288 阅读 · 0 评论 -
LeetCode 283. 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原创 2016-02-13 20:36:07 · 238 阅读 · 0 评论 -
LeetCode 100. Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 分析:二叉树的问题,原创 2016-02-14 16:14:59 · 336 阅读 · 0 评论 -
LeetCode 258. Add Digits
LeetCode 258. Add Digits 三种解法原创 2016-02-01 22:53:11 · 246 阅读 · 0 评论 -
LeetCode 136.137. 260.Single Number ⅠII III
LeetCode 136.137. 260.Single Number ⅠII III原创 2016-02-15 23:53:09 · 384 阅读 · 0 评论 -
LeetCode 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O原创 2016-02-16 15:02:44 · 293 阅读 · 0 评论 -
LeetCode 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may ass原创 2016-02-16 23:21:45 · 362 阅读 · 0 评论 -
LeetCode 217. 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原创 2016-02-17 14:11:13 · 253 阅读 · 0 评论 -
LeetCode 171. Excel Sheet Column Number & 168. Excel Sheet Column Title
LeetCode 171. Excel Sheet Column Number & 168. Excel Sheet Column Title原创 2016-02-18 00:21:39 · 371 阅读 · 0 评论 -
LeetCode 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element原创 2016-02-18 14:50:32 · 263 阅读 · 0 评论 -
LeetCode 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 000000原创 2016-03-05 10:27:50 · 350 阅读 · 0 评论 -
LeetCode 231. Power of Two & 326. Power of Three
Given an integer, write a function to determine if it is a power of two or three. 分析:判断一个数是否是2的幂(另一题是3的幂) 直观的解决办法就是循环除 2 或者 3 来判断,另外一种不需要循环的方式就是用对数和幂指数的数学方法来运算。 另外,由于数据可以用二进制表示,那么 2 的幂可以通过位运算来判断。原创 2016-03-05 12:58:53 · 349 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree && Minimum Depth of Binary
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. 本题目是简单的二叉树深度问题,二叉树是每个节点最多有两个子树的树结构原创 2016-02-11 16:34:57 · 243 阅读 · 0 评论