原创 LeetCode 202 Happy number

  Write an algorithm to determine if a number is "happy". A happy number

原创 算法導論 動態規劃之鋼條切割

#include<iostream> #include<algorithm> using namespace std; int UpToBottom(int *p,int n)//普通的自頂向下實現 { if (n == 0) re

原创 Leetcode266 Palindrome Permutation

Question Given a string, determine if a permutation of the string could form a palindrome. For example,  “code” -> F

原创 Uva133 約瑟夫圓環新解

之前學數據結構遇到雙向循環列表,現在發現一種更簡便的方法解決類似約瑟夫圓環問題。   #include<iostream> using namespace std; int n,k,m ,a[25]; int go(int p, int

原创 LeetCode 136 single number

題目: 給定一個數組,每個元素都出現2次除了其中的一個,找出只出現一次的數字注意:算法必須是線性時間複雜度,不使用額外的空間。 提示:利用亦或運算的性質。 #include<iostream> #include<vector> using

原创 Uva1588

/*Page 59 3-11 齒輪齧合 */</span>#include <iostream> using namespace std; int main() { char Up[100], Down[100]; while (sc

原创 Uva201 Squares

 *未按照題目的格式。 /*整體思路:枚舉法,掃描全部的點,用size代表每次檢查的正方形邊長,依次檢查是否滿足題意*/ #include<iostream> using namespace std; int H[10][10]; int

原创 Uva10340

  #include<iostream> #include<string> using namespace std; int main() { int score = 0; string s, t; cin >> s >> t;

原创 LeetCode 217 Contains Duplicate

題目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value

原创 LeetCode137 Single Number II

question: Given an array of integers, every element appears three times except for one. Find that single one. Note:

原创 LeetCode 191 number of 1 bits

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming

原创 LeetCode 258. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: G

原创 LeetCode 231 Power of Two(三解)

231. Power of Two Given an integer, write a function to determine if it is a power of two. 我的方法是暴力求解,循環讓1一直乘以2,如果結果等於n

原创 LeetCode 3 Longest Substring Without Repeating Characters

題目:   Given a string, find the length of the longest substring without repeating characters. For example, the longest

原创 LeetCode 83 Remove Duplicates from Sorted List

 題目: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1