JZ48 不用加减乘除做加法 Solution 1234567891011class Solution {public: int Add(int num1, int num2) { while (num2) { // 当进位为 0 时。跳出 int c = ((unsigned int)(num1 & num2)) << 1; 2021-10-10 algo 数学 nowcoder
JZ47 求1+2+3+...+n Solution 12345678class Solution {public: int Sum_Solution(int n) { int sum = n; bool x = (n > 0) && (sum += Sum_Solution(n-1)); return sum; } 2021-10-10 algo 数学 nowcoder
JZ46 孩子们的游戏 Solution 模拟法 123456789101112131415161718192021class Solution {public: int LastRemaining_Solution(int n, int m) { if (n <= 0 || m < 0) return -1; // 利用数组模拟环删除过程 2021-10-10 algo 数学 nowcoder
JZ45 扑克牌顺子 Solution 12345678910111213141516class Solution {public: bool IsContinuous( vector<int> numbers ) { if (numbers.size() < 5) return false; vector<int> recor 2021-10-10 algo nowcoder 数组
JZ44 翻转单词序列 Solution 12345678910111213141516class Solution {public: string ReverseSentence(string str) { string res = "", cur = ""; for (char c : str) { 2021-10-10 algo 字符串 nowcoder
JZ43 左旋转字符串 Solution 拼接再截取 12345678910class Solution {public: string LeftRotateString(string str, int n) { int len = str.size(); if (len == 0 || n <= 0) return str; n %= 2021-10-10 algo 字符串 nowcoder
JZ42 和为S的两个数字 Solution 双指针 1234567891011121314151617181920212223242526class Solution {public: vector<int> FindNumbersWithSum(vector<int> array,int sum) { vector<int> res; 2021-10-10 algo nowcoder 数组
JZ41 和为S的连续正数序列 Solution 暴力法 123456789101112131415161718192021222324class Solution {public: vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int>> 2021-10-10 algo nowcoder 数组
JZ40 数组中只出现一次的两个数字 Solution 位运算 123456789101112131415161718192021222324252627282930class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param array int整型vector * 2021-10-08 algo 位运算 nowcoder
JZ39 平衡二叉树 Solution 1234567891011121314151617class Solution {public: bool IsBalanced_Solution(TreeNode* pRoot) { return getDepth(pRoot) != -1; } int getDepth(TreeNode* root 2021-10-08 algo 二叉树 nowcoder