Move Zeroes

3-13 899 views

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For exa...
阅读全文 0

Odd Even Linked List

5-13 875 views

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 ...
阅读全文 0

Remove Duplicates from Sorted Array

3-13 844 views

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space...
阅读全文 0


6-01 1,381 views

求两个数的最大公因子,使用“辗转相除法”。 原理如下:若r=a%b,则gcd(a,b)=gcd(b,r)。 简单推导: 因为r=a%b,所以a=bq+r,r=a-bq。 a=bq+r,能被b,r整除的...
阅读全文 0


1-05 39,118 views

题目:如何查找单链表的倒数第n个指针。 算法一:第一次遍历到链表末尾,找到链表长度N;第二遍遍历,找到第N-n个节点。 算法二:设立两个指针,p1指向头节点...
阅读全文 0


12-31 6,001 views

题目:给定数组str[],循环左移m位。即如果str=”ABCDEF”,循环左移2位得到 “CDEFAB”。 算法:使用两个倒序,倒序AB得到BA,倒序CDEF...
阅读全文 0