随笔分类 - 数据结构和算法
摘要: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
阅读全文
摘要:Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. For example, Input: "Hello,
阅读全文
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This
阅读全文
摘要: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 wron
阅读全文
摘要: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
阅读全文
摘要:alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 注意:不能使用运算符喽 那我
阅读全文
摘要:Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh".
阅读全文
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given num = 5, return fa
阅读全文
摘要:Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion?
阅读全文
摘要:Reverse a singly linked list.
阅读全文
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 此题是求阶乘后面零的个数。
阅读全文
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -
阅读全文
摘要: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
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 参考博客:链表环状检测
阅读全文
摘要:Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to us
阅读全文
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return solution:
阅读全文
摘要:package cn.magicdu.algorithm; import java.util.LinkedList; import java.util.List; /** * 出圈问题,数到某个数字的倍数就出圈,打印最后剩下的元素的原来位置 * * @author xiaoduc * */ public class Circle { public static vo...
阅读全文
摘要:package cn.magicdu.algorithm; public class CircleNumber { public static void main(String[] args) { for(int i=10;i0){ newValue=newValue*10+num%10; //得到一位数字 num/=10...
阅读全文
摘要:package cn.magicdu.algorithm; /** * 九九乘法口诀表 * * @author xiaoduc * */ public class NineNineMulitTable { public static void main(String[] args) { print99(); } /** *...
阅读全文