本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss

随笔分类 -  OJ

摘要:题目链接Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the". 1 class Solution { 2 publ... 阅读全文
posted @ 2014-09-22 19:59 tenos 阅读(1180) 评论(0) 推荐(1) 编辑
摘要:题目链接给定两个正整数a,b,分别定义两个集合L和R,集合L:即把1~a,1~b中整数乘积的集合定义为L = {x * y | x,y是整数且1 b 可以两者交换),a的十进制位数为ka, b的十进制位数为kb。因此异或求解集合R中元素时,只有b的最后ka个二进制位受影响,b的前kb-ka个二进制位可以表示0…2^(kb-ka)-1的所有数。现在我们只考虑b的后面ka个二进制位:1、假设b = 11001,a = 101,那么R = {00001…11001}^{001…101}表示的数有哪些呢? 我们可以看到两者异或后可以表示的最大的数是11001^100 = 11101(注意到后三位异或. 阅读全文
posted @ 2013-12-29 15:44 tenos 阅读(1190) 评论(0) 推荐(0) 编辑
摘要:题目如下甲乙两个人用一个英语单词玩游戏。两个人轮流进行,每个人每次从中删掉任意一个字母,如果剩余的字母序列是严格单调递增的(按字典序a Map; static int who (string word) { //用map保存子问题,防止重复计算 //amap[s]表示字符串s由甲操作时甲能否获胜 //bmap[s]表示字符串s由乙操作时甲能否获胜 Map amap, bmap; return (int)dfs(word, 1, amap, bmap); }private: //判断字符串是否严格... 阅读全文
posted @ 2013-12-21 14:04 tenos 阅读(1341) 评论(0) 推荐(0) 编辑
摘要:题目链接Given two binary strings, return their sum (also a binary string).For example, a = "11" b = "1" Return "100".分析:简单的处理二进制求和和进位即可 本文地址class So... 阅读全文
posted @ 2013-12-15 15:22 tenos 阅读(586) 评论(0) 推荐(0) 编辑
摘要:题目链接Validate if a given string is numeric.Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true 本文地址Note... 阅读全文
posted @ 2013-12-15 15:18 tenos 阅读(1311) 评论(0) 推荐(0) 编辑
摘要:题目链接Given a number represented as an array of digits, plus one to the number分析:too simple 本文地址class Solution {public: vector plusOne(vector &digits... 阅读全文
posted @ 2013-12-15 14:58 tenos 阅读(622) 评论(0) 推荐(0) 编辑
摘要:题目链接Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You s... 阅读全文
posted @ 2013-12-15 14:51 tenos 阅读(1951) 评论(0) 推荐(0) 编辑
摘要:题目链接Implement int sqrt(int x).Compute and return the square root of x.面试时需要考虑x是否小于0.分析:牛顿法,先假设一个初始解res(本文设为1),然后以抛物y = x^2-c(这里的c相当于题目中的x)上的点(res, res... 阅读全文
posted @ 2013-12-12 20:07 tenos 阅读(594) 评论(2) 推荐(0) 编辑
摘要:题目链接You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you... 阅读全文
posted @ 2013-12-09 14:25 tenos 阅读(1477) 评论(2) 推荐(1) 编辑
摘要:题目链接Given an absolute path for a file (Unix-style), simplify it.For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c"Corner Ca... 阅读全文
posted @ 2013-12-09 14:14 tenos 阅读(1241) 评论(1) 推荐(0) 编辑
摘要:题目链接Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You ha... 阅读全文
posted @ 2013-12-09 14:08 tenos 阅读(972) 评论(0) 推荐(0) 编辑
摘要:题目链接Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space? A straight forward... 阅读全文
posted @ 2013-12-09 13:49 tenos 阅读(843) 评论(0) 推荐(0) 编辑
摘要:LeetCode:Search in Rotated Sorted ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5... 阅读全文
posted @ 2013-12-09 13:32 tenos 阅读(2063) 评论(0) 推荐(0) 编辑
摘要:题目链接Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorte... 阅读全文
posted @ 2013-12-08 22:25 tenos 阅读(827) 评论(0) 推荐(0) 编辑
摘要:题目链接Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order r... 阅读全文
posted @ 2013-12-08 22:16 tenos 阅读(1133) 评论(0) 推荐(1) 编辑
摘要:题目链接Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example, If n = 4 and k = 2, a solution is:[ [2,4], ... 阅读全文
posted @ 2013-12-06 15:50 tenos 阅读(3605) 评论(0) 推荐(1) 编辑
摘要:题目链接Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "ad... 阅读全文
posted @ 2013-12-06 15:34 tenos 阅读(2175) 评论(5) 推荐(1) 编辑
摘要:LeetCode:Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once.For example, Give... 阅读全文
posted @ 2013-12-06 15:24 tenos 阅读(1077) 评论(0) 推荐(0) 编辑
摘要:LeetCode:Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear only once and return th... 阅读全文
posted @ 2013-12-06 14:49 tenos 阅读(1034) 评论(0) 推荐(0) 编辑
摘要:题目链接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 = "ADOB... 阅读全文
posted @ 2013-12-06 14:01 tenos 阅读(6947) 评论(4) 推荐(3) 编辑


本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss

公益页面-寻找遗失儿童