随笔分类 -  数据结构和算法

摘要: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 阅读全文
posted @ 2016-12-07 09:46 破玉 阅读(371) 评论(0) 推荐(0)
摘要: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, 阅读全文
posted @ 2016-12-05 21:23 破玉 阅读(872) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-28 10:05 破玉 阅读(559) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-27 10:33 破玉 阅读(273) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-26 10:30 破玉 阅读(407) 评论(0) 推荐(0)
摘要: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. 注意:不能使用运算符喽 那我 阅读全文
posted @ 2016-11-25 09:28 破玉 阅读(209) 评论(0) 推荐(0)
摘要:Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 阅读全文
posted @ 2016-11-24 09:54 破玉 阅读(235) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-23 15:27 破玉 阅读(142) 评论(0) 推荐(0)
摘要: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? 阅读全文
posted @ 2016-11-22 11:16 破玉 阅读(226) 评论(0) 推荐(0)
摘要:Reverse a singly linked list. 阅读全文
posted @ 2016-11-21 10:51 破玉 阅读(111) 评论(0) 推荐(0)
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 此题是求阶乘后面零的个数。 阅读全文
posted @ 2016-11-20 09:04 破玉 阅读(148) 评论(0) 推荐(0)
摘要: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 - 阅读全文
posted @ 2016-11-19 11:22 破玉 阅读(146) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-18 11:10 破玉 阅读(297) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 参考博客:链表环状检测 阅读全文
posted @ 2016-11-17 19:59 破玉 阅读(115) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-11-16 10:02 破玉 阅读(157) 评论(0) 推荐(0)
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return solution: 阅读全文
posted @ 2016-11-14 10:25 破玉 阅读(389) 评论(0) 推荐(0)
摘要:1. 冒泡排序 2.插入排序 3.快速排序 阅读全文
posted @ 2016-10-17 20:57 破玉 阅读(258) 评论(0) 推荐(0)
摘要:package cn.magicdu.algorithm; import java.util.LinkedList; import java.util.List; /** * 出圈问题,数到某个数字的倍数就出圈,打印最后剩下的元素的原来位置 * * @author xiaoduc * */ public class Circle { public static vo... 阅读全文
posted @ 2016-10-17 19:55 破玉 阅读(781) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2016-10-17 19:32 破玉 阅读(1928) 评论(0) 推荐(0)
摘要:package cn.magicdu.algorithm; /** * 九九乘法口诀表 * * @author xiaoduc * */ public class NineNineMulitTable { public static void main(String[] args) { print99(); } /** *... 阅读全文
posted @ 2016-10-17 19:15 破玉 阅读(2085) 评论(0) 推荐(0)