随笔分类 - leetcode刷题
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo
阅读全文
摘要:一、Department Top Three Salaries The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +-
阅读全文
摘要:一、Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 10
阅读全文
摘要:Sort a linked list using insertion sort. 分析:此题要求在链表上实现插入排序。 思路:插入排序是一种O(n^2)复杂度的算法,基本想法就是每次循环找到一个元素在当前排好的结果中相对应的位置然后插进去,经过n次迭代之后就能得到排好序的结果。 可以这么做:建立一个
阅读全文
摘要: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-
阅读全文
摘要:Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After rem
阅读全文
摘要:Given a linked list, swap every two adjacent(相邻的) nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Y
阅读全文
摘要:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you nee
阅读全文
摘要: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
阅读全文
摘要:题目:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the or...
阅读全文
摘要:Sort a linked list inO(nlogn) time using constant space complexity.分析:题目要求时间复杂度为O(nlogn),所以不能用quickSort(最坏O(n^2)),可以使用mergeSort.对一个链表进行归并排序,首先注意归并排序的基...
阅读全文
摘要: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.分析:思路比较简单...
阅读全文
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...
阅读全文
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l...
阅读全文
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest...
阅读全文
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great...
阅读全文
摘要:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]...
阅读全文
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion10.01代码如下:class Solution { public: int compareVersion(strin...
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...
阅读全文