Last active
December 26, 2016 02:21
-
-
Save lxiange/c82450bf82ee5627f86b2eec834e8d64 to your computer and use it in GitHub Desktop.
Time Complexity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void foo1(int n) { | |
int bar = 0; | |
for (int i = 0; i < n; i++) { | |
bar++; | |
} | |
} | |
void foo2(int n) { | |
int sum = 0; | |
int i = 0; | |
while (sum < n) { | |
sum += i++; | |
} | |
} | |
void foo3(int[] arr) { | |
int bar = 0; | |
for (int i = 0; i < arr.length; i++) { | |
bar++; | |
} | |
} | |
void foo4(int[] arr) { | |
int bar = 0; | |
for (int i = 0; i < arr.length; i++) { | |
for (int j = 0; j < arr[i]; j++) { | |
bar++; | |
} | |
} | |
} | |
void foo5(char[] arr) { | |
int num = atoi(arr); | |
int bar = 0; | |
for (int i = 0; i < num; i++) { | |
bar++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment