摘要:
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit on th... 阅读全文
posted @ 2017-01-10 23:37
xiejunzhao
阅读(410)
评论(0)
推荐(0)
摘要:
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000000000... 阅读全文
posted @ 2017-01-10 23:37
xiejunzhao
阅读(128)
评论(0)
推荐(0)
摘要:
Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 ... 阅读全文
posted @ 2017-01-10 23:22
xiejunzhao
阅读(153)
评论(0)
推荐(0)
摘要:
十进制转二进制static void Main(string[] args) { int i = 60; string s = ""; while (i>0) { s = (i % 2).ToString() + s; i /= 2; } Console.WriteLine(Convert.ToString(60, 2));//c#转换方法 Console.WriteLine(s);}Give... 阅读全文
posted @ 2017-01-10 23:21
xiejunzhao
阅读(204)
评论(0)
推荐(0)
摘要:
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is = 0 || carry>0) { digit = carry; ... 阅读全文
posted @ 2017-01-10 23:21
xiejunzhao
阅读(174)
评论(0)
推荐(0)
摘要:
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public int RomanCharToInt(char c) { switch (c) { ... 阅读全文
posted @ 2017-01-10 23:21
xiejunzhao
阅读(242)
评论(0)
推荐(0)
摘要:
Calculate 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.Credits:Special thanks to @fujiaozhu for adding this problem and ... 阅读全文
posted @ 2017-01-10 23:21
xiejunzhao
阅读(120)
评论(0)
推荐(0)
摘要:
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), des... 阅读全文
posted @ 2017-01-10 23:19
xiejunzhao
阅读(135)
评论(0)
推荐(0)
摘要:
题目要求求出长度即可,并不需要求出最长回文串。思路:用字典统计每一个字符的出现次数,出现次数大于1的字符必定出现在回文串中,另外还再加上一个中心点。public static int LongestPalindrome(string s) { int length = 0; Dictionary dictionary = new Dictionary(); int value = 0; forea... 阅读全文
posted @ 2017-01-10 23:18
xiejunzhao
阅读(121)
评论(0)
推荐(0)
摘要:
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of ... 阅读全文
posted @ 2017-01-10 23:18
xiejunzhao
阅读(287)
评论(0)
推荐(0)
摘要:
假设str长度为len,重复的子串长度为k,则如果真的由连续多个长度为k的子串重复构成str,那么在对str求next时,由于连续对称性(如图,前后两个虚线框内字符串相等),会从next[k+1]开始,1,2,3...地递增,直到next[len]=len-k,且(len-k)%k==0,表示有整数个k要一直求到next[len]而不是next[len-1],是因为next[len-1]只是表示前... 阅读全文
posted @ 2017-01-10 23:14
xiejunzhao
阅读(215)
评论(0)
推荐(0)
摘要:
//循环版本public static bool IsPowerOfThree(int n) { if (n == 1) { return true; } double num = n; bool isPower = false; while (num >= 1) { num = num / 3; if (num == 1 && num == (int)num) { return tru... 阅读全文
posted @ 2017-01-10 23:14
xiejunzhao
阅读(572)
评论(0)
推荐(0)
摘要:
Power of Two Total Accepted: 3596 Total Submissions: 11779Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem... 阅读全文
posted @ 2017-01-10 23:14
xiejunzhao
阅读(229)
评论(0)
推荐(0)
摘要:
public class Solution { public int HammingDistance(int x, int y) { int distance = 0; string sX = Convert.ToString(x, 2); string sY = Convert.ToString(y, 2); int maxLength = Math.Max(sX.Length, ... 阅读全文
posted @ 2017-01-10 23:13
xiejunzhao
阅读(204)
评论(0)
推荐(0)
摘要:
Reverse a singly linked list. 递归实现 阅读全文
posted @ 2017-01-10 23:12
xiejunzhao
阅读(118)
评论(0)
推荐(0)
摘要:
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could yo... 阅读全文
posted @ 2017-01-10 23:11
xiejunzhao
阅读(124)
评论(0)
推荐(0)
摘要:
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as many times as it sho... 阅读全文
posted @ 2017-01-10 23:10
xiejunzhao
阅读(127)
评论(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 array is non-empty and the majority element always... 阅读全文
posted @ 2017-01-10 23:09
xiejunzhao
阅读(135)
评论(0)
推荐(0)
摘要:
217. Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return fa... 阅读全文
posted @ 2017-01-10 23:09
xiejunzhao
阅读(128)
评论(0)
推荐(0)
摘要:
错误1"aa""bb"static public bool IsAnagram(string s, string t) { int sLength = s.Length; int tLength = t.Length; if (sLength != tLength) { return false; } char c = ' '; int value = 0; Dictionary d = new... 阅读全文
posted @ 2017-01-10 23:08
xiejunzhao
阅读(298)
评论(0)
推荐(0)
摘要:
Excel Sheet Column NumberRelated to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C ->... 阅读全文
posted @ 2017-01-10 23:07
xiejunzhao
阅读(106)
评论(0)
推荐(0)
摘要:
递归实现static public bool IsSameTree(TreeNode root1, TreeNode root2) { if (root1 == null && root2 == null) { return true; } if ((root1 == null && root2 != null) || (root1 != null && root2 == null)) { r... 阅读全文
posted @ 2017-01-10 23:07
xiejunzhao
阅读(3027)
评论(0)
推荐(0)
摘要:
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result can be in any ... 阅读全文
posted @ 2017-01-10 23:05
xiejunzhao
阅读(153)
评论(0)
推荐(0)
摘要:
QuestionWrite 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 -> 4 and you are given the third node with v... 阅读全文
posted @ 2017-01-10 23:05
xiejunzhao
阅读(122)
评论(0)
推荐(0)
摘要:
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may assume... 阅读全文
posted @ 2017-01-10 23:05
xiejunzhao
阅读(281)
评论(0)
推荐(0)
摘要:
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot... 阅读全文
posted @ 2017-01-10 23:04
xiejunzhao
阅读(177)
评论(0)
推荐(0)
摘要:
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.publi... 阅读全文
posted @ 2017-01-10 23:04
xiejunzhao
阅读(159)
评论(0)
推荐(0)
摘要:
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, ... 阅读全文
posted @ 2017-01-10 23:03
xiejunzhao
阅读(151)
评论(0)
推荐(0)
摘要:
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input: [1,2,3] Output: ... 阅读全文
posted @ 2017-01-10 23:03
xiejunzhao
阅读(98)
评论(0)
推荐(0)
摘要:
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 example, given nums = [0, 1, 0, 3, 12], after calling your func... 阅读全文
posted @ 2017-01-10 23:01
xiejunzhao
阅读(303)
评论(0)
推荐(0)
摘要:
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me... 阅读全文
posted @ 2017-01-10 23:00
xiejunzhao
阅读(250)
评论(0)
推荐(0)
摘要:
求二叉树的最大深度using System;using System.Collections.Generic;using System.Linq;using System.Text;using Algorithm;namespace Solution { public class Solution1 { public int MaxDepth(TreeNode root) { if (roo... 阅读全文
posted @ 2017-01-10 23:00
xiejunzhao
阅读(121)
评论(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 a random position.Find the letter that was added in... 阅读全文
posted @ 2017-01-10 23:00
xiejunzhao
阅读(150)
评论(0)
推荐(0)
摘要:
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo... 阅读全文
posted @ 2017-01-10 23:00
xiejunzhao
阅读(179)
评论(0)
推荐(0)
摘要:
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For... 阅读全文
posted @ 2017-01-10 22:59
xiejunzhao
阅读(167)
评论(0)
推荐(0)
摘要:
Write a function that takes a string as input and returns the string reversed.Example: Given s = "hello", return "olleh". /** * @param {string} s * @return {string} */var reverseString = function (s) ... 阅读全文
posted @ 2017-01-10 22:59
xiejunzhao
阅读(180)
评论(0)
推荐(0)
摘要:
Given an array of integers, every element appears twice except for one. Find that single one./* Given an array of integers, every element appears twice except for one. Find that single one. */using... 阅读全文
posted @ 2017-01-10 22:59
xiejunzhao
阅读(161)
评论(0)
推荐(0)
摘要:
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to 4 / \ 7 2 / \ / \ 9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howell:Google: 90%... 阅读全文
posted @ 2017-01-10 22:58
xiejunzhao
阅读(137)
评论(0)
推荐(0)
摘要:
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely ... 阅读全文
posted @ 2017-01-10 22:57
xiejunzhao
阅读(240)
评论(0)
推荐(0)

浙公网安备 33010602011771号