01 2017 档案

摘要:For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L... 阅读全文
posted @ 2017-01-30 22:31 xiejunzhao 阅读(158) 评论(0) 推荐(0)
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional ... 阅读全文
posted @ 2017-01-28 19:13 xiejunzhao 阅读(126) 评论(0) 推荐(0)
摘要:函数指针重载:参数类型要匹配,指针类型必须精确匹配 使用decltype作用于某个函数时,要显示加上*以表示我们需要返回指针,而非函数本身 int func(int a, int b);using pFunc1 = decltype(func) *;typedef decltype(func) *pFunc2;using pFunc3 = int (*)(int a, int b);using ... 阅读全文
posted @ 2017-01-28 17:37 xiejunzhao 阅读(117) 评论(0) 推荐(0)
摘要:顶层const:指针本身是常量,不能改变指针的指向底层const:指针指向一个常量,不能改变指向对象的值null 阅读全文
posted @ 2017-01-28 17:36 xiejunzhao 阅读(107) 评论(0) 推荐(0)
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1 { class Program { delegate double ProcessDelegate(double p... 阅读全文
posted @ 2017-01-28 17:32 xiejunzhao 阅读(182) 评论(0) 推荐(0)
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System... 阅读全文
posted @ 2017-01-28 17:32 xiejunzhao 阅读(1109) 评论(0) 推荐(0)
摘要:项目需要,经常需要手动调整图片尺寸,流程太过麻烦,效率低下。所以写了一个小程序,以提高工作效率using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;using System.Drawing;using... 阅读全文
posted @ 2017-01-28 17:24 xiejunzhao 阅读(2799) 评论(0) 推荐(0)
摘要:项目需要,经常需要手动压缩图片,流程太过麻烦,效率低下。所以写了一个小程序,以提高工作效率using System;using System.Net;using System.Text;using System.IO;class Program{ static void Main() { Console.WriteLine("请输入TinyPng.com的API KEY,... 阅读全文
posted @ 2017-01-28 17:23 xiejunzhao 阅读(1263) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.创建一个新结点,同时遍历两个链表,取较小的一个添加到新结点后面。最后再把剩下的节点加到链表后面public class... 阅读全文
posted @ 2017-01-23 23:36 xiejunzhao 阅读(177) 评论(0) 推荐(0)
摘要:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it i... 阅读全文
posted @ 2017-01-19 23:30 xiejunzhao 阅读(172) 评论(0) 推荐(0)
摘要:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:1,... 阅读全文
posted @ 2017-01-18 23:52 xiejunzhao 阅读(124) 评论(0) 推荐(0)
摘要:Given an 2D board, count how many different battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receive a va... 阅读全文
posted @ 2017-01-17 23:14 xiejunzhao 阅读(119) 评论(0) 推荐(0)
摘要:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5 you sho... 阅读全文
posted @ 2017-01-16 22:11 xiejunzhao 阅读(123) 评论(0) 推荐(0)
摘要:Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. ... 阅读全文
posted @ 2017-01-15 17:43 xiejunzhao 阅读(347) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.移除单链表中重复的节点public class Solution { ... 阅读全文
posted @ 2017-01-14 12:04 xiejunzhao 阅读(162) 评论(0) 推荐(0)
摘要:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of a 32-bi... 阅读全文
posted @ 2017-01-14 11:56 xiejunzhao 阅读(162) 评论(0) 推荐(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 climb to the top?假设你在爬一个楼梯,该楼梯有n阶,你有两种爬法,每次爬一阶或者两阶。请问... 阅读全文
posted @ 2017-01-14 11:56 xiejunzhao 阅读(28) 评论(0) 推荐(0)
摘要:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance between i and k (the order of the tup... 阅读全文
posted @ 2017-01-12 00:24 xiejunzhao 阅读(153) 评论(0) 推荐(0)
摘要: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 阅读(412) 评论(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 阅读(130) 评论(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)
摘要: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 阅读(122) 评论(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 阅读(206) 评论(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 阅读(177) 评论(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 阅读(243) 评论(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 阅读(136) 评论(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 阅读(122) 评论(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 阅读(288) 评论(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 阅读(217) 评论(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 阅读(575) 评论(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 阅读(230) 评论(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 阅读(205) 评论(0) 推荐(0)
摘要:Reverse a singly linked list. 递归实现 阅读全文
posted @ 2017-01-10 23:12 xiejunzhao 阅读(119) 评论(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 阅读(125) 评论(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 阅读(128) 评论(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 阅读(137) 评论(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 阅读(130) 评论(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 阅读(107) 评论(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 阅读(3029) 评论(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 阅读(154) 评论(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 阅读(123) 评论(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 阅读(282) 评论(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 阅读(178) 评论(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 阅读(160) 评论(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 阅读(154) 评论(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 阅读(99) 评论(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 阅读(307) 评论(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 阅读(251) 评论(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 阅读(180) 评论(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 阅读(181) 评论(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 阅读(163) 评论(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 阅读(138) 评论(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 阅读(241) 评论(0) 推荐(0)