刷题
DTF_ys
我
展开
-
Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only...原创 2018-08-28 00:04:14 · 276 阅读 · 0 评论 -
Reverse Linked List
题目Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL总结思路一:递归,从后往前反转代码:# Definition for singly-linked list.# class ListNo...原创 2018-09-21 14:26:09 · 97 阅读 · 0 评论 -
Palindrome Linked List
题目Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: true总结思路:这题的关键是找到链表的中间节点(medium)用slow和fast两个指...原创 2018-09-22 19:47:18 · 109 阅读 · 0 评论 -
uess Number Higher or Lower
题目We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is higher...原创 2018-10-09 20:47:02 · 111 阅读 · 0 评论 -
Find the Difference
题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was a...原创 2018-10-09 21:19:48 · 489 阅读 · 0 评论 -
Find All Numbers Disappeared in an Array
题目Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Cou...原创 2018-10-25 01:07:06 · 102 阅读 · 0 评论 -
DI String Match
题目Given a string S that only contains “I” (increase) or “D” (decrease), let N = S.length.Return any permutation A of [0, 1, …, N] such that for all i = 0, …, N-1:If S[i] == “I”, then A[i] < A[i+...原创 2018-12-15 22:41:08 · 155 阅读 · 0 评论 -
Palindromic Substrings
题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consis...原创 2019-01-17 15:27:02 · 108 阅读 · 0 评论 -
Group Anagrams
题目Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2019-02-21 19:31:13 · 157 阅读 · 0 评论 -
leetcode刷题:Linked List Cycle II (链表循环 II) 详解
原题题目链接Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the positi...原创 2019-02-28 19:24:19 · 326 阅读 · 0 评论 -
Combination Sum
题目Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repe...原创 2019-02-20 21:53:39 · 96 阅读 · 0 评论 -
Search in Rotated Sorted Array
题目Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found...原创 2019-04-12 01:23:53 · 165 阅读 · 0 评论 -
Isomorphic Strings
题目Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot...原创 2018-09-14 10:46:27 · 105 阅读 · 0 评论 -
Count Primes
题目Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.总结思路一:判断每一个数是不...原创 2018-09-13 00:09:40 · 91 阅读 · 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 ↘ ...原创 2018-09-06 14:51:12 · 86 阅读 · 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...原创 2018-08-31 01:19:20 · 83 阅读 · 0 评论 -
Merge Sorted Array
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 assume tha...原创 2018-08-29 00:42:26 · 88 阅读 · 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.Note: A leaf is a node with no chi...原创 2018-09-01 01:06:44 · 81 阅读 · 0 评论 -
Maximum Subarray
题目: Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Expl...原创 2018-08-25 00:16:14 · 103 阅读 · 0 评论 -
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 defin...原创 2018-08-25 17:32:58 · 111 阅读 · 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.Note: A leaf is a node with no childre...原创 2018-08-29 23:58:37 · 117 阅读 · 0 评论 -
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?总结我的代码:public class Solution { public boolean hasCycle(ListNode head) ...原创 2018-09-04 22:31:05 · 90 阅读 · 0 评论 -
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 ...原创 2018-09-07 19:27:38 · 97 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
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,null,null,15...原创 2018-08-30 11:53:38 · 104 阅读 · 0 评论 -
Factorial Trailing Zeroes
题目Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation: 3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5! = 120, one tra...原创 2018-09-08 21:04:48 · 105 阅读 · 0 评论 -
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 the sum of the squar...原创 2018-09-12 00:10:28 · 291 阅读 · 0 评论 -
Pascal's Triangle II
题目Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal’s triangle.Note that the row index starts from 0. In Pascal’s triangle, each number is the sum of the two numbe...原创 2018-09-03 23:41:55 · 98 阅读 · 0 评论 -
算法:快速排序的实现
理解:快速排序对问题分而治之的一种方法,在每一趟排序后,都能确定一个数的位置(即分割点),因此快速排序的核心是确定分割点的位置并把数组按大小分在分割点的两侧。因此快排可以分为两部分,第一部分是递归处理问题,第二部分是找到分割点第一部分:def quickSort(l, r): if l >=r: return p = partition(nums, l, r...原创 2019-07-03 00:48:33 · 259 阅读 · 0 评论