![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法-Algorithm
文章平均质量分 52
crazy_chen
这个作者很懒,什么都没留下…
展开
-
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原创 2015-03-05 19:20:15 · 301 阅读 · 0 评论 -
数组去重
Write a function to remove duplicated objects from an array. Preserve the order. For example, if the input array is [1, 5, 4, 2, 7, 2, 6, 5], the result should be [1, 5, 4, 2, 7, 6]. The implementation原创 2015-03-26 18:57:51 · 475 阅读 · 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 cons原创 2015-03-26 18:42:17 · 307 阅读 · 0 评论 -
Leetcode:Merge Two Sorted Lists
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. 给你2个排序好的单链表,返回一个merge的单链表。 链表数据结构: public class ListNode原创 2015-03-26 18:33:20 · 356 阅读 · 0 评论 -
Leetcode:Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length.public int原创 2015-03-26 18:43:12 · 342 阅读 · 0 评论 -
Leetcode:Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Have you thought about this? Here are some good questions to ask before coding. Bonus原创 2015-03-26 18:40:26 · 292 阅读 · 0 评论 -
Leetcode:Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02): The signature of the function had been updated to retur原创 2015-03-26 18:47:45 · 348 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2015-03-06 23:51:22 · 306 阅读 · 0 评论 -
excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2015-03-06 23:53:19 · 347 阅读 · 0 评论 -
Maximum Depth of Binary Tree
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. * Definition for binary tree原创 2015-03-06 23:48:22 · 298 阅读 · 0 评论 -
Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? public int climbStairs(in原创 2015-03-06 23:58:20 · 344 阅读 · 0 评论 -
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.还是用d原创 2015-03-06 23:51:09 · 335 阅读 · 0 评论 -
Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from原创 2015-03-06 23:55:19 · 272 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. public class ListNode原创 2015-03-06 23:55:21 · 360 阅读 · 0 评论 -
SingleNumberII
public class SingleNumberII { /* * Given an array of integers, every element appears three times except for * one. Find that single one. * * Note: Your algorithm should have a原创 2015-03-13 10:29:39 · 395 阅读 · 0 评论 -
Reverse Words in a String
Given an input string, reverse the string word by word.For example, Given s = “the sky is blue”, return “blue is sky the”.Update (2015-02-12): For C programmers: Try to solve it in-place in O(1) spa原创 2015-03-13 10:39:04 · 435 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
public class PopulatingNextRightPointersinEachNode { /* * Given a binary tree * * struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; * TreeLinkNode *next; } Populate原创 2015-03-13 10:33:07 · 374 阅读 · 0 评论 -
Leetcode:Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2015-03-26 18:51:52 · 330 阅读 · 0 评论 -
Leetcode: Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as原创 2015-03-26 18:35:18 · 346 阅读 · 0 评论 -
Leetcode: Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.给你一个整形数组,该数组实际表示一个非负整数,每个元素代表原创 2015-03-26 18:31:31 · 304 阅读 · 0 评论 -
Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating原创 2015-03-05 19:20:39 · 311 阅读 · 0 评论 -
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Tag:Mat原创 2015-03-05 19:26:34 · 336 阅读 · 0 评论 -
Compare Version Numbers
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and原创 2015-03-05 19:27:31 · 306 阅读 · 0 评论 -
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 ↘原创 2015-03-05 19:29:25 · 338 阅读 · 0 评论 -
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. Could you implement it without using ext原创 2015-03-05 19:31:11 · 378 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Hide Tags Array原创 2015-03-05 19:32:26 · 279 阅读 · 0 评论 -
Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?和上一题类似,给一个原创 2015-03-05 19:34:21 · 360 阅读 · 0 评论 -
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原创 2015-03-05 19:35:12 · 290 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2015-03-05 19:36:52 · 306 阅读 · 0 评论 -
Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo原创 2015-03-05 19:39:36 · 376 阅读 · 0 评论 -
Balanced Binary Tree
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 diffe原创 2015-03-05 19:42:28 · 302 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100”.public class Solution { public String addBinary(String a, String b) {原创 2015-03-05 19:46:07 · 312 阅读 · 0 评论 -
Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2015-03-05 19:46:48 · 279 阅读 · 0 评论 -
ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2015-03-05 19:21:46 · 292 阅读 · 0 评论 -
Minimum Depth of Binary Tree
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.public int minDepth(TreeNode root)原创 2015-03-05 19:41:15 · 297 阅读 · 0 评论 -
Binary Tree Level Order Traversal2
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2015-03-05 19:49:19 · 306 阅读 · 0 评论 -
TwoSum
给一个数组,还有一个target,找到数组中能够产生和值为target的两个数,返回2个数的index。 假设每次输入,肯定有唯一解 2次for循环得出一个暴力解,但是超时了。 或者空间换时间,把每一个数对应需要的另一个值保存在hashmap中,然后再来一次循环,如果包含该key,就对了“`java /* * Given an array of integers, find t原创 2015-03-13 10:30:00 · 288 阅读 · 0 评论