03 2015 档案
摘要: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 mat...
阅读全文
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:我的思路,先沿对角线对称,再左右...
阅读全文
摘要: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...
阅读全文
摘要: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 inserted in or...
阅读全文
摘要:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t...
阅读全文
摘要:Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri...
阅读全文
摘要:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ],...
阅读全文
摘要:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ...
阅读全文
摘要:做太多遍了,秒杀。class Solution {public: int hammingWeight(uint32_t n) { int num = 0; for(;n; n &=(n-1), num++); return num; }};
阅读全文
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:不能用额外空间,就用矩阵的第一行和第一列来标记这一行或这一列是否需要置0. 用两个bool量记录第一行和第一列是否需...
阅读全文
摘要:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For exam...
阅读全文
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.思路...
阅读全文
摘要: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 origi...
阅读全文
摘要: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.思路:使用伪头部c...
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
阅读全文
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.题目关键点...
阅读全文
摘要:记录下可以用的中序遍历方法方法1:vector InOrderTraverse(TreeNode * root) //中序遍历 { vector ans; TreeNode* p; vector Stack; Stack.push_bac...
阅读全文
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBA...
阅读全文
摘要:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.anagrams 的意思是两个词用相同的字母组成 比如 “dog" "go...
阅读全文
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.思路:自己脑子当机了,总是想着斜率和截距都要相同。但实际上三个点是一条直线的话只要它们的斜率相同就可以了,...
阅读全文
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ...
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?思路:...
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ...
阅读全文
摘要:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-o...
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
阅读全文