惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - stonespawn

Vue 组件库2 Vue 的组件库 VS2019 自动代码补全功能 GIT 删除操作 vue-router 注意事项 Vue中axios访问 后端跨域问题 Vue2.0 搭配 axios Vue 脚手架搭建 grunt使用入门 Git相关操作及记录 Ajax在调用含有SoapHeader的webservice方法 关于JS 树形结构 导出EXCEL【Web方式HTML通过拼接html中table】 链接点击跳动问题 WatiN——Web自动化测试(三)【弹出窗口处理】 WatiN——Web自动化测试(二) WatiN——Web自动化测试(一) 网页调用服务程序 - stonespawn - 博客园 小问题 小技巧 :创建虚拟目录并将IIS里面.net配置版本设为2.0 - stonespawn
算法小题目
stonespawn · 2022-06-13 · via 博客园 - stonespawn

1、X=10,Y=85,D=30 (步长),X+N*D>=Y

public int solution(int X, int Y, int D) {
        if((Y-X)%D==0)
            return (Y-X)/D;
        else
            return (Y-X)/D+1;
}

 2、找出缺少的正整数

public int F(int[] A)
        {
            int[] positive = new int[A.Length+1];
            int pIndex = 1;
            A = Xier(A);
            for (int i = 0; i < A.Length; i++)
            {
                if (A[i] >= 0)
                {
                    positive[pIndex] = A[i];// 第一个数0
                    pIndex++;
                }
            }

            for (int i = 0; i < positive.Length; i++)
            {
                if (i == positive.Length - 1)
                {
                    return positive[positive.Length - 1] + 1;
                }
                else
                {
                    if (positive[i] + 1 < positive[i + 1])
                    {
                        return positive[i] + 1;
                    }
                }
            }
            return positive[positive.Length-1]+1;
 }

public int[] Xier(int[] A)
        {
            for (int gap = A.Length; gap > 0; gap/=2)
            {
                for (int i = gap; i < A.Length; i++)
                {
                    int temp = A[i];
                    int j = i - gap;
                    while (j >= 0 && temp < A[j])
                    {
                        A[j + gap] = A[j];
                        j -= gap;
                    }
                    A[j + gap] = temp;
                }
            }
            return A;
        }

 3、找出数组中不同值数量

public int D(int[] A)
        {
            int count = 0;
            A = Xier(A);
            if (A.Length > 0)
            {
                count = 1;
                for (int i = 0; i < A.Length - 1; i++)
                {
                    if (A[i] != A[i + 1])
                    {
                        count++;
                    }
                }                
            }
            return count;
        }

 4、求出A到B中有多少数可以 X%K==0

public int S(int A,int B,int K)
        {
            //方法1 时间复杂度最高,超时
            //int index = 0;
            //for (int i = A; i <= B; i++)
            //{
            //    if (i % K == 0) { index++; }
            //}
            //return index;

            //方法2 时间复杂度(O(B-A)/K)
            //int flag = 0;
            //if (A % K == 0)
            //{
            //    flag = A;
            //}
            //else
            //{
            //    flag = (A / K + 1) * K;
            //}
            //int index = 0;
            //for (int i= flag; i <= B; i+=K)
            //{
            //    if (i % K == 0) { index++; }
            //}
            //return index;

            //方法3
            int i = B / K;
            int j = A / K;
            if (A % K == 0)
            {
                return i - j + 1;
            }
            else
            {
                return i - j;
            }
        }