随笔分类 - 算法题
摘要:Description:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are s...
阅读全文
摘要:Description:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,...
阅读全文
摘要:Description: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 in...
阅读全文
摘要:Description:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each...
阅读全文
摘要:Description:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexcept...
阅读全文
摘要:Description:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return...
阅读全文
摘要:Description:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.n皇后问题:每两个皇后之间不能...
阅读全文
摘要:Description:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?在不借助辅助空间的情况下判断一个链表是否存在回路。可以用两个...
阅读全文
摘要:Description:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3retur...
阅读全文
摘要:Description:Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the tw...
阅读全文
摘要:Description:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You ma...
阅读全文
摘要:Description:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf pat...
阅读全文
摘要:Description:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails t...
阅读全文
摘要:Description:Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For exa...
阅读全文
摘要:Description:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, ...
阅读全文
摘要:Description:Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process ...
阅读全文
摘要:Description:Given acompletebinary tree, count the number of nodes.In a complete binary tree every level, except possibly the last, is completely fille...
阅读全文
摘要:Description:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on...
阅读全文
摘要:Description:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?判断一个单向链表是不是回文。思路:最简单的思路就...
阅读全文
摘要:Description: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...
阅读全文
浙公网安备 33010602011771号