LeetCode
文章平均质量分 74
议题一玩到
硅谷码农
展开
-
#leetcode#Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2015-07-13 08:19:13 · 473 阅读 · 0 评论 -
#leetcode#Intersection of Two LinkedList
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-07-20 16:38:35 · 664 阅读 · 0 评论 -
#leetcode#One Edit Distance
Given two strings S and T, determine if they are both one edit distance apart.分析:one edit distance,要么S,T长度相同, 只有一对不同char,那么只要跳过这对不同的char,应该能匹配完两个String的;原创 2015-07-20 16:18:05 · 966 阅读 · 0 评论 -
#leetcode#Anagrames
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.分析:判断两个String是不是anagrams,比较简单的方法就是先转换成charArray,然后排序,然后重新生成String,看是否相同, 这个Stri原创 2015-07-21 06:14:16 · 615 阅读 · 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 1 step.)You have the following 3 operations permitted on a word:原创 2015-06-26 07:27:09 · 804 阅读 · 0 评论 -
#leetcode#LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2015-07-22 08:51:02 · 792 阅读 · 0 评论 -
#leetcode#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-07-22 15:10:11 · 539 阅读 · 0 评论 -
#leetcode#Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2015-05-24 13:48:47 · 491 阅读 · 0 评论 -
#leetcode#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-07-22 16:53:39 · 648 阅读 · 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 / \原创 2015-07-23 12:41:57 · 863 阅读 · 0 评论 -
#leetcode#Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.分析:注意k有可能会大于list的长度,所以先求出list原创 2015-07-31 01:41:53 · 588 阅读 · 0 评论 -
#leetcode#Find Peak Element
Find Peak ElementTotal Accepted:31990Total Submissions:101250My SubmissionsQuestionSolutionA peak element is an element that is greater than its neighbors.Given an input原创 2015-07-18 16:36:24 · 481 阅读 · 1 评论 -
#leetcode#Missing Ranges
Missing Ranges Total Accepted: 2544 Total Submissions: 10515My SubmissionsQuestion Solution Given a sorted integer array where the range of elements are [lower, upper] inclusive,原创 2015-07-16 14:12:35 · 818 阅读 · 0 评论 -
#leetcode#Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2015-06-14 11:47:03 · 425 阅读 · 0 评论 -
#leetcode#Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.借鉴 https://leetcodenotes.wordpre原创 2015-06-14 14:46:52 · 461 阅读 · 0 评论 -
#leetcode#Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2015-06-16 02:35:50 · 566 阅读 · 0 评论 -
#leetcode#Merge K Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Divide and Conquer Linked List Heap思路:方法1, 利用merge原创 2015-06-16 08:00:28 · 568 阅读 · 0 评论 -
#leetcode#Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2015-06-14 12:21:38 · 683 阅读 · 0 评论 -
#leetcode#Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3原创 2015-06-15 13:09:28 · 708 阅读 · 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.这题brute force肯定要bug free, 如果能打出来O(n)的解法肯定加分, rolling hash解法必须掌原创 2015-07-07 02:34:18 · 606 阅读 · 0 评论 -
#leetcode#Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2015-07-14 03:49:57 · 637 阅读 · 0 评论 -
#leetcode#Product of Array Except Self
Product of Array Except Self Total Accepted: 442 Total Submissions: 1138My SubmissionsQuestion Solution Given an array of n integers where n > 1, nums, return an array output s原创 2015-07-16 10:46:39 · 1302 阅读 · 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原创 2015-07-23 05:43:50 · 988 阅读 · 0 评论 -
#leetcode#Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2015-06-12 14:18:13 · 474 阅读 · 0 评论 -
#leetcode#38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read o原创 2017-06-14 16:07:12 · 459 阅读 · 0 评论 -
#leetcode#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.Follow up:What if the原创 2015-07-02 05:28:54 · 1072 阅读 · 0 评论 -
#leetcode#Ugly Numbers 2
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first原创 2017-06-10 15:12:52 · 323 阅读 · 0 评论 -
#leetcode#500 Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Da原创 2017-06-11 11:13:55 · 316 阅读 · 0 评论 -
#leetcode#547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, the原创 2017-06-14 15:29:28 · 521 阅读 · 0 评论 -
#leetcode#130. Surrounded Regions
iven a 2D board containing'X'and'O'(theletterO), capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.For example,X X X原创 2017-08-21 09:12:05 · 354 阅读 · 1 评论 -
#leetcode#647. Palindromic Substrings
https://leetcode.com/problems/palindromic-substrings/description/Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes原创 2017-09-18 02:08:00 · 854 阅读 · 0 评论 -
#leetcode#305. Number of Islands II
A 2d grid map of m rows andn columns is initially filled with water. We may perform anaddLand operation which turns the water at position (row, col) into a land. Given a list of positions to opera原创 2017-06-02 16:27:20 · 639 阅读 · 0 评论 -
#leetcoce#277. Find the Celebrity
Suppose you are at a party withnpeople (labeled from0ton - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the othern - 1people know him/her but原创 2017-09-18 08:45:06 · 529 阅读 · 1 评论 -
#leetcode#329. Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside原创 2017-05-08 09:11:36 · 501 阅读 · 0 评论 -
#leetcode#220. Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute diffe原创 2017-05-26 14:37:11 · 390 阅读 · 0 评论 -
#leetcode#179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2017-05-23 13:38:01 · 320 阅读 · 0 评论 -
#leetcode#Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did原创 2015-07-25 03:42:37 · 777 阅读 · 0 评论 -
#leetcode#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原创 2015-09-15 13:36:19 · 574 阅读 · 0 评论 -
#leetcode#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.=================================不让用加减符号,很自然想原创 2016-08-18 14:38:12 · 375 阅读 · 0 评论 -
#leetcode#Reverse String
好久没刷题,准备刷起来了,leetcode都300多题了, 世界变化太快随便找了个简单题,Reverse String,很自然就想到用StringBuilder从尾到头撸一遍,代码如下public class Solution { public String reverseString(String s) { if(s == null || s.length原创 2016-08-08 15:16:49 · 403 阅读 · 0 评论